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 PAD_SET_CUR(CvPADLIST(cv),1);
233 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
239 PUSHBLOCK(cx, CXt_SUB, SP);
242 (void)SvREFCNT_inc(cv);
243 for(index = 2 ; index < items ; index++) {
245 GvSV(bgv) = ST(index);
250 ST(0) = sv_mortalcopy(ret);
251 POPBLOCK(cx,PL_curpm);
269 I32 gimme = G_SCALAR;
271 bool oldcatch = CATCH_GET;
276 SAVESPTR(GvSV(PL_defgv));
277 cv = sv_2cv(block, &stash, &gv, 0);
278 reducecop = CvSTART(cv);
279 SAVESPTR(CvROOT(cv)->op_ppaddr);
280 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
282 PAD_SET_CUR(CvPADLIST(cv),1);
285 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
290 PUSHBLOCK(cx, CXt_SUB, SP);
293 (void)SvREFCNT_inc(cv);
295 for(index = 1 ; index < items ; index++) {
296 GvSV(PL_defgv) = ST(index);
299 if (SvTRUE(*PL_stack_sp)) {
301 POPBLOCK(cx,PL_curpm);
306 POPBLOCK(cx,PL_curpm);
318 struct op *old_op = PL_op;
320 /* We call pp_rand here so that Drand01 get initialized if rand()
321 or srand() has not already been called
323 memzero((char*)(&dmy_op), sizeof(struct op));
324 /* we let pp_rand() borrow the TARG allocated for this XS sub */
325 dmy_op.op_targ = PL_op->op_targ;
327 (void)*(PL_ppaddr[OP_RAND])(aTHX);
329 for (index = items ; index > 1 ; ) {
330 int swap = (int)(Drand01() * (double)(index--));
332 ST(swap) = ST(index);
339 MODULE=List::Util PACKAGE=Scalar::Util
349 char *ptr = SvPV(str,len);
350 ST(0) = sv_newmortal();
351 (void)SvUPGRADE(ST(0),SVt_PVNV);
352 sv_setpvn(ST(0),ptr,len);
353 if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
354 SvNVX(ST(0)) = SvNV(num);
358 else if (SvUOK(num)) {
359 SvUVX(ST(0)) = SvUV(num);
365 SvIVX(ST(0)) = SvIV(num);
368 if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
381 if(!sv_isobject(sv)) {
384 RETVAL = sv_reftype(SvRV(sv),TRUE);
400 RETVAL = sv_reftype(SvRV(sv),FALSE);
414 RETVAL = PTR2IV(SvRV(sv));
427 croak("weak references are not implemented in this release of perl");
436 ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
439 croak("weak references are not implemented in this release of perl");
447 RETVAL = SvREADONLY(sv);
456 RETVAL = SvTAINTED(sv);
466 ST(0) = boolSV(SvVOK(sv));
469 croak("vstrings are not implemented in this release of perl");
475 #if !defined(SvWEAKREF) || !defined(SvVOK)
476 HV *stash = gv_stashpvn("Scalar::Util", 12, TRUE);
477 GV *vargv = *(GV**)hv_fetch(stash, "EXPORT_FAIL", 11, TRUE);
479 if (SvTYPE(vargv) != SVt_PVGV)
480 gv_init(vargv, stash, "Scalar::Util", 12, TRUE);
481 varav = GvAVn(vargv);
484 av_push(varav, newSVpv("weaken",6));
485 av_push(varav, newSVpv("isweak",6));
488 av_push(varav, newSVpv("isvstring",9));