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 slu_sv_value(sv) (NV)(SvIOK(sv) ? SvIOK_UV(sv) ? SvUVX(sv) : SvIVX(sv) : SvNV(sv))
49 # define slu_sv_value(sv) (NV)(SvIOK(sv) ? SvIVX(sv) : SvNV(sv))
53 # define Drand01() ((rand() & 0x7FFF) / (double) ((unsigned long)1 << 15))
58 # define gv_stashpvn(n,l,c) gv_stashpv(n,c)
65 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
66 MAGIC *mg = mg_find(sv, 't');
67 if (mg && ((mg->mg_len & 1) || (mg->mg_len & 2) && mg->mg_obj == sv))
73 # define SvTAINTED_on(sv) sv_magic((sv), Nullsv, 't', Nullch, 0)
74 # define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
76 # define PL_defgv defgv
78 # define PL_curpad curpad
79 # define CALLRUNOPS runops
80 # define PL_curpm curpm
81 # define PL_sv_undef sv_undef
82 # define PERL_CONTEXT struct context
84 #if (PERL_VERSION < 5) || (PERL_VERSION == 5 && PERL_SUBVERSION <50)
86 # define PL_tainting tainting
88 # ifndef PL_stack_base
89 # define PL_stack_base stack_base
92 # define PL_stack_sp stack_sp
95 # define PL_ppaddr ppaddr
100 # define PTR2IV(ptr) (IV)(ptr)
103 MODULE=List::Util PACKAGE=List::Util
120 retval = slu_sv_value(retsv);
121 for(index = 1 ; index < items ; index++) {
122 SV *stacksv = ST(index);
123 NV val = slu_sv_value(stacksv);
124 if(val < retval ? !ix : ix) {
146 RETVAL = slu_sv_value(sv);
147 for(index = 1 ; index < items ; index++) {
149 RETVAL += slu_sv_value(sv);
170 sv_cmp & sv_cmp_locale return 1,0,-1 for gt,eq,lt
171 so we set ix to the value we are looking for
172 xsubpp does not allow -ve values, so we start with 0,2 and subtract 1
177 if(MAXARG & OPpLOCALE) {
178 for(index = 1 ; index < items ; index++) {
179 SV *right = ST(index);
180 if(sv_cmp_locale(left, right) == ix)
186 for(index = 1 ; index < items ; index++) {
187 SV *right = ST(index);
188 if(sv_cmp(left, right) == ix)
214 I32 gimme = G_SCALAR;
216 bool oldcatch = CATCH_GET;
221 agv = gv_fetchpv("a", TRUE, SVt_PV);
222 bgv = gv_fetchpv("b", TRUE, SVt_PV);
225 cv = sv_2cv(block, &stash, &gv, 0);
226 reducecop = CvSTART(cv);
227 SAVESPTR(CvROOT(cv)->op_ppaddr);
228 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
230 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
235 PUSHBLOCK(cx, CXt_SUB, SP);
238 (void)SvREFCNT_inc(cv);
239 for(index = 2 ; index < items ; index++) {
241 GvSV(bgv) = ST(index);
246 ST(0) = sv_mortalcopy(ret);
247 POPBLOCK(cx,PL_curpm);
265 I32 gimme = G_SCALAR;
267 bool oldcatch = CATCH_GET;
272 SAVESPTR(GvSV(PL_defgv));
273 cv = sv_2cv(block, &stash, &gv, 0);
274 reducecop = CvSTART(cv);
275 SAVESPTR(CvROOT(cv)->op_ppaddr);
276 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
278 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
282 PUSHBLOCK(cx, CXt_SUB, SP);
285 (void)SvREFCNT_inc(cv);
287 for(index = 1 ; index < items ; index++) {
288 GvSV(PL_defgv) = ST(index);
291 if (SvTRUE(*PL_stack_sp)) {
293 POPBLOCK(cx,PL_curpm);
298 POPBLOCK(cx,PL_curpm);
310 struct op *old_op = PL_op;
312 SV **old_curpad = PL_curpad;
314 /* We call pp_rand here so that Drand01 get initialized if rand()
315 or srand() has not already been called
317 my_pad[1] = sv_newmortal();
318 memzero((char*)(&dmy_op), sizeof(struct op));
321 PL_curpad = (SV **)&my_pad;
322 (void)*(PL_ppaddr[OP_RAND])(aTHX);
324 PL_curpad = old_curpad;
325 for (index = items ; index > 1 ; ) {
326 int swap = (int)(Drand01() * (double)(index--));
328 ST(swap) = ST(index);
335 MODULE=List::Util PACKAGE=Scalar::Util
345 char *ptr = SvPV(str,len);
346 ST(0) = sv_newmortal();
347 (void)SvUPGRADE(ST(0),SVt_PVNV);
348 sv_setpvn(ST(0),ptr,len);
349 if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
350 SvNVX(ST(0)) = SvNV(num);
354 else if (SvUOK(num)) {
355 SvUVX(ST(0)) = SvUV(num);
361 SvIVX(ST(0)) = SvIV(num);
364 if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
377 if(!sv_isobject(sv)) {
380 RETVAL = sv_reftype(SvRV(sv),TRUE);
396 RETVAL = sv_reftype(SvRV(sv),FALSE);
410 RETVAL = PTR2IV(SvRV(sv));
423 croak("weak references are not implemented in this release of perl");
432 ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
435 croak("weak references are not implemented in this release of perl");
443 RETVAL = SvREADONLY(sv);
452 RETVAL = SvTAINTED(sv);
462 ST(0) = boolSV(SvVOK(sv));
465 croak("vstrings are not implemented in this release of perl");
471 #if !defined(SvWEAKREF) || !defined(SvVOK)
472 HV *stash = gv_stashpvn("Scalar::Util", 12, TRUE);
473 GV *vargv = *(GV**)hv_fetch(stash, "EXPORT_FAIL", 11, TRUE);
475 if (SvTYPE(vargv) != SVt_PVGV)
476 gv_init(vargv, stash, "Scalar::Util", 12, TRUE);
477 varav = GvAVn(vargv);
480 av_push(varav, newSVpv("weaken",6));
481 av_push(varav, newSVpv("isweak",6));
484 av_push(varav, newSVpv("isvstring",9));