Plan 9 from Bell Labs’s /usr/web/sources/contrib/gabidiaz/root/sys/src/cmd/perl/ext/List/Util/ListUtil.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/*
 * This file was generated automatically by xsubpp version 1.9508 from the
 * contents of Util.xs. Do not edit this file, edit Util.xs instead.
 *
 *	ANY CHANGES MADE HERE WILL BE LOST!
 *
 */

#line 1 "Util.xs"
/* Copyright (c) 1997-2000 Graham Barr <[email protected]>. All rights reserved.
 * This program is free software; you can redistribute it and/or
 * modify it under the same terms as Perl itself.
 */

#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>

#ifndef PERL_VERSION
#    include "patchlevel.h"
#    define PERL_REVISION	5
#    define PERL_VERSION	PATCHLEVEL
#    define PERL_SUBVERSION	SUBVERSION
#endif

#ifndef aTHX
#  define aTHX
#  define pTHX
#endif

/* Some platforms have strict exports. And before 5.7.3 cxinc (or Perl_cxinc)
   was not exported. Therefore platforms like win32, VMS etc have problems
   so we redefine it here -- GMB
*/
#if PERL_VERSION < 7
/* Not in 5.6.1. */
#  define SvUOK(sv)           SvIOK_UV(sv)
#  ifdef cxinc
#    undef cxinc
#  endif
#  define cxinc() my_cxinc(aTHX)
static I32
my_cxinc(pTHX)
{
    cxstack_max = cxstack_max * 3 / 2;
    Renew(cxstack, cxstack_max + 1, struct context);      /* XXX should fix CXINC macro */
    return cxstack_ix + 1;
}
#endif

#if PERL_VERSION < 6
#    define NV double
#endif

#ifndef Drand01
#    define Drand01()		((rand() & 0x7FFF) / (double) ((unsigned long)1 << 15))
#endif

#if PERL_VERSION < 5
#  ifndef gv_stashpvn
#    define gv_stashpvn(n,l,c) gv_stashpv(n,c)
#  endif
#  ifndef SvTAINTED

static bool
sv_tainted(SV *sv)
{
    if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
	MAGIC *mg = mg_find(sv, 't');
	if (mg && ((mg->mg_len & 1) || (mg->mg_len & 2) && mg->mg_obj == sv))
	    return TRUE;
    }
    return FALSE;
}

#    define SvTAINTED_on(sv) sv_magic((sv), Nullsv, 't', Nullch, 0)
#    define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
#  endif
#  define PL_defgv defgv
#  define PL_op op
#  define PL_curpad curpad
#  define CALLRUNOPS runops
#  define PL_curpm curpm
#  define PL_sv_undef sv_undef
#  define PERL_CONTEXT struct context
#endif
#if (PERL_VERSION < 5) || (PERL_VERSION == 5 && PERL_SUBVERSION <50)
#  ifndef PL_tainting
#    define PL_tainting tainting
#  endif
#  ifndef PL_stack_base
#    define PL_stack_base stack_base
#  endif
#  ifndef PL_stack_sp
#    define PL_stack_sp stack_sp
#  endif
#  ifndef PL_ppaddr
#    define PL_ppaddr ppaddr
#  endif
#endif

#line 103 "Util.c"
XS(XS_List__Util_min); /* prototype to pass -Wmissing-prototypes */
XS(XS_List__Util_min)
{
    dXSARGS;
    dXSI32;
    {
#line 102 "Util.xs"
{
    int index;
    NV retval;
    SV *retsv;
    if(!items) {
	XSRETURN_UNDEF;
    }
    retsv = ST(0);
    retval = SvNV(retsv);
    for(index = 1 ; index < items ; index++) {
	SV *stacksv = ST(index);
	NV val = SvNV(stacksv);
	if(val < retval ? !ix : ix) {
	    retsv = stacksv;
	    retval = val;
	}
    }
    ST(0) = retsv;
    XSRETURN(1);
}
#line 131 "Util.c"
    }
    XSRETURN(1);
}

XS(XS_List__Util_sum); /* prototype to pass -Wmissing-prototypes */
XS(XS_List__Util_sum)
{
    dXSARGS;
    {
	NV	RETVAL;
	dXSTARG;
#line 129 "Util.xs"
{
    int index;
    if(!items) {
	XSRETURN_UNDEF;
    }
    RETVAL = SvNV(ST(0));
    for(index = 1 ; index < items ; index++) {
	RETVAL += SvNV(ST(index));
    }
}
#line 154 "Util.c"
	XSprePUSH; PUSHn((NV)RETVAL);
    }
    XSRETURN(1);
}

