1 /* Copyright (c) 1997-2000 Graham Barr <gbarr@pobox.com>. All rights reserved.
2 * This program is free software; you can redistribute it and/or
3 * modify it under the same terms as Perl itself.
11 # include <patchlevel.h>
12 # if !(defined(PERL_VERSION) || (SUBVERSION > 0 && defined(PATCHLEVEL)))
13 # include <could_not_find_Perl_patchlevel.h>
15 # define PERL_REVISION 5
16 # define PERL_VERSION PATCHLEVEL
17 # define PERL_SUBVERSION SUBVERSION
21 # include "multicall.h"
28 /* Some platforms have strict exports. And before 5.7.3 cxinc (or Perl_cxinc)
29 was not exported. Therefore platforms like win32, VMS etc have problems
30 so we redefine it here -- GMB
34 # define SvUOK(sv) SvIOK_UV(sv)
38 # define cxinc() my_cxinc(aTHX)
42 cxstack_max = cxstack_max * 3 / 2;
43 Renew(cxstack, cxstack_max + 1, struct context); /* XXX should fix CXINC macro */
44 return cxstack_ix + 1;
53 # define slu_sv_value(sv) (SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv))
55 # define slu_sv_value(sv) (SvIOK(sv)) ? (NV)(SvIVX(sv)) : (SvNV(sv))
59 # define Drand01() ((rand() & 0x7FFF) / (double) ((unsigned long)1 << 15))
64 # define gv_stashpvn(n,l,c) gv_stashpv(n,c)
71 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
72 MAGIC *mg = mg_find(sv, 't');
73 if (mg && ((mg->mg_len & 1) || (mg->mg_len & 2) && mg->mg_obj == sv))
79 # define SvTAINTED_on(sv) sv_magic((sv), Nullsv, 't', Nullch, 0)
80 # define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
82 # define PL_defgv defgv
84 # define PL_curpad curpad
85 # define CALLRUNOPS runops
86 # define PL_curpm curpm
87 # define PL_sv_undef sv_undef
88 # define PERL_CONTEXT struct context
90 #if (PERL_VERSION < 5) || (PERL_VERSION == 5 && PERL_SUBVERSION <50)
92 # define PL_tainting tainting
94 # ifndef PL_stack_base
95 # define PL_stack_base stack_base
98 # define PL_stack_sp stack_sp
101 # define PL_ppaddr ppaddr
106 # define PTR2UV(ptr) (UV)(ptr)
110 # define SvUV_set(sv, val) (((XPVUV*)SvANY(sv))->xuv_uv = (val))
113 #ifndef PERL_UNUSED_DECL
115 # if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
116 # define PERL_UNUSED_DECL
118 # define PERL_UNUSED_DECL __attribute__((unused))
121 # define PERL_UNUSED_DECL
126 #define dNOOP extern int Perl___notused PERL_UNUSED_DECL
137 MODULE=List::Util PACKAGE=List::Util
155 magic = SvAMAGIC(retsv);
157 retval = slu_sv_value(retsv);
159 for(index = 1 ; index < items ; index++) {
160 SV *stacksv = ST(index);
162 if ((magic || SvAMAGIC(stacksv)) && (tmpsv = amagic_call(retsv, stacksv, gt_amg, 0))) {
163 if (SvTRUE(tmpsv) ? !ix : ix) {
165 magic = SvAMAGIC(retsv);
167 retval = slu_sv_value(retsv);
172 NV val = slu_sv_value(stacksv);
174 retval = slu_sv_value(retsv);
177 if(val < retval ? !ix : ix) {
203 retsv = sv_newmortal();
207 retval = slu_sv_value(sv);
209 for(index = 1 ; index < items ; index++) {
211 if (retsv || SvAMAGIC(sv)) {
213 retsv = sv_newmortal();
214 sv_setnv(retsv,retval);
216 if (!amagic_call(retsv, sv, add_amg, AMGf_assign)) {
217 sv_setnv(retsv, SvNV(retsv) + SvNV(sv));
221 retval += slu_sv_value(sv);
225 retsv = sv_newmortal();
226 sv_setnv(retsv,retval);
247 sv_cmp & sv_cmp_locale return 1,0,-1 for gt,eq,lt
248 so we set ix to the value we are looking for
249 xsubpp does not allow -ve values, so we start with 0,2 and subtract 1
254 if(MAXARG & OPpLOCALE) {
255 for(index = 1 ; index < items ; index++) {
256 SV *right = ST(index);
257 if(sv_cmp_locale(left, right) == ix)
263 for(index = 1 ; index < items ; index++) {
264 SV *right = ST(index);
265 if(sv_cmp(left, right) == ix)
286 SV *ret = sv_newmortal();
290 I32 gimme = G_SCALAR;
291 SV **args = &PL_stack_base[ax];
297 cv = sv_2cv(block, &stash, &gv, 0);
299 croak("Not a subroutine reference");
302 agv = gv_fetchpv("a", TRUE, SVt_PV);
303 bgv = gv_fetchpv("b", TRUE, SVt_PV);
307 SvSetSV(ret, args[1]);
308 for(index = 2 ; index < items ; index++) {
309 GvSV(bgv) = args[index];
311 SvSetSV(ret, *PL_stack_sp);
328 I32 gimme = G_SCALAR;
329 SV **args = &PL_stack_base[ax];
335 cv = sv_2cv(block, &stash, &gv, 0);
337 croak("Not a subroutine reference");
340 SAVESPTR(GvSV(PL_defgv));
342 for(index = 1 ; index < items ; index++) {
343 GvSV(PL_defgv) = args[index];
345 if (SvTRUE(*PL_stack_sp)) {
364 #if (PERL_VERSION < 9)
366 struct op *old_op = PL_op;
368 /* We call pp_rand here so that Drand01 get initialized if rand()
369 or srand() has not already been called
371 memzero((char*)(&dmy_op), sizeof(struct op));
372 /* we let pp_rand() borrow the TARG allocated for this XS sub */
373 dmy_op.op_targ = PL_op->op_targ;
375 (void)*(PL_ppaddr[OP_RAND])(aTHX);
378 /* Initialize Drand01 if rand() or srand() has
379 not already been called
381 if (!PL_srand_called) {
382 (void)seedDrand01((Rand_seed_t)Perl_seed(aTHX));
383 PL_srand_called = TRUE;
387 for (index = items ; index > 1 ; ) {
388 int swap = (int)(Drand01() * (double)(index--));
390 ST(swap) = ST(index);
397 MODULE=List::Util PACKAGE=Scalar::Util
407 char *ptr = SvPV(str,len);
408 ST(0) = sv_newmortal();
409 (void)SvUPGRADE(ST(0),SVt_PVNV);
410 sv_setpvn(ST(0),ptr,len);
413 if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
414 SvNV_set(ST(0), SvNV(num));
418 else if (SvUOK(num)) {
419 SvUV_set(ST(0), SvUV(num));
425 SvIV_set(ST(0), SvIV(num));
428 if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
441 if(!sv_isobject(sv)) {
444 RETVAL = (char*)sv_reftype(SvRV(sv),TRUE);
460 RETVAL = (char*)sv_reftype(SvRV(sv),FALSE);
476 RETVAL = PTR2UV(SvRV(sv));
489 croak("weak references are not implemented in this release of perl");
498 ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
501 croak("weak references are not implemented in this release of perl");
509 RETVAL = SvREADONLY(sv);
518 RETVAL = SvTAINTED(sv);
528 ST(0) = boolSV(SvVOK(sv));
531 croak("vstrings are not implemented in this release of perl");
535 looks_like_number(sv)
540 if (SvAMAGIC(sv) && (tempsv = AMG_CALLun(sv, numer))) {
543 else if (SvMAGICAL(sv)) {
546 #if (PERL_VERSION < 8) || (PERL_VERSION == 8 && PERL_SUBVERSION <5)
547 if (SvPOK(sv) || SvPOKp(sv)) {
548 RETVAL = looks_like_number(sv);
551 RETVAL = SvFLAGS(sv) & (SVf_NOK|SVp_NOK|SVf_IOK|SVp_IOK);
554 RETVAL = looks_like_number(sv);
560 set_prototype(subref, proto)
567 SV *sv = SvRV(subref);
568 if (SvTYPE(sv) != SVt_PVCV) {
569 /* not a subroutine reference */
570 croak("set_prototype: not a subroutine reference");
573 /* set the prototype */
575 char *ptr = SvPV(proto, len);
576 sv_setpvn(sv, ptr, len);
579 /* delete the prototype */
584 croak("set_prototype: not a reference");
591 HV *lu_stash = gv_stashpvn("List::Util", 10, TRUE);
592 GV *rmcgv = *(GV**)hv_fetch(lu_stash, "REAL_MULTICALL", 14, TRUE);
594 #if !defined(SvWEAKREF) || !defined(SvVOK)
595 HV *su_stash = gv_stashpvn("Scalar::Util", 12, TRUE);
596 GV *vargv = *(GV**)hv_fetch(su_stash, "EXPORT_FAIL", 11, TRUE);
598 if (SvTYPE(vargv) != SVt_PVGV)
599 gv_init(vargv, su_stash, "Scalar::Util", 12, TRUE);
600 varav = GvAVn(vargv);
602 if (SvTYPE(rmcgv) != SVt_PVGV)
603 gv_init(rmcgv, lu_stash, "List::Util", 12, TRUE);
604 rmcsv = GvSVn(rmcgv);
606 av_push(varav, newSVpv("weaken",6));
607 av_push(varav, newSVpv("isweak",6));
610 av_push(varav, newSVpv("isvstring",9));
612 #ifdef REAL_MULTICALL
613 sv_setsv(rmcsv, &PL_sv_yes);
615 sv_setsv(rmcsv, &PL_sv_no);