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);
245 for(index = 2 ; index < items ; index++) {
246 GvSV(bgv) = ST(index);
249 SvSetSV(ret, *PL_stack_sp);
252 POPBLOCK(cx,PL_curpm);
271 I32 gimme = G_SCALAR;
273 bool oldcatch = CATCH_GET;
278 SAVESPTR(GvSV(PL_defgv));
279 cv = sv_2cv(block, &stash, &gv, 0);
280 reducecop = CvSTART(cv);
281 SAVESPTR(CvROOT(cv)->op_ppaddr);
282 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
284 PAD_SET_CUR(CvPADLIST(cv),1);
287 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
292 PUSHBLOCK(cx, CXt_SUB, SP);
295 for(index = 1 ; index < items ; index++) {
296 GvSV(PL_defgv) = ST(index);
299 if (SvTRUE(*PL_stack_sp)) {
301 POPBLOCK(cx,PL_curpm);
307 POPBLOCK(cx,PL_curpm);
320 struct op *old_op = PL_op;
322 /* We call pp_rand here so that Drand01 get initialized if rand()
323 or srand() has not already been called
325 memzero((char*)(&dmy_op), sizeof(struct op));
326 /* we let pp_rand() borrow the TARG allocated for this XS sub */
327 dmy_op.op_targ = PL_op->op_targ;
329 (void)*(PL_ppaddr[OP_RAND])(aTHX);
331 for (index = items ; index > 1 ; ) {
332 int swap = (int)(Drand01() * (double)(index--));
334 ST(swap) = ST(index);
341 MODULE=List::Util PACKAGE=Scalar::Util
351 char *ptr = SvPV(str,len);
352 ST(0) = sv_newmortal();
353 (void)SvUPGRADE(ST(0),SVt_PVNV);
354 sv_setpvn(ST(0),ptr,len);
355 if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
356 SvNV_set(ST(0), SvNV(num));
360 else if (SvUOK(num)) {
361 SvUV_set(ST(0), SvUV(num));
367 SvIV_set(ST(0), SvIV(num));
370 if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
383 if(!sv_isobject(sv)) {
386 RETVAL = sv_reftype(SvRV(sv),TRUE);
402 RETVAL = sv_reftype(SvRV(sv),FALSE);
418 RETVAL = PTR2UV(SvRV(sv));
431 croak("weak references are not implemented in this release of perl");
440 ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
443 croak("weak references are not implemented in this release of perl");
451 RETVAL = SvREADONLY(sv);
460 RETVAL = SvTAINTED(sv);
470 ST(0) = boolSV(SvVOK(sv));
473 croak("vstrings are not implemented in this release of perl");
477 looks_like_number(sv)
481 RETVAL = looks_like_number(sv);
486 set_prototype(subref, proto)
493 SV *sv = SvRV(subref);
494 if (SvTYPE(sv) != SVt_PVCV) {
495 /* not a subroutine reference */
496 croak("set_prototype: not a subroutine reference");
499 /* set the prototype */
501 char *ptr = SvPV(proto, len);
502 sv_setpvn(sv, ptr, len);
505 /* delete the prototype */
510 croak("set_prototype: not a reference");
517 #if !defined(SvWEAKREF) || !defined(SvVOK)
518 HV *stash = gv_stashpvn("Scalar::Util", 12, TRUE);
519 GV *vargv = *(GV**)hv_fetch(stash, "EXPORT_FAIL", 11, TRUE);
521 if (SvTYPE(vargv) != SVt_PVGV)
522 gv_init(vargv, stash, "Scalar::Util", 12, TRUE);
523 varav = GvAVn(vargv);
526 av_push(varav, newSVpv("weaken",6));
527 av_push(varav, newSVpv("isweak",6));
530 av_push(varav, newSVpv("isvstring",9));