XS(XS_List__Util_minstr); /* prototype to pass -Wmissing-prototypes */
XS(XS_List__Util_minstr)
{
    dXSARGS;
    dXSI32;
    {
#line 150 "Util.xs"
{
    SV *left;
    int index;
    if(!items) {
	XSRETURN_UNDEF;
    }
    /*
      sv_cmp & sv_cmp_locale return 1,0,-1 for gt,eq,lt
      so we set ix to the value we are looking for
      xsubpp does not allow -ve values, so we start with 0,2 and subtract 1
    */
    ix -= 1;
    left = ST(0);
#ifdef OPpLOCALE
    if(MAXARG & OPpLOCALE) {
	for(index = 1 ; index < items ; index++) {
	    SV *right = ST(index);
	    if(sv_cmp_locale(left, right) == ix)
		left = right;
	}
    }
    else {
#endif
	for(index = 1 ; index < items ; index++) {
	    SV *right = ST(index);
	    if(sv_cmp(left, right) == ix)
		left = right;
	}
#ifdef OPpLOCALE
    }
#endif
    ST(0) = left;
    XSRETURN(1);
}
#line 201 "Util.c"
    }
    XSRETURN(1);
}

XS(XS_List__Util_reduce); /* prototype to pass -Wmissing-prototypes */
XS(XS_List__Util_reduce)
{
    dXSARGS;
    if (items < 1)
	Perl_croak(aTHX_ "Usage: List::Util::reduce(block, ...)");
    {
	SV *	block = ST(0);
#line 192 "Util.xs"
{
    SV *ret;
    int index;
    GV *agv,*bgv,*gv;
    HV *stash;
    CV *cv;
    OP *reducecop;
    PERL_CONTEXT *cx;
    SV** newsp;
    I32 gimme = G_SCALAR;
    bool oldcatch = CATCH_GET;

    if(items <= 1) {
	XSRETURN_UNDEF;
    }
    agv = gv_fetchpv("a", TRUE, SVt_PV);
    bgv = gv_fetchpv("b", TRUE, SVt_PV);
    SAVESPTR(GvSV(agv));
    SAVESPTR(GvSV(bgv));
    cv = sv_2cv(block, &stash, &gv, 0);
    reducecop = CvSTART(cv);
    SAVESPTR(CvROOT(cv)->op_ppaddr);
    CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
    SAVESPTR(PL_curpad);
    PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
    SAVETMPS;
    SAVESPTR(PL_op);
    ret = ST(1);
    CATCH_SET(TRUE);
    PUSHBLOCK(cx, CXt_NULL, SP);
    for(index = 2 ; index < items ; index++) {
	GvSV(agv) = ret;
	GvSV(bgv) = ST(index);
	PL_op = reducecop;
	CALLRUNOPS(aTHX);
	ret = *PL_stack_sp;
    }
    ST(0) = sv_mortalcopy(ret);
    POPBLOCK(cx,PL_curpm);
    CATCH_SET(oldcatch);
    XSRETURN(1);
}
#line 257 "Util.c"
    }
    XSRETURN(1);
}

XS(XS_List__Util_first); /* prototype to pass -Wmissing-prototypes */
XS(XS_List__Util_first)
{
    dXSARGS;
    if (items < 1)
	Perl_croak(aTHX_ "Usage: List::Util::first(block, ...)");
    {
	SV *	block = ST(0);
#line 240 "Util.xs"
{
    int index;
    GV *gv;
    HV *stash;
    CV *cv;
    OP *reducecop;
    PERL_CONTEXT *cx;
    SV** newsp;
    I32 gimme = G_SCALAR;
    bool oldcatch = CATCH_GET;

    if(items <= 1) {
	XSRETURN_UNDEF;
    }
    SAVESPTR(GvSV(PL_defgv));
    cv = sv_2cv(block, &stash, &gv, 0);
    reducecop = CvSTART(cv);
    SAVESPTR(CvROOT(cv)->op_ppaddr);
    CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
    SAVESPTR(PL_curpad);
    PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
    SAVETMPS;
    SAVESPTR(PL_op);
    CATCH_SET(TRUE);
    PUSHBLOCK(cx, CXt_NULL, SP);
    for(index = 1 ; index < items ; index++) {
	GvSV(PL_defgv) = ST(index);
	PL_op = reducecop;
	CALLRUNOPS(aTHX);
	if (SvTRUE(*PL_stack_sp)) {
	  ST(0) = ST(index);
	  POPBLOCK(cx,PL_curpm);
	  CATCH_SET(oldcatch);
	  XSRETURN(1);
	}
    }
    POPBLOCK(cx,PL_curpm);
    CATCH_SET(oldcatch);
    XSRETURN_UNDEF;
}
#line 311 "Util.c"
    }
    XSRETURN(1);
}

