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

#line 1 "Net.xs"
/*
 * Math::Random::MT::Net
 * Copyright 2001 Abhijit Menon-Sen <ams@wiw.org>
 * Copyright 2005 Jerry D. Hedden <jdhedden@1979.usna.com>
 */

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"

#include "mt19937ar.h"

typedef struct mt * Math__Random__MT__Net;

void * U32ArrayPtr ( int n ) {
    SV * sv = sv_2mortal( NEWSV( 0, n*sizeof(U32) ) );
    return SvPVX(sv);
}

#line 31 "Net.c"
XS(XS_Math__Random__MT__Net_mt_init); /* prototype to pass -Wmissing-prototypes */
XS(XS_Math__Random__MT__Net_mt_init)
{
    dXSARGS;
    if (items < 1)
	Perl_croak(aTHX_ "Usage: Math::Random::MT::Net::mt_init(array, ...)");
    {
	Math__Random__MT__Net	RETVAL;
#line 27 "Net.xs"
        U32 * array = U32ArrayPtr( items );
        U32 ix_array = 0;
        while (items--) {
            array[ix_array] = (U32)SvIV(ST(ix_array));
            ix_array++;
        }
        RETVAL = genrand_init_by_array( (uint32_t*)array, ix_array );
#line 48 "Net.c"
	ST(0) = sv_newmortal();
	sv_setref_pv(ST(0), "Math::Random::MT::Net", (void*)RETVAL);
    }
    XSRETURN(1);
}

XS(XS_Math__Random__MT__Net_mt_rand32); /* prototype to pass -Wmissing-prototypes */
XS(XS_Math__Random__MT__Net_mt_rand32)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Math::Random::MT::Net::mt_rand32(self)");
    {
	Math__Random__MT__Net	self;
	U32	RETVAL;
	dXSTARG;

	if (sv_derived_from(ST(0), "Math::Random::MT::Net")) {
	    IV tmp = SvIV((SV*)SvRV(ST(0)));
	    self = INT2PTR(Math__Random__MT__Net,tmp);
	}
	else
	    Perl_croak(aTHX_ "self is not of type Math::Random::MT::Net");
#line 41 "Net.xs"
        RETVAL = genrand_rand32(self);
#line 74 "Net.c"
	XSprePUSH; PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}

XS(XS_Math__Random__MT__Net_mt_DESTROY); /* prototype to pass -Wmissing-prototypes */
XS(XS_Math__Random__MT__Net_mt_DESTROY)
{
    dXSARGS;
    if (items != 1)
	Perl_croak(aTHX_ "Usage: Math::Random::MT::Net::mt_DESTROY(self)");
    {
	Math__Random__MT__Net	self;

	if (SvROK(ST(0))) {
	    IV tmp = SvIV((SV*)SvRV(ST(0)));
	    self = INT2PTR(Math__Random__MT__Net,tmp);
	}
	else
	    Perl_croak(aTHX_ "self is not a reference");
#line 49 "Net.xs"
        genrand_free(self);
#line 97 "Net.c"
    }
    XSRETURN_EMPTY;
}

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

    XS_VERSION_BOOTCHECK ;

        newXS("Math::Random::MT::Net::mt_init", XS_Math__Random__MT__Net_mt_init, file);
        newXS("Math::Random::MT::Net::mt_rand32", XS_Math__Random__MT__Net_mt_rand32, file);
        newXS("Math::Random::MT::Net::mt_DESTROY", XS_Math__Random__MT__Net_mt_DESTROY, file);
    XSRETURN_YES;
}

