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)
107 # define SvUV_set(sv, val) (((XPVUV*)SvANY(sv))->xuv_uv = (val))
111 # if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
112 # define PERL_UNUSED_DECL
114 # define PERL_UNUSED_DECL __attribute__((unused))
117 # define PERL_UNUSED_DECL
121 #define dNOOP extern int Perl___notused PERL_UNUSED_DECL
128 MODULE=List::Util PACKAGE=List::Util
145 retval = slu_sv_value(retsv);
146 for(index = 1 ; index < items ; index++) {
147 SV *stacksv = ST(index);
148 NV val = slu_sv_value(stacksv);
149 if(val < retval ? !ix : ix) {
171 RETVAL = slu_sv_value(sv);
172 for(index = 1 ; index < items ; index++) {
174 RETVAL += slu_sv_value(sv);
195 sv_cmp & sv_cmp_locale return 1,0,-1 for gt,eq,lt
196 so we set ix to the value we are looking for
197 xsubpp does not allow -ve values, so we start with 0,2 and subtract 1
202 if(MAXARG & OPpLOCALE) {
203 for(index = 1 ; index < items ; index++) {
204 SV *right = ST(index);
205 if(sv_cmp_locale(left, right) == ix)
211 for(index = 1 ; index < items ; index++) {
212 SV *right = ST(index);
213 if(sv_cmp(left, right) == ix)
232 SV *ret = sv_newmortal();
240 I32 gimme = G_SCALAR;
242 bool oldcatch = CATCH_GET;
247 agv = gv_fetchpv("a", TRUE, SVt_PV);
248 bgv = gv_fetchpv("b", TRUE, SVt_PV);
252 cv = sv_2cv(block, &stash, &gv, 0);
253 reducecop = CvSTART(cv);
254 SAVESPTR(CvROOT(cv)->op_ppaddr);
255 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
257 PAD_SET_CUR(CvPADLIST(cv),1);
260 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
266 PUSHBLOCK(cx, CXt_SUB, SP);
268 for(index = 2 ; index < items ; index++) {
269 GvSV(bgv) = ST(index);
272 SvSetSV(ret, *PL_stack_sp);
275 POPBLOCK(cx,PL_curpm);
294 I32 gimme = G_SCALAR;
296 bool oldcatch = CATCH_GET;
301 SAVESPTR(GvSV(PL_defgv));
302 cv = sv_2cv(block, &stash, &gv, 0);
303 reducecop = CvSTART(cv);
304 SAVESPTR(CvROOT(cv)->op_ppaddr);
305 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
307 PAD_SET_CUR(CvPADLIST(cv),1);
310 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
315 PUSHBLOCK(cx, CXt_SUB, SP);
318 for(index = 1 ; index < items ; index++) {
319 GvSV(PL_defgv) = ST(index);
322 if (SvTRUE(*PL_stack_sp)) {
324 POPBLOCK(cx,PL_curpm);
329 POPBLOCK(cx,PL_curpm);
342 struct op *old_op = PL_op;
344 /* We call pp_rand here so that Drand01 get initialized if rand()
345 or srand() has not already been called
347 memzero((char*)(&dmy_op), sizeof(struct op));
348 /* we let pp_rand() borrow the TARG allocated for this XS sub */
349 dmy_op.op_targ = PL_op->op_targ;
351 (void)*(PL_ppaddr[OP_RAND])(aTHX);
353 for (index = items ; index > 1 ; ) {
354 int swap = (int)(Drand01() * (double)(index--));
356 ST(swap) = ST(index);
363 MODULE=List::Util PACKAGE=Scalar::Util
373 char *ptr = SvPV(str,len);
374 ST(0) = sv_newmortal();
375 (void)SvUPGRADE(ST(0),SVt_PVNV);
376 sv_setpvn(ST(0),ptr,len);
377 if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
378 SvNV_set(ST(0), SvNV(num));
382 else if (SvUOK(num)) {
383 SvUV_set(ST(0), SvUV(num));
389 SvIV_set(ST(0), SvIV(num));
392 if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
405 if(!sv_isobject(sv)) {
408 RETVAL = sv_reftype(SvRV(sv),TRUE);
424 RETVAL = sv_reftype(SvRV(sv),FALSE);
440 RETVAL = PTR2UV(SvRV(sv));
453 croak("weak references are not implemented in this release of perl");
462 ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
465 croak("weak references are not implemented in this release of perl");
473 RETVAL = SvREADONLY(sv);
482 RETVAL = SvTAINTED(sv);
492 ST(0) = boolSV(SvVOK(sv));
495 croak("vstrings are not implemented in this release of perl");
499 looks_like_number(sv)
503 RETVAL = looks_like_number(sv);
508 set_prototype(subref, proto)
515 SV *sv = SvRV(subref);
516 if (SvTYPE(sv) != SVt_PVCV) {
517 /* not a subroutine reference */
518 croak("set_prototype: not a subroutine reference");
521 /* set the prototype */
523 char *ptr = SvPV(proto, len);
524 sv_setpvn(sv, ptr, len);
527 /* delete the prototype */
532 croak("set_prototype: not a reference");
539 #if !defined(SvWEAKREF) || !defined(SvVOK)
540 HV *stash = gv_stashpvn("Scalar::Util", 12, TRUE);
541 GV *vargv = *(GV**)hv_fetch(stash, "EXPORT_FAIL", 11, TRUE);
543 if (SvTYPE(vargv) != SVt_PVGV)
544 gv_init(vargv, stash, "Scalar::Util", 12, TRUE);
545 varav = GvAVn(vargv);
548 av_push(varav, newSVpv("weaken",6));
549 av_push(varav, newSVpv("isweak",6));
552 av_push(varav, newSVpv("isvstring",9));