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 # define PERL_REVISION 5
13 # define PERL_VERSION PATCHLEVEL
14 # define PERL_SUBVERSION SUBVERSION
26 # define Drand01() ((rand() & 0x7FFF) / (double) ((unsigned long)1 << 15))
31 # define gv_stashpvn(n,l,c) gv_stashpv(n,c)
38 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
39 MAGIC *mg = mg_find(sv, 't');
40 if (mg && ((mg->mg_len & 1) || (mg->mg_len & 2) && mg->mg_obj == sv))
46 # define SvTAINTED_on(sv) sv_magic((sv), Nullsv, 't', Nullch, 0)
47 # define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
49 # define PL_defgv defgv
51 # define PL_curpad curpad
52 # define CALLRUNOPS runops
53 # define PL_curpm curpm
54 # define PL_sv_undef sv_undef
55 # define PERL_CONTEXT struct context
57 #if (PERL_VERSION < 5) || (PERL_VERSION == 5 && PERL_SUBVERSION <50)
59 # define PL_tainting tainting
61 # ifndef PL_stack_base
62 # define PL_stack_base stack_base
65 # define PL_stack_sp stack_sp
68 # define PL_ppaddr ppaddr
72 MODULE=List::Util PACKAGE=List::Util
90 for(index = 1 ; index < items ; index++) {
91 SV *stacksv = ST(index);
92 NV val = SvNV(stacksv);
93 if(val < retval ? !ix : ix) {
113 RETVAL = SvNV(ST(0));
114 for(index = 1 ; index < items ; index++) {
115 RETVAL += SvNV(ST(index));
136 sv_cmp & sv_cmp_locale return 1,0,-1 for gt,eq,lt
137 so we set ix to the value we are looking for
138 xsubpp does not allow -ve values, so we start with 0,2 and subtract 1
143 if(MAXARG & OPpLOCALE) {
144 for(index = 1 ; index < items ; index++) {
145 SV *right = ST(index);
146 if(sv_cmp_locale(left, right) == ix)
152 for(index = 1 ; index < items ; index++) {
153 SV *right = ST(index);
154 if(sv_cmp(left, right) == ix)
180 I32 gimme = G_SCALAR;
181 bool oldcatch = CATCH_GET;
186 agv = gv_fetchpv("a", TRUE, SVt_PV);
187 bgv = gv_fetchpv("b", TRUE, SVt_PV);
190 cv = sv_2cv(block, &stash, &gv, 0);
191 reducecop = CvSTART(cv);
192 SAVESPTR(CvROOT(cv)->op_ppaddr);
193 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
195 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
200 PUSHBLOCK(cx, CXt_NULL, SP);
201 for(index = 2 ; index < items ; index++) {
203 GvSV(bgv) = ST(index);
208 ST(0) = sv_mortalcopy(ret);
209 POPBLOCK(cx,PL_curpm);
227 I32 gimme = G_SCALAR;
228 bool oldcatch = CATCH_GET;
233 SAVESPTR(GvSV(PL_defgv));
234 cv = sv_2cv(block, &stash, &gv, 0);
235 reducecop = CvSTART(cv);
236 SAVESPTR(CvROOT(cv)->op_ppaddr);
237 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
239 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
243 PUSHBLOCK(cx, CXt_NULL, SP);
244 for(index = 1 ; index < items ; index++) {
245 GvSV(PL_defgv) = ST(index);
248 if (SvTRUE(*PL_stack_sp)) {
250 POPBLOCK(cx,PL_curpm);
255 POPBLOCK(cx,PL_curpm);
267 struct op *old_op = PL_op;
269 SV **old_curpad = PL_curpad;
271 /* We call pp_rand here so that Drand01 get initialized if rand()
272 or srand() has not already been called
274 my_pad[1] = sv_newmortal();
275 memzero((char*)(&dmy_op), sizeof(struct op));
278 PL_curpad = (SV **)&my_pad;
281 PL_curpad = old_curpad;
282 for (index = items ; index > 1 ; ) {
283 int swap = (int)(Drand01() * (double)(index--));
285 ST(swap) = ST(index);
292 MODULE=List::Util PACKAGE=Scalar::Util
302 char *ptr = SvPV(str,len);
303 ST(0) = sv_newmortal();
304 (void)SvUPGRADE(ST(0),SVt_PVNV);
305 sv_setpvn(ST(0),ptr,len);
306 if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
307 SvNVX(ST(0)) = SvNV(num);
311 else if (SvUOK(num)) {
312 SvUVX(ST(0)) = SvUV(num);
318 SvIVX(ST(0)) = SvIV(num);
321 if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
334 if(!sv_isobject(sv)) {
337 RETVAL = sv_reftype(SvRV(sv),TRUE);
353 RETVAL = sv_reftype(SvRV(sv),FALSE);
366 croak("weak references are not implemented in this release of perl");
375 ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
378 croak("weak references are not implemented in this release of perl");
386 RETVAL = SvREADONLY(sv);
395 RETVAL = SvTAINTED(sv);
402 HV *stash = gv_stashpvn("Scalar::Util", 12, TRUE);
403 GV *vargv = *(GV**)hv_fetch(stash, "EXPORT_FAIL", 11, TRUE);
405 if (SvTYPE(vargv) != SVt_PVGV)
406 gv_init(vargv, stash, "Scalar::Util", 12, TRUE);
407 varav = GvAVn(vargv);
408 av_push(varav, newSVpv("weaken",6));
409 av_push(varav, newSVpv("isweak",6));