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
25 /* Some platforms have strict exports. And before 5.7.3 cxinc (or Perl_cxinc)
26 was not exported. Therefore platforms like win32, VMS etc have problems
27 so we redefine it here -- GMB
31 # define SvUOK(sv) SvIOK_UV(sv)
35 # define cxinc() my_cxinc(aTHX)
39 cxstack_max = cxstack_max * 3 / 2;
40 Renew(cxstack, cxstack_max + 1, struct context); /* XXX should fix CXINC macro */
41 return cxstack_ix + 1;
50 # define slu_sv_value(sv) (SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv))
52 # define slu_sv_value(sv) (SvIOK(sv)) ? (NV)(SvIVX(sv)) : (SvNV(sv))
56 # define Drand01() ((rand() & 0x7FFF) / (double) ((unsigned long)1 << 15))
61 # define gv_stashpvn(n,l,c) gv_stashpv(n,c)
68 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
69 MAGIC *mg = mg_find(sv, 't');
70 if (mg && ((mg->mg_len & 1) || (mg->mg_len & 2) && mg->mg_obj == sv))
76 # define SvTAINTED_on(sv) sv_magic((sv), Nullsv, 't', Nullch, 0)
77 # define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
79 # define PL_defgv defgv
81 # define PL_curpad curpad
82 # define CALLRUNOPS runops
83 # define PL_curpm curpm
84 # define PL_sv_undef sv_undef
85 # define PERL_CONTEXT struct context
87 #if (PERL_VERSION < 5) || (PERL_VERSION == 5 && PERL_SUBVERSION <50)
89 # define PL_tainting tainting
91 # ifndef PL_stack_base
92 # define PL_stack_base stack_base
95 # define PL_stack_sp stack_sp
98 # define PL_ppaddr ppaddr
103 # define PTR2UV(ptr) (UV)(ptr)
106 MODULE=List::Util PACKAGE=List::Util
123 retval = slu_sv_value(retsv);
124 for(index = 1 ; index < items ; index++) {
125 SV *stacksv = ST(index);
126 NV val = slu_sv_value(stacksv);
127 if(val < retval ? !ix : ix) {
149 RETVAL = slu_sv_value(sv);
150 for(index = 1 ; index < items ; index++) {
152 RETVAL += slu_sv_value(sv);
173 sv_cmp & sv_cmp_locale return 1,0,-1 for gt,eq,lt
174 so we set ix to the value we are looking for
175 xsubpp does not allow -ve values, so we start with 0,2 and subtract 1
180 if(MAXARG & OPpLOCALE) {
181 for(index = 1 ; index < items ; index++) {
182 SV *right = ST(index);
183 if(sv_cmp_locale(left, right) == ix)
189 for(index = 1 ; index < items ; index++) {
190 SV *right = ST(index);
191 if(sv_cmp(left, right) == ix)
209 SV *ret = sv_newmortal();
217 I32 gimme = G_SCALAR;
219 bool oldcatch = CATCH_GET;
224 agv = gv_fetchpv("a", TRUE, SVt_PV);
225 bgv = gv_fetchpv("b", TRUE, SVt_PV);
229 cv = sv_2cv(block, &stash, &gv, 0);
230 reducecop = CvSTART(cv);
231 SAVESPTR(CvROOT(cv)->op_ppaddr);
232 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
234 PAD_SET_CUR(CvPADLIST(cv),1);
237 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
243 PUSHBLOCK(cx, CXt_SUB, SP);
246 (void)SvREFCNT_inc(cv);
247 for(index = 2 ; index < items ; index++) {
248 GvSV(bgv) = ST(index);
251 SvSetSV(ret, *PL_stack_sp);
254 POPBLOCK(cx,PL_curpm);
272 I32 gimme = G_SCALAR;
274 bool oldcatch = CATCH_GET;
279 SAVESPTR(GvSV(PL_defgv));
280 cv = sv_2cv(block, &stash, &gv, 0);
281 reducecop = CvSTART(cv);
282 SAVESPTR(CvROOT(cv)->op_ppaddr);
283 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
285 PAD_SET_CUR(CvPADLIST(cv),1);
288 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
293 PUSHBLOCK(cx, CXt_SUB, SP);
296 (void)SvREFCNT_inc(cv);
298 for(index = 1 ; index < items ; index++) {
299 GvSV(PL_defgv) = ST(index);
302 if (SvTRUE(*PL_stack_sp)) {
304 POPBLOCK(cx,PL_curpm);
309 POPBLOCK(cx,PL_curpm);
321 struct op *old_op = PL_op;
323 /* We call pp_rand here so that Drand01 get initialized if rand()
324 or srand() has not already been called
326 memzero((char*)(&dmy_op), sizeof(struct op));
327 /* we let pp_rand() borrow the TARG allocated for this XS sub */
328 dmy_op.op_targ = PL_op->op_targ;
330 (void)*(PL_ppaddr[OP_RAND])(aTHX);
332 for (index = items ; index > 1 ; ) {
333 int swap = (int)(Drand01() * (double)(index--));
335 ST(swap) = ST(index);
342 MODULE=List::Util PACKAGE=Scalar::Util
352 char *ptr = SvPV(str,len);
353 ST(0) = sv_newmortal();
354 (void)SvUPGRADE(ST(0),SVt_PVNV);
355 sv_setpvn(ST(0),ptr,len);
356 if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
357 SvNVX(ST(0)) = SvNV(num);
361 else if (SvUOK(num)) {
362 SvUVX(ST(0)) = SvUV(num);
368 SvIVX(ST(0)) = SvIV(num);
371 if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
384 if(!sv_isobject(sv)) {
387 RETVAL = sv_reftype(SvRV(sv),TRUE);
403 RETVAL = sv_reftype(SvRV(sv),FALSE);
417 RETVAL = PTR2UV(SvRV(sv));
430 croak("weak references are not implemented in this release of perl");
439 ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
442 croak("weak references are not implemented in this release of perl");
450 RETVAL = SvREADONLY(sv);
459 RETVAL = SvTAINTED(sv);
469 ST(0) = boolSV(SvVOK(sv));
472 croak("vstrings are not implemented in this release of perl");
476 looks_like_number(sv)
480 RETVAL = looks_like_number(sv);
485 set_prototype(subref, proto)
492 SV *sv = SvRV(subref);
493 if (SvTYPE(sv) != SVt_PVCV) {
494 /* not a subroutine reference */
495 croak("set_prototype: not a subroutine reference");
498 /* set the prototype */
500 char *ptr = SvPV(proto, len);
501 sv_setpvn(sv, ptr, len);
504 /* delete the prototype */
509 croak("set_prototype: not a reference");
516 #if !defined(SvWEAKREF) || !defined(SvVOK)
517 HV *stash = gv_stashpvn("Scalar::Util", 12, TRUE);
518 GV *vargv = *(GV**)hv_fetch(stash, "EXPORT_FAIL", 11, TRUE);
520 if (SvTYPE(vargv) != SVt_PVGV)
521 gv_init(vargv, stash, "Scalar::Util", 12, TRUE);
522 varav = GvAVn(vargv);
525 av_push(varav, newSVpv("weaken",6));
526 av_push(varav, newSVpv("isweak",6));
529 av_push(varav, newSVpv("isvstring",9));