XS(XS_List__Util_shuffle); /* prototype to pass -Wmissing-prototypes */
XS(XS_List__Util_shuffle)
{
    dXSARGS;
    {
#line 285 "Util.xs"
{
    int index;
    struct op dmy_op;
    struct op *old_op = PL_op;
    SV *my_pad[2];
    SV **old_curpad = PL_curpad;

    /* We call pp_rand here so that Drand01 get initialized if rand()
       or srand() has not already been called
    */
    my_pad[1] = sv_newmortal();
    memzero((char*)(&dmy_op), sizeof(struct op));
    dmy_op.op_targ = 1;
    PL_op = &dmy_op;
    PL_curpad = (SV **)&my_pad;
    (void)*(PL_ppaddr[OP_RAND])(aTHX);
    PL_op = old_op;
    PL_curpad = old_curpad;
    for (index = items ; index > 1 ; ) {
	int swap = (int)(Drand01() * (double)(index--));
	SV *tmp = ST(swap);
	ST(swap) = ST(index);
	ST(index) = tmp;
    }
    XSRETURN(items);
}
#line 348 "Util.c"
    }
    XSRETURN(1);
}

XS(XS_Scalar__Util_dualvar); /* prototype to pass -Wmissing-prototypes */
XS(XS_Scalar__Util_dualvar)
{
    dXSARGS;
    if (items != 2)
	Perl_croak(aTHX_ "Usage: Scalar::Util::dualvar(num, str)");
    {
	SV *	num = ST(0);
	SV *	str = ST(1);
#line 321 "Util.xs"
{
    STRLEN len;
    char *ptr = SvPV(str,len);
    ST(0) = sv_newmortal();
    (void)SvUPGRADE(ST(0),SVt_PVNV);
    sv_setpvn(ST(0),ptr,len);
    if(SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
	SvNVX(ST(0)) = SvNV(num);
	SvNOK_on(ST(0));
    }
#ifdef SVf_IVisUV
    else if (SvUOK(num)) {
	SvUVX(ST(0)) = SvUV(num);
	SvIOK_on(ST(0));
	SvIsUV_on(ST(0));
    }
#endif
    else {
	SvIVX(ST(0)) = SvIV(num);
	SvIOK_on(ST(0));
    }
    if(PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
	SvTAINTED_on(ST(0));
    XSRETURN(1);
}
#line 388 "Util.c"
    }
    XSRETURN(1);
}

XS(XS_Scalar__Util_blessed); /* prototype to pass -Wmissing-prototypes */
XS(XS_Scalar__Util_blessed)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Scalar::Util::blessed(sv)");
    {
	SV *	sv = ST(0);
	char *	RETVAL;
	dXSTARG;
#line 352 "Util.xs"
{
    if (SvMAGICAL(sv))
	mg_get(sv);
    if(!sv_isobject(sv)) {
	XSRETURN_UNDEF;
    }
    RETVAL = sv_reftype(SvRV(sv),TRUE);
}
#line 412 "Util.c"
	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}

XS(XS_Scalar__Util_reftype); /* prototype to pass -Wmissing-prototypes */
XS(XS_Scalar__Util_reftype)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Scalar::Util::reftype(sv)");
    {
	SV *	sv = ST(0);
	char *	RETVAL;
	dXSTARG;
#line 368 "Util.xs"
{
    if (SvMAGICAL(sv))
	mg_get(sv);
    if(!SvROK(sv)) {
	XSRETURN_UNDEF;
    }
    RETVAL = sv_reftype(SvRV(sv),FALSE);
}
#line 437 "Util.c"
	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}

XS(XS_Scalar__Util_weaken); /* prototype to pass -Wmissing-prototypes */
XS(XS_Scalar__Util_weaken)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Scalar::Util::weaken(sv)");
    {
	SV *	sv = ST(0);
#line 384 "Util.xs"
#ifdef SvWEAKREF
	sv_rvweaken(sv);
#else
	croak("weak references are not implemented in this release of perl");
#endif
#line 457 "Util.c"
    }
    XSRETURN_EMPTY;
}

XS(XS_Scalar__Util_isweak); /* prototype to pass -Wmissing-prototypes */
XS(XS_Scalar__Util_isweak)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Scalar::Util::isweak(sv)");
    {
	SV *	sv = ST(0);
#line 395 "Util.xs"
#ifdef SvWEAKREF
	ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
	XSRETURN(1);
#else
	croak("weak references are not implemented in this release of perl");
#endif
#line 477 "Util.c"
    }
    XSRETURN(1);
}

XS(XS_Scalar__Util_readonly); /* prototype to pass -Wmissing-prototypes */
XS(XS_Scalar__Util_readonly)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Scalar::Util::readonly(sv)");
    {
	SV *	sv = ST(0);
	int	RETVAL;
	dXSTARG;
#line 407 "Util.xs"
  RETVAL = SvREADONLY(sv);
#line 494 "Util.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}

XS(XS_Scalar__Util_tainted); /* prototype to pass -Wmissing-prototypes */
XS(XS_Scalar__Util_tainted)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Scalar::Util::tainted(sv)");
    {
	SV *	sv = ST(0);
	int	RETVAL;
	dXSTARG;
#line 416 "Util.xs"
  RETVAL = SvTAINTED(sv);
#line 512 "Util.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}

#ifdef __cplusplus
extern "C"
#endif
XS(boot_List__Util); /* prototype to pass -Wmissing-prototypes */
XS(boot_List__Util)
{
    dXSARGS;
    char* file = __FILE__;

    XS_VERSION_BOOTCHECK ;

    {
        CV * cv ;

        cv = newXS("List::Util::max", XS_List__Util_min, file);
        XSANY.any_i32 = 1 ;
        sv_setpv((SV*)cv, "@") ;
        cv = newXS("List::Util::min", XS_List__Util_min, file);
        XSANY.any_i32 = 0 ;
        sv_setpv((SV*)cv, "@") ;
        newXSproto("List::Util::sum", XS_List__Util_sum, file, "@");
        cv = newXS("List::Util::minstr", XS_List__Util_minstr, file);
        XSANY.any_i32 = 2 ;
        sv_setpv((SV*)cv, "@") ;
        cv = newXS("List::Util::maxstr", XS_List__Util_minstr, file);
        XSANY.any_i32 = 0 ;
        sv_setpv((SV*)cv, "@") ;
        newXSproto("List::Util::reduce", XS_List__Util_reduce, file, "&@");
        newXSproto("List::Util::first", XS_List__Util_first, file, "&@");
        newXSproto("List::Util::shuffle", XS_List__Util_shuffle, file, "@");
        newXSproto("Scalar::Util::dualvar", XS_Scalar__Util_dualvar, file, "$$");
        newXSproto("Scalar::Util::blessed", XS_Scalar__Util_blessed, file, "$");
        newXSproto("Scalar::Util::reftype", XS_Scalar__Util_reftype, file, "$");
        newXSproto("Scalar::Util::weaken", XS_Scalar__Util_weaken, file, "$");
        newXSproto("Scalar::Util::isweak", XS_Scalar__Util_isweak, file, "$");
        newXSproto("Scalar::Util::readonly", XS_Scalar__Util_readonly, file, "$");
        newXSproto("Scalar::Util::tainted", XS_Scalar__Util_tainted, file, "$");
    }

    /* Initialisation Section */

#line 421 "Util.xs"
{
#ifndef SvWEAKREF
    HV *stash = gv_stashpvn("Scalar::Util", 12, TRUE);
    GV *vargv = *(GV**)hv_fetch(stash, "EXPORT_FAIL", 11, TRUE);
    AV *varav;
    if (SvTYPE(vargv) != SVt_PVGV)
	gv_init(vargv, stash, "Scalar::Util", 12, TRUE);
    varav = GvAVn(vargv);
    av_push(varav, newSVpv("weaken",6));
    av_push(varav, newSVpv("isweak",6));
#endif
}

#line 573 "Util.c"

    /* End of Initialisation Section */

    XSRETURN_YES;
}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].