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
22 /* Some platforms have strict exports. And before 5.7.3 cxinc (or Perl_cxinc)
23 was not exported. Therefore platforms like win32, VMS etc have problems
24 so we redefine it here -- GMB
28 # define SvUOK(sv) SvIOK_UV(sv)
32 # define cxinc() my_cxinc(aTHX)
36 cxstack_max = cxstack_max * 3 / 2;
37 Renew(cxstack, cxstack_max + 1, struct context); /* XXX should fix CXINC macro */
38 return cxstack_ix + 1;
47 # define Drand01() ((rand() & 0x7FFF) / (double) ((unsigned long)1 << 15))
52 # define gv_stashpvn(n,l,c) gv_stashpv(n,c)
59 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
60 MAGIC *mg = mg_find(sv, 't');
61 if (mg && ((mg->mg_len & 1) || (mg->mg_len & 2) && mg->mg_obj == sv))
67 # define SvTAINTED_on(sv) sv_magic((sv), Nullsv, 't', Nullch, 0)
68 # define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
70 # define PL_defgv defgv
72 # define PL_curpad curpad
73 # define CALLRUNOPS runops
74 # define PL_curpm curpm
75 # define PL_sv_undef sv_undef
76 # define PERL_CONTEXT struct context
78 #if (PERL_VERSION < 5) || (PERL_VERSION == 5 && PERL_SUBVERSION <50)
80 # define PL_tainting tainting
82 # ifndef PL_stack_base
83 # define PL_stack_base stack_base
86 # define PL_stack_sp stack_sp
89 # define PL_ppaddr ppaddr
93 MODULE=List::Util PACKAGE=List::Util
110 retval = SvNV(retsv);
111 for(index = 1 ; index < items ; index++) {
112 SV *stacksv = ST(index);
113 NV val = SvNV(stacksv);
114 if(val < retval ? !ix : ix) {
134 RETVAL = SvNV(ST(0));
135 for(index = 1 ; index < items ; index++) {
136 RETVAL += SvNV(ST(index));
157 sv_cmp & sv_cmp_locale return 1,0,-1 for gt,eq,lt
158 so we set ix to the value we are looking for
159 xsubpp does not allow -ve values, so we start with 0,2 and subtract 1
164 if(MAXARG & OPpLOCALE) {
165 for(index = 1 ; index < items ; index++) {
166 SV *right = ST(index);
167 if(sv_cmp_locale(left, right) == ix)
173 for(index = 1 ; index < items ; index++) {
174 SV *right = ST(index);
175 if(sv_cmp(left, right) == ix)
201 I32 gimme = G_SCALAR;
202 bool oldcatch = CATCH_GET;
207 agv = gv_fetchpv("a", TRUE, SVt_PV);
208 bgv = gv_fetchpv("b", TRUE, SVt_PV);
211 cv = sv_2cv(block, &stash, &gv, 0);
212 reducecop = CvSTART(cv);
213 SAVESPTR(CvROOT(cv)->op_ppaddr);
214 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
216 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
221 PUSHBLOCK(cx, CXt_NULL, SP);
222 for(index = 2 ; index < items ; index++) {
224 GvSV(bgv) = ST(index);
229 ST(0) = sv_mortalcopy(ret);
230 POPBLOCK(cx,PL_curpm);
248 I32 gimme = G_SCALAR;
249 bool oldcatch = CATCH_GET;
254 SAVESPTR(GvSV(PL_defgv));
255 cv = sv_2cv(block, &stash, &gv, 0);
256 reducecop = CvSTART(cv);
257 SAVESPTR(CvROOT(cv)->op_ppaddr);
258 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
260 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
264 PUSHBLOCK(cx, CXt_NULL, SP);
265 for(index = 1 ; index < items ; index++) {
266 GvSV(PL_defgv) = ST(index);
269 if (SvTRUE(*PL_stack_sp)) {
271 POPBLOCK(cx,PL_curpm);
276 POPBLOCK(cx,PL_curpm);
288 struct op *old_op = PL_op;
290 SV **old_curpad = PL_curpad;
292 /* We call pp_rand here so that Drand01 get initialized if rand()
293 or srand() has not already been called
295 my_pad[1] = sv_newmortal();
296 memzero((char*)(&dmy_op), sizeof(struct op));
299 PL_curpad = (SV **)&my_pad;
300 (void)*(PL_ppaddr[OP_RAND])(aTHX);
302 PL_curpad = old_curpad;
303 for (index = items ; index > 1 ; ) {
304 int swap = (int)(Drand01() * (double)(index--));
306 ST(swap) = ST(index);
313 MODULE=List::Util PACKAGE=Scalar::Util
323 char *ptr = SvPV(str,len);
324 ST(0) = sv_newmortal();
325 (void)SvUPGRADE(ST(0),SVt_PVNV);
326 sv_setpvn(ST(0),ptr,len);
327 if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
328 SvNVX(ST(0)) = SvNV(num);
332 else if (SvUOK(num)) {
333 SvUVX(ST(0)) = SvUV(num);
339 SvIVX(ST(0)) = SvIV(num);
342 if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
355 if(!sv_isobject(sv)) {
358 RETVAL = sv_reftype(SvRV(sv),TRUE);
374 RETVAL = sv_reftype(SvRV(sv),FALSE);
387 croak("weak references are not implemented in this release of perl");
396 ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
399 croak("weak references are not implemented in this release of perl");
407 RETVAL = SvREADONLY(sv);
416 RETVAL = SvTAINTED(sv);
423 HV *stash = gv_stashpvn("Scalar::Util", 12, TRUE);
424 GV *vargv = *(GV**)hv_fetch(stash, "EXPORT_FAIL", 11, TRUE);
426 if (SvTYPE(vargv) != SVt_PVGV)
427 gv_init(vargv, stash, "Scalar::Util", 12, TRUE);
428 varav = GvAVn(vargv);
429 av_push(varav, newSVpv("weaken",6));
430 av_push(varav, newSVpv("isweak",6));