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
21 # include "multicall.h"
28 /* Some platforms have strict exports. And before 5.7.3 cxinc (or Perl_cxinc)
29 was not exported. Therefore platforms like win32, VMS etc have problems
30 so we redefine it here -- GMB
34 # define SvUOK(sv) SvIOK_UV(sv)
38 # define cxinc() my_cxinc(aTHX)
42 cxstack_max = cxstack_max * 3 / 2;
43 Renew(cxstack, cxstack_max + 1, struct context); /* XXX should fix CXINC macro */
44 return cxstack_ix + 1;
53 # define slu_sv_value(sv) (SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv))
55 # define slu_sv_value(sv) (SvIOK(sv)) ? (NV)(SvIVX(sv)) : (SvNV(sv))
59 # define Drand01() ((rand() & 0x7FFF) / (double) ((unsigned long)1 << 15))
64 # define gv_stashpvn(n,l,c) gv_stashpv(n,c)
71 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
72 MAGIC *mg = mg_find(sv, 't');
73 if (mg && ((mg->mg_len & 1) || (mg->mg_len & 2) && mg->mg_obj == sv))
79 # define SvTAINTED_on(sv) sv_magic((sv), Nullsv, 't', Nullch, 0)
80 # define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
82 # define PL_defgv defgv
84 # define PL_curpad curpad
85 # define CALLRUNOPS runops
86 # define PL_curpm curpm
87 # define PL_sv_undef sv_undef
88 # define PERL_CONTEXT struct context
90 #if (PERL_VERSION < 5) || (PERL_VERSION == 5 && PERL_SUBVERSION <50)
92 # define PL_tainting tainting
94 # ifndef PL_stack_base
95 # define PL_stack_base stack_base
98 # define PL_stack_sp stack_sp
101 # define PL_ppaddr ppaddr
106 # define PTR2UV(ptr) (UV)(ptr)
110 # define SvUV_set(sv, val) (((XPVUV*)SvANY(sv))->xuv_uv = (val))
113 #ifndef PERL_UNUSED_DECL
115 # if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
116 # define PERL_UNUSED_DECL
118 # define PERL_UNUSED_DECL __attribute__((unused))
121 # define PERL_UNUSED_DECL
126 #define dNOOP extern int Perl___notused PERL_UNUSED_DECL
137 MODULE=List::Util PACKAGE=List::Util
154 retval = slu_sv_value(retsv);
155 for(index = 1 ; index < items ; index++) {
156 SV *stacksv = ST(index);
157 NV val = slu_sv_value(stacksv);
158 if(val < retval ? !ix : ix) {
180 RETVAL = slu_sv_value(sv);
181 for(index = 1 ; index < items ; index++) {
183 RETVAL += slu_sv_value(sv);
204 sv_cmp & sv_cmp_locale return 1,0,-1 for gt,eq,lt
205 so we set ix to the value we are looking for
206 xsubpp does not allow -ve values, so we start with 0,2 and subtract 1
211 if(MAXARG & OPpLOCALE) {
212 for(index = 1 ; index < items ; index++) {
213 SV *right = ST(index);
214 if(sv_cmp_locale(left, right) == ix)
220 for(index = 1 ; index < items ; index++) {
221 SV *right = ST(index);
222 if(sv_cmp(left, right) == ix)
243 SV *ret = sv_newmortal();
247 I32 gimme = G_SCALAR;
248 SV **args = &PL_stack_base[ax];
254 cv = sv_2cv(block, &stash, &gv, 0);
256 agv = gv_fetchpv("a", TRUE, SVt_PV);
257 bgv = gv_fetchpv("b", TRUE, SVt_PV);
261 SvSetSV(ret, args[1]);
262 for(index = 2 ; index < items ; index++) {
263 GvSV(bgv) = args[index];
265 SvSetSV(ret, *PL_stack_sp);
282 I32 gimme = G_SCALAR;
283 SV **args = &PL_stack_base[ax];
289 cv = sv_2cv(block, &stash, &gv, 0);
291 SAVESPTR(GvSV(PL_defgv));
293 for(index = 1 ; index < items ; index++) {
294 GvSV(PL_defgv) = args[index];
296 if (SvTRUE(*PL_stack_sp)) {
315 #if (PERL_VERSION < 8) || (PERL_VERSION == 8 && PERL_SUBVERSION <1)
317 struct op *old_op = PL_op;
319 /* We call pp_rand here so that Drand01 get initialized if rand()
320 or srand() has not already been called
322 memzero((char*)(&dmy_op), sizeof(struct op));
323 /* we let pp_rand() borrow the TARG allocated for this XS sub */
324 dmy_op.op_targ = PL_op->op_targ;
326 (void)*(PL_ppaddr[OP_RAND])(aTHX);
329 /* Initialize Drand01 if rand() or srand() has
330 not already been called
332 if (!PL_srand_called) {
333 (void)seedDrand01((Rand_seed_t)Perl_seed(aTHX));
334 PL_srand_called = TRUE;
338 for (index = items ; index > 1 ; ) {
339 int swap = (int)(Drand01() * (double)(index--));
341 ST(swap) = ST(index);
348 MODULE=List::Util PACKAGE=Scalar::Util
358 char *ptr = SvPV(str,len);
359 ST(0) = sv_newmortal();
360 (void)SvUPGRADE(ST(0),SVt_PVNV);
361 sv_setpvn(ST(0),ptr,len);
362 if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
363 SvNV_set(ST(0), SvNV(num));
367 else if (SvUOK(num)) {
368 SvUV_set(ST(0), SvUV(num));
374 SvIV_set(ST(0), SvIV(num));
377 if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
390 if(!sv_isobject(sv)) {
393 RETVAL = sv_reftype(SvRV(sv),TRUE);
409 RETVAL = sv_reftype(SvRV(sv),FALSE);
425 RETVAL = PTR2UV(SvRV(sv));
438 croak("weak references are not implemented in this release of perl");
447 ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
450 croak("weak references are not implemented in this release of perl");
458 RETVAL = SvREADONLY(sv);
467 RETVAL = SvTAINTED(sv);
477 ST(0) = boolSV(SvVOK(sv));
480 croak("vstrings are not implemented in this release of perl");
484 looks_like_number(sv)
488 RETVAL = looks_like_number(sv);
493 set_prototype(subref, proto)
500 SV *sv = SvRV(subref);
501 if (SvTYPE(sv) != SVt_PVCV) {
502 /* not a subroutine reference */
503 croak("set_prototype: not a subroutine reference");
506 /* set the prototype */
508 char *ptr = SvPV(proto, len);
509 sv_setpvn(sv, ptr, len);
512 /* delete the prototype */
517 croak("set_prototype: not a reference");
524 HV *lu_stash = gv_stashpvn("List::Util", 10, TRUE);
525 GV *rmcgv = *(GV**)hv_fetch(lu_stash, "REAL_MULTICALL", 14, TRUE);
527 #if !defined(SvWEAKREF) || !defined(SvVOK)
528 HV *su_stash = gv_stashpvn("Scalar::Util", 12, TRUE);
529 GV *vargv = *(GV**)hv_fetch(su_stash, "EXPORT_FAIL", 11, TRUE);
531 if (SvTYPE(vargv) != SVt_PVGV)
532 gv_init(vargv, su_stash, "Scalar::Util", 12, TRUE);
533 varav = GvAVn(vargv);
535 if (SvTYPE(rmcgv) != SVt_PVGV)
536 gv_init(rmcgv, lu_stash, "List::Util", 12, TRUE);
537 rmcsv = GvSVn(rmcgv);
539 av_push(varav, newSVpv("weaken",6));
540 av_push(varav, newSVpv("isweak",6));
543 av_push(varav, newSVpv("isvstring",9));
545 #ifdef REAL_MULTICALL
546 sv_setsv(rmcsv, &PL_sv_yes);
548 sv_setsv(rmcsv, &PL_sv_no);