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) {
204 retsv = sv_newmortal();
208 retval = slu_sv_value(sv);
210 for(index = 1 ; index < items ; index++) {
212 if (retsv || SvAMAGIC(sv)) {
214 retsv = sv_newmortal();
215 sv_setnv(retsv,retval);
217 if (!amagic_call(retsv, sv, add_amg, AMGf_assign)) {
218 sv_setnv(retsv, SvNV(retsv) + SvNV(sv));
222 retval += slu_sv_value(sv);
226 retsv = sv_newmortal();
227 sv_setnv(retsv,retval);
248 sv_cmp & sv_cmp_locale return 1,0,-1 for gt,eq,lt
249 so we set ix to the value we are looking for
250 xsubpp does not allow -ve values, so we start with 0,2 and subtract 1
255 if(MAXARG & OPpLOCALE) {
256 for(index = 1 ; index < items ; index++) {
257 SV *right = ST(index);
258 if(sv_cmp_locale(left, right) == ix)
264 for(index = 1 ; index < items ; index++) {
265 SV *right = ST(index);
266 if(sv_cmp(left, right) == ix)
287 SV *ret = sv_newmortal();
291 I32 gimme = G_SCALAR;
292 SV **args = &PL_stack_base[ax];
298 cv = sv_2cv(block, &stash, &gv, 0);
300 croak("Not a subroutine reference");
303 agv = gv_fetchpv("a", TRUE, SVt_PV);
304 bgv = gv_fetchpv("b", TRUE, SVt_PV);
308 SvSetSV(ret, args[1]);
309 for(index = 2 ; index < items ; index++) {
310 GvSV(bgv) = args[index];
312 SvSetSV(ret, *PL_stack_sp);
329 I32 gimme = G_SCALAR;
330 SV **args = &PL_stack_base[ax];
336 cv = sv_2cv(block, &stash, &gv, 0);
338 SAVESPTR(GvSV(PL_defgv));
340 for(index = 1 ; index < items ; index++) {
341 GvSV(PL_defgv) = args[index];
343 if (SvTRUE(*PL_stack_sp)) {
362 #if (PERL_VERSION < 9)
364 struct op *old_op = PL_op;
366 /* We call pp_rand here so that Drand01 get initialized if rand()
367 or srand() has not already been called
369 memzero((char*)(&dmy_op), sizeof(struct op));
370 /* we let pp_rand() borrow the TARG allocated for this XS sub */
371 dmy_op.op_targ = PL_op->op_targ;
373 (void)*(PL_ppaddr[OP_RAND])(aTHX);
376 /* Initialize Drand01 if rand() or srand() has
377 not already been called
379 if (!PL_srand_called) {
380 (void)seedDrand01((Rand_seed_t)Perl_seed(aTHX));
381 PL_srand_called = TRUE;
385 for (index = items ; index > 1 ; ) {
386 int swap = (int)(Drand01() * (double)(index--));
388 ST(swap) = ST(index);
395 MODULE=List::Util PACKAGE=Scalar::Util
405 char *ptr = SvPV(str,len);
406 ST(0) = sv_newmortal();
407 (void)SvUPGRADE(ST(0),SVt_PVNV);
408 sv_setpvn(ST(0),ptr,len);
409 if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
410 SvNV_set(ST(0), SvNV(num));
414 else if (SvUOK(num)) {
415 SvUV_set(ST(0), SvUV(num));
421 SvIV_set(ST(0), SvIV(num));
424 if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
437 if(!sv_isobject(sv)) {
440 RETVAL = (char*)sv_reftype(SvRV(sv),TRUE);
456 RETVAL = (char*)sv_reftype(SvRV(sv),FALSE);
472 RETVAL = PTR2UV(SvRV(sv));
485 croak("weak references are not implemented in this release of perl");
494 ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
497 croak("weak references are not implemented in this release of perl");
505 RETVAL = SvREADONLY(sv);
514 RETVAL = SvTAINTED(sv);
524 ST(0) = boolSV(SvVOK(sv));
527 croak("vstrings are not implemented in this release of perl");
531 looks_like_number(sv)
536 if (SvAMAGIC(sv) && (tempsv = AMG_CALLun(sv, numer))) {
539 else if (SvMAGICAL(sv)) {
542 #if (PERL_VERSION < 8) || (PERL_VERSION == 8 && PERL_SUBVERSION <5)
543 if (SvPOK(sv) || SvPOKp(sv)) {
544 RETVAL = looks_like_number(sv);
547 RETVAL = SvFLAGS(sv) & (SVf_NOK|SVp_NOK|SVf_IOK|SVp_IOK);
550 RETVAL = looks_like_number(sv);
556 set_prototype(subref, proto)
563 SV *sv = SvRV(subref);
564 if (SvTYPE(sv) != SVt_PVCV) {
565 /* not a subroutine reference */
566 croak("set_prototype: not a subroutine reference");
569 /* set the prototype */
571 char *ptr = SvPV(proto, len);
572 sv_setpvn(sv, ptr, len);
575 /* delete the prototype */
580 croak("set_prototype: not a reference");
587 HV *lu_stash = gv_stashpvn("List::Util", 10, TRUE);
588 GV *rmcgv = *(GV**)hv_fetch(lu_stash, "REAL_MULTICALL", 14, TRUE);
590 #if !defined(SvWEAKREF) || !defined(SvVOK)
591 HV *su_stash = gv_stashpvn("Scalar::Util", 12, TRUE);
592 GV *vargv = *(GV**)hv_fetch(su_stash, "EXPORT_FAIL", 11, TRUE);
594 if (SvTYPE(vargv) != SVt_PVGV)
595 gv_init(vargv, su_stash, "Scalar::Util", 12, TRUE);
596 varav = GvAVn(vargv);
598 if (SvTYPE(rmcgv) != SVt_PVGV)
599 gv_init(rmcgv, lu_stash, "List::Util", 12, TRUE);
600 rmcsv = GvSVn(rmcgv);
602 av_push(varav, newSVpv("weaken",6));
603 av_push(varav, newSVpv("isweak",6));
606 av_push(varav, newSVpv("isvstring",9));
608 #ifdef REAL_MULTICALL
609 sv_setsv(rmcsv, &PL_sv_yes);
611 sv_setsv(rmcsv, &PL_sv_no);