/*
 * This file was generated automatically by ExtUtils::ParseXS version 3.24 from the
 * contents of QtCore4.xs. Do not edit this file, edit QtCore4.xs instead.
 *
 *    ANY CHANGES MADE HERE WILL BE LOST!
 *
 */

#line 1 "QtCore4.xs"
//util.h brings in all the required Qt4 headers.  This has to happen before the
//perl stuff below
#include "util.h"

#include <QXmlStreamAttributes>

// Perl headers
extern "C" {
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
}

// Now my own headers
#include "smoke.h"
#include "QtCore4.h"
#include "binding.h"
#include "smokeperl.h"
#include "marshall_types.h" // Method call classes
#include "handlers.h" // for install_handlers function
#include "listclass_macros.h"

extern PerlQt4::Binding binding;
extern Q_DECL_EXPORT Smoke* qtcore_Smoke;
extern "C" void init_qtcore_Smoke();
extern Q_DECL_EXPORT QHash<Smoke*, PerlQt4Module> perlqt_modules;
extern SV* sv_qapp;
Q_DECL_EXPORT QList<Smoke*> smokeList;
QList<QString> arrayTypes;

DEF_VECTORCLASS_FUNCTIONS(QXmlStreamAttributes, QXmlStreamAttribute, Qt::XmlStreamAttributes);

#line 44 "QtCore4.c"
#ifndef PERL_UNUSED_VAR
#  define PERL_UNUSED_VAR(var) if (0) var = var
#endif

#ifndef dVAR
#  define dVAR		dNOOP
#endif


/* This stuff is not part of the API! You have been warned. */
#ifndef PERL_VERSION_DECIMAL
#  define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
#endif
#ifndef PERL_DECIMAL_VERSION
#  define PERL_DECIMAL_VERSION \
	  PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
#endif
#ifndef PERL_VERSION_GE
#  define PERL_VERSION_GE(r,v,s) \
	  (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
#endif
#ifndef PERL_VERSION_LE
#  define PERL_VERSION_LE(r,v,s) \
	  (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
#endif

/* XS_INTERNAL is the explicit static-linkage variant of the default
 * XS macro.
 *
 * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
 * "STATIC", ie. it exports XSUB symbols. You probably don't want that
 * for anything but the BOOT XSUB.
 *
 * See XSUB.h in core!
 */


/* TODO: This might be compatible further back than 5.10.0. */
#if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
#  undef XS_EXTERNAL
#  undef XS_INTERNAL
#  if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
#    define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
#    define XS_INTERNAL(name) STATIC XSPROTO(name)
#  endif
#  if defined(__SYMBIAN32__)
#    define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
#    define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
#  endif
#  ifndef XS_EXTERNAL
#    if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
#      define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
#      define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
#    else
#      ifdef __cplusplus
#        define XS_EXTERNAL(name) extern "C" XSPROTO(name)
#        define XS_INTERNAL(name) static XSPROTO(name)
#      else
#        define XS_EXTERNAL(name) XSPROTO(name)
#        define XS_INTERNAL(name) STATIC XSPROTO(name)
#      endif
#    endif
#  endif
#endif

/* perl >= 5.10.0 && perl <= 5.15.1 */


/* The XS_EXTERNAL macro is used for functions that must not be static
 * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
 * macro defined, the best we can do is assume XS is the same.
 * Dito for XS_INTERNAL.
 */
#ifndef XS_EXTERNAL
#  define XS_EXTERNAL(name) XS(name)
#endif
#ifndef XS_INTERNAL
#  define XS_INTERNAL(name) XS(name)
#endif

/* Now, finally, after all this mess, we want an ExtUtils::ParseXS
 * internal macro that we're free to redefine for varying linkage due
 * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
 * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
 */

#undef XS_EUPXS
#if defined(PERL_EUPXS_ALWAYS_EXPORT)
#  define XS_EUPXS(name) XS_EXTERNAL(name)
#else
   /* default to internal */
#  define XS_EUPXS(name) XS_INTERNAL(name)
#endif

#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)

/* prototype to pass -Wmissing-prototypes */
STATIC void
S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params);

STATIC void
S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params)
{
    const GV *const gv = CvGV(cv);

    PERL_ARGS_ASSERT_CROAK_XS_USAGE;

    if (gv) {
        const char *const gvname = GvNAME(gv);
        const HV *const stash = GvSTASH(gv);
        const char *const hvname = stash ? HvNAME(stash) : NULL;

        if (hvname)
            Perl_croak(aTHX_ "Usage: %s::%s(%s)", hvname, gvname, params);
        else
            Perl_croak(aTHX_ "Usage: %s(%s)", gvname, params);
    } else {
        /* Pants. I don't think that it should be possible to get here. */
        Perl_croak(aTHX_ "Usage: CODE(0x%"UVxf")(%s)", PTR2UV(cv), params);
    }
}
#undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE

#ifdef PERL_IMPLICIT_CONTEXT
#define croak_xs_usage(a,b)    S_croak_xs_usage(aTHX_ a,b)
#else
#define croak_xs_usage        S_croak_xs_usage
#endif

#endif

/* NOTE: the prototype of newXSproto() is different in versions of perls,
 * so we define a portable version of newXSproto()
 */
#ifdef newXS_flags
#define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
#else
#define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
#endif /* !defined(newXS_flags) */

#line 186 "QtCore4.c"

XS_EUPXS(XS_Qt___internal_classIsa); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_classIsa)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "className, base");
    {
	char *	className = (char *)SvPV_nolen(ST(0))
;
	char *	base = (char *)SvPV_nolen(ST(1))
;
	int	RETVAL;
	dXSTARG;
#line 43 "QtCore4.xs"
        RETVAL = isDerivedFromByName(className, base, 0);
#line 203 "QtCore4.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt___internal_findMethod); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_findMethod)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "classname, methodname");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	char*	classname = (char *)SvPV_nolen(ST(0))
;
	char*	methodname = (char *)SvPV_nolen(ST(1))
;
#line 57 "QtCore4.xs"
        QList<Smoke::ModuleIndex> milist;
        if ( strcmp( classname, "QGlobalSpace" ) == 0 ) {
            // All modules put their global functions in "QGlobalSpace".  So we
            // have to use each smoke object to look for this method.
            for (int i = 0; i < smokeList.size(); ++i) {
                Smoke::ModuleIndex mi = smokeList.at(i)->findMethod(classname, methodname);
                if( mi.smoke ) {
                    // Found a result, add it to the return
                    milist.append(mi);
                }
            }
        }
        else {
            // qtcore_Smoke will be able to find any method not in QGlobalSpace
            milist.append( qtcore_Smoke->findMethod(classname, methodname) );
        }
        foreach (Smoke::ModuleIndex mi, milist) {
            if ( !mi.index ) {
                // empty list
            }
            else if ( mi.index  > 0 ) {
                int smokeId = smokeList.indexOf(mi.smoke);
                if ( smokeId == -1 ) {
                    croak( "Method \"%s::%s\" called, which is defined in the smoke"
                        "module \"%s\", which has not been loaded\n", classname,
                        methodname, mi.smoke->moduleName() );
                }
                Smoke::Index methodId = mi.smoke->methodMaps[mi.index].method;
                if ( !methodId ) {
                    croak( "Corrupt method %s::%s", classname, methodname );
                }
                else if ( methodId > 0 ) {     // single match
                    XPUSHs( sv_2mortal(alloc_perl_moduleindex(smokeId, methodId)) );
                }
                else {                  // multiple match
                    // trun into ambiguousMethodList index
                    methodId = -methodId;

                    // Put all ambiguous method possibilities onto the stack
                    while( mi.smoke->ambiguousMethodList[methodId] ) {
                        XPUSHs( 
                            sv_2mortal(
                                alloc_perl_moduleindex(smokeId, (IV)mi.smoke->ambiguousMethodList[methodId])
                            )
                        );
                        ++methodId;
                    }
                }
            }
        }
#line 274 "QtCore4.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Qt___internal_getClassList); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_getClassList)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {
	SV *	RETVAL;
#line 113 "QtCore4.xs"
        AV* av = newAV();
        for (int i = 1; i <= qtcore_Smoke->numClasses; i++) {
            av_push(av, newSVpv(qtcore_Smoke->classes[i].className, 0));
        }
        RETVAL = newRV_noinc((SV*)av);
#line 295 "QtCore4.c"
	ST(0) = RETVAL;
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt___internal_getEnumList); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_getEnumList)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {
	SV *	RETVAL;
#line 126 "QtCore4.xs"
        AV *av = newAV();
        for(int i = 1; i < qtcore_Smoke->numTypes; i++) {
            Smoke::Type curType = qtcore_Smoke->types[i];
            if( (curType.flags & Smoke::tf_elem) == Smoke::t_enum )
                av_push(av, newSVpv(curType.name, 0));
        }
        RETVAL = newRV_noinc((SV*)av);
#line 319 "QtCore4.c"
	ST(0) = RETVAL;
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt___internal_getIsa); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_getIsa)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "moduleId");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	moduleId = ST(0)
;
#line 142 "QtCore4.xs"
        AV* av = (AV*)SvRV(moduleId);
        SV** smokeId = av_fetch(av, 0, 0);
        SV** classId = av_fetch(av, 1, 0);
        Smoke* smoke = smokeList[SvIV(*smokeId)];
        Smoke::Index *parents =
            smoke->inheritanceList +
            smoke->classes[SvIV(*classId)].parents;
        while(*parents)
            XPUSHs(sv_2mortal(newSVpv(smoke->classes[*parents++].className, 0)));
#line 348 "QtCore4.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Qt___internal_getTypeNameOfArg); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_getTypeNameOfArg)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "smokeId, methodId, argnum");
    {
	int	smokeId = (int)SvIV(ST(0))
;
	int	methodId = (int)SvIV(ST(1))
;
	int	argnum = (int)SvIV(ST(2))
;
	char *	RETVAL;
	dXSTARG;
#line 161 "QtCore4.xs"
        Smoke* smoke = smokeList[smokeId];
        Smoke::Method &method = smoke->methods[methodId];
        Smoke::Index* args = smoke->argumentList + method.args;
        RETVAL = (char*)smoke->types[args[argnum]].name;
#line 375 "QtCore4.c"
	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt___internal_getNativeMetaObject); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_getNativeMetaObject)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "smokeId, methodId");
    {
	int	smokeId = (int)SvIV(ST(0))
;
	int	methodId = (int)SvIV(ST(1))
;
	SV *	RETVAL;
#line 173 "QtCore4.xs"
        smokeperl_object* nothis = alloc_smokeperl_object( false, 0, 0, 0 );
        Smoke* smoke = smokeList[smokeId];
        PerlQt4::MethodCall call(
            smoke,
            methodId,
            nothis,
            0,
            0
        );
        call.next();
        RETVAL = call.var();
#line 406 "QtCore4.c"
	ST(0) = RETVAL;
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt___internal_getNumArgs); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_getNumArgs)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "smokeId, methodId");
    {
	int	smokeId = (int)SvIV(ST(0))
;
	int	methodId = (int)SvIV(ST(1))
;
	int	RETVAL;
	dXSTARG;
#line 194 "QtCore4.xs"
        Smoke::Method &method = smokeList[smokeId]->methods[methodId];
        RETVAL = method.numArgs;
#line 430 "QtCore4.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt___internal_getSVt); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_getSVt)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "sv");
    {
	SV*	sv = ST(0)
;
	const char *	RETVAL;
	dXSTARG;
#line 203 "QtCore4.xs"
        RETVAL = get_SVt(sv);
#line 450 "QtCore4.c"
	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt___internal_findClass); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_findClass)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "name");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	char*	name = (char *)SvPV_nolen(ST(0))
;
#line 214 "QtCore4.xs"
        Smoke::ModuleIndex mi = qtcore_Smoke->findClass(name);
        EXTEND(SP, 2);
        PUSHs(sv_2mortal(newSViv(mi.index)));
        PUSHs(sv_2mortal(newSViv(smokeList.indexOf(mi.smoke))));
#line 473 "QtCore4.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Qt___internal_classFromId); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_classFromId)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "moduleId");
    {
	SV*	moduleId = ST(0)
;
	const char *	RETVAL;
	dXSTARG;
#line 225 "QtCore4.xs"
        AV* av = (AV*)SvRV(moduleId);
        int smokeId = SvIV(*(SV**)av_fetch(av, 0, 0));
        int classId = SvIV(*(SV**)av_fetch(av, 1, 0));
        Smoke* smoke = smokeList[smokeId];
        RETVAL = smoke->classes[classId].className;
#line 497 "QtCore4.c"
	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt___internal_debug); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_debug)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {
	int	RETVAL;
	dXSTARG;
#line 236 "QtCore4.xs"
        RETVAL = do_debug;
#line 515 "QtCore4.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt___internal_installautoload); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_installautoload)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "package");
    {
	char*	package = (char *)SvPV_nolen(ST(0))
;
#line 248 "QtCore4.xs"
        if(!package) XSRETURN_EMPTY;
        char* autoload = new char[strlen(package) + 11];
        sprintf(autoload, "%s::_UTOLOAD", package);
        newXS(autoload, XS_AUTOLOAD, __FILE__);
        sprintf(autoload, "%s::DESTROY", package);
        newXS(autoload, XS_DESTROY, __FILE__);
        delete[] autoload;
#line 539 "QtCore4.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Qt___internal_installqt_metacall); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_installqt_metacall)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "package");
    {
	char *	package = (char *)SvPV_nolen(ST(0))
;
#line 260 "QtCore4.xs"
        if(!package) XSRETURN_EMPTY;
        char *qt_metacall = new char[strlen(package) + 14];
        strcpy(qt_metacall, package);
        strcat(qt_metacall, "::qt_metacall");
        newXS(qt_metacall, XS_qt_metacall, __FILE__);
        delete[] qt_metacall;
#line 561 "QtCore4.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Qt___internal_installsignal); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_installsignal)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "signalname");
    {
	char *	signalname = (char *)SvPV_nolen(ST(0))
;
#line 271 "QtCore4.xs"
        if(!signalname) XSRETURN_EMPTY;
        newXS(signalname, XS_signal, __FILE__);
#line 579 "QtCore4.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Qt___internal_installthis); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_installthis)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "package");
    {
	char*	package = (char *)SvPV_nolen(ST(0))
;
#line 278 "QtCore4.xs"
        if( !package ) XSRETURN_EMPTY;
        char* attr = new char[strlen(package) + 7];
        strcpy(attr, package);
        strcat(attr, "::this");
        // *{ $name } = sub () : lvalue;
        CV *attrsub = newXS(attr, XS_this, __FILE__);
        sv_setpv((SV*)attrsub, ""); // sub this () : lvalue; perldoc perlsub
        delete[] attr;
#line 603 "QtCore4.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Qt___internal_make_metaObject); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_make_metaObject)
{
    dVAR; dXSARGS;
    if (items != 4)
       croak_xs_usage(cv,  "parentModuleId, parentMeta, stringdata_sv, data_sv");
    {
	SV*	parentModuleId = ST(0)
;
	SV*	parentMeta = ST(1)
;
	SV*	stringdata_sv = ST(2)
;
	SV*	data_sv = ST(3)
;
	SV *	RETVAL;
#line 294 "QtCore4.xs"
        // Get the meta object of the super class, to inherit the super's
        // sig/slots
        QMetaObject* superdata;
        if( SvROK(parentMeta) ){
            // The parent class is a custom Perl class whose metaObject
            // was constructed at runtime
            superdata = (QMetaObject*)sv_obj_info(parentMeta)->ptr;
        }
        else {
            // The parent class is a Smoke class, so call metaObject() on the
            // instance to get it via a smoke library call
            Smoke* parentClassSmoke = smokeList[SvIV(*(SV**)av_fetch((AV*)SvRV(parentModuleId), 0, 0))];
            Smoke::Index parentClassId = SvIV(*(SV**)av_fetch((AV*)SvRV(parentModuleId), 1, 0));
            Smoke::ModuleIndex classMId( parentClassSmoke, parentClassId );
            Smoke::ModuleIndex nameMId = parentClassSmoke->idMethodName("staticMetaObject");
            Smoke::ModuleIndex meth = parentClassSmoke->findMethod(classMId, nameMId);
            if (meth.index > 0) {
                Smoke::Method &m = meth.smoke->methods[meth.smoke->methodMaps[meth.index].method];
                Smoke::ClassFn fn = meth.smoke->classes[m.classId].classFn;
                Smoke::StackItem args[1];
                (*fn)(m.method, 0, args);
                superdata = (QMetaObject*) args[0].s_voidp;
            }
            else {
                // Should never happen...
                croak( "Cannot find %s::metaObject() method\n",
                       meth.smoke->classes[parentClassId].className );
            }
        }

        // Create the qt_meta_data array.
        int count = av_len((AV*)SvRV(data_sv)) + 1;
        uint* qt_meta_data = new uint[count];
        for (int i = 0; i < count; i++) {
            SV** datarow = av_fetch((AV*)SvRV(data_sv), i, 0);
            qt_meta_data[i] = (uint)SvIV(*datarow);
        }

        // Create the qt_meta_stringdata array.
        // Can't use string functions here, because these strings contain
        // null (0) bits, which the string functions will interpret as the end
        // of the string
        STRLEN len = SvLEN(stringdata_sv);
        char* qt_meta_stringdata = new char[len];
        memcpy( (void*)(qt_meta_stringdata), (void*)SvPV_nolen(stringdata_sv), len );

        // Define our meta object
        const QMetaObject staticMetaObject = {
            { superdata, qt_meta_stringdata,
              qt_meta_data, 0 }
        };
        QMetaObject *meta = new QMetaObject;
        *meta = staticMetaObject;

        //Package up this pointer to be returned to perl
        smokeperl_object o;
        o.smoke = qtcore_Smoke;
        o.classId = qtcore_Smoke->idClass("QMetaObject").index,
        o.ptr = meta;
        o.allocated = true;

        HV *hv = newHV();
        RETVAL = newRV_noinc((SV*)hv);
        sv_bless( RETVAL, gv_stashpv( " Qt::MetaObject", TRUE ) );
        sv_magic((SV*)hv, 0, '~', (char*)&o, sizeof(o));
        //Not sure we need the entry in the pointer_map
        mapPointer(RETVAL, &o, pointer_map, o.classId, 0);
#line 693 "QtCore4.c"
	ST(0) = RETVAL;
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt___internal_isObject); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_isObject)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "obj");
    {
	SV*	obj = ST(0)
;
	bool	RETVAL;
#line 368 "QtCore4.xs"
        RETVAL = sv_obj_info(obj) ? TRUE : FALSE;
#line 713 "QtCore4.c"
	ST(0) = boolSV(RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt___internal_setDebug); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_setDebug)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "channel");
    {
	int	channel = (int)SvIV(ST(0))
;
#line 376 "QtCore4.xs"
        do_debug = channel;
#line 731 "QtCore4.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Qt___internal_setQApp); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_setQApp)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "qapp");
    {
	SV*	qapp = ST(0)
;
#line 382 "QtCore4.xs"
        if( SvROK( qapp ) )
            sv_setsv_mg( sv_qapp, qapp );
#line 749 "QtCore4.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Qt___internal_setThis); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_setThis)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "obj");
    {
	SV*	obj = ST(0)
;
#line 389 "QtCore4.xs"
        sv_setsv_mg( sv_this, obj );
#line 766 "QtCore4.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Qt___internal_sv_to_ptr); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_sv_to_ptr)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "sv");
    {
	SV*	sv = ST(0)
;
	void *	RETVAL;
	dXSTARG;

	RETVAL = sv_to_ptr(sv);
	XSprePUSH; PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt___internal_sv_obj_info); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_sv_obj_info)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "sv");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	sv = ST(0)
;
#line 399 "QtCore4.xs"
        smokeperl_object* o = sv_obj_info(sv);
        if( !o || !o->ptr )
            XSRETURN_UNDEF;
        XPUSHs(sv_2mortal(newSViv(o->allocated ? 1 : 0)));
        XPUSHs(sv_2mortal(newSVpv(o->smoke->classes[o->classId].className, strlen(o->smoke->classes[o->classId].className))));
        XPUSHs(sv_2mortal(newSVpv(o->smoke->moduleName(), strlen(o->smoke->moduleName()))));
        XPUSHs(sv_2mortal(newSVpvf("0x%x", (IV)o->ptr)));
#line 810 "QtCore4.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Qt___internal_setIsArrayType); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt___internal_setIsArrayType)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "typeName");
    {
	const char*	typeName = (const char *)SvPV_nolen(ST(0))
;
#line 411 "QtCore4.xs"
        arrayTypes.append(typeName);
#line 828 "QtCore4.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Qt_this); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt_this)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {
	SV *	RETVAL;
#line 421 "QtCore4.xs"
        RETVAL = newSVsv(sv_this);
#line 844 "QtCore4.c"
	ST(0) = RETVAL;
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Qt_qApp); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Qt_qApp)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {
	SV *	RETVAL;
#line 428 "QtCore4.xs"
        if (!sv_qapp)
            RETVAL = &PL_sv_undef;
        else
            RETVAL = newSVsv(sv_qapp);
#line 865 "QtCore4.c"
	ST(0) = RETVAL;
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}

#ifdef WIN32
#undef XSPROTO
#define XSPROTO(name) void Q_DECL_EXPORT name(pTHX_ CV* cv)
#define boot_QtCore4 boot_PerlQtCore4
#endif
#ifdef __cplusplus
extern "C"
#endif
XS_EXTERNAL(boot_QtCore4); /* prototype to pass -Wmissing-prototypes */
XS_EXTERNAL(boot_QtCore4)
{
    dVAR; dXSARGS;
#if (PERL_REVISION == 5 && PERL_VERSION < 9)
    char* file = __FILE__;
#else
    const char* file = __FILE__;
#endif

    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
#ifdef XS_APIVERSION_BOOTCHECK
    XS_APIVERSION_BOOTCHECK;
#endif
    XS_VERSION_BOOTCHECK;

        newXS("Qt::_internal::classIsa", XS_Qt___internal_classIsa, file);
        newXS("Qt::_internal::findMethod", XS_Qt___internal_findMethod, file);
        newXS("Qt::_internal::getClassList", XS_Qt___internal_getClassList, file);
        newXS("Qt::_internal::getEnumList", XS_Qt___internal_getEnumList, file);
        newXS("Qt::_internal::getIsa", XS_Qt___internal_getIsa, file);
        newXS("Qt::_internal::getTypeNameOfArg", XS_Qt___internal_getTypeNameOfArg, file);
        newXS("Qt::_internal::getNativeMetaObject", XS_Qt___internal_getNativeMetaObject, file);
        newXS("Qt::_internal::getNumArgs", XS_Qt___internal_getNumArgs, file);
        newXS("Qt::_internal::getSVt", XS_Qt___internal_getSVt, file);
        newXS("Qt::_internal::findClass", XS_Qt___internal_findClass, file);
        newXS("Qt::_internal::classFromId", XS_Qt___internal_classFromId, file);
        newXS("Qt::_internal::debug", XS_Qt___internal_debug, file);
        newXS("Qt::_internal::installautoload", XS_Qt___internal_installautoload, file);
        newXS("Qt::_internal::installqt_metacall", XS_Qt___internal_installqt_metacall, file);
        newXS("Qt::_internal::installsignal", XS_Qt___internal_installsignal, file);
        newXS("Qt::_internal::installthis", XS_Qt___internal_installthis, file);
        newXS("Qt::_internal::make_metaObject", XS_Qt___internal_make_metaObject, file);
        newXS("Qt::_internal::isObject", XS_Qt___internal_isObject, file);
        newXS("Qt::_internal::setDebug", XS_Qt___internal_setDebug, file);
        newXS("Qt::_internal::setQApp", XS_Qt___internal_setQApp, file);
        newXS("Qt::_internal::setThis", XS_Qt___internal_setThis, file);
        newXS("Qt::_internal::sv_to_ptr", XS_Qt___internal_sv_to_ptr, file);
        newXS("Qt::_internal::sv_obj_info", XS_Qt___internal_sv_obj_info, file);
        newXS("Qt::_internal::setIsArrayType", XS_Qt___internal_setIsArrayType, file);
        (void)newXSproto_portable("Qt::this", XS_Qt_this, file, "");
        (void)newXSproto_portable("Qt::qApp", XS_Qt_qApp, file, "");

    /* Initialisation Section */

#line 448 "QtCore4.xs"
    /* same as -DUSE_SAFE_PUTENV in compile. prevents a "free from wrong
     * pool during global destruction" error with debugperl; and a segfault
     * otherwise (due to invalid free)
     *
     * see also:
     * http://www.nntp.perl.org/group/perl.perl5.porters/2008/06/msg137726.html
     * http://www.qtsoftware.com/developer/task-tracker/index_html?id=217782&method=entry
     */
#ifndef PERL_USE_SAFE_PUTENV
    PL_use_safe_putenv = 1;
#endif

    init_qtcore_Smoke();
    smokeList << qtcore_Smoke;

    binding = PerlQt4::Binding(qtcore_Smoke);
    PerlQt4Module module = { "PerlQtCore4", resolve_classname_qt, 0, &binding };
    perlqt_modules[qtcore_Smoke] = module;

    install_handlers(Qt4_handlers);

    pointer_map = get_hv( "Qt::_internal::pointer_map", FALSE );

    newXS("Qt::qVariantFromValue", XS_qvariant_from_value, __FILE__);
    newXS("Qt::qVariantValue", XS_qvariant_value, __FILE__);
    newXS(" Qt::Object::findChildren", XS_find_qobject_children, __FILE__);
    newXS("Qt::Object::findChildren", XS_find_qobject_children, __FILE__);
    newXS("Qt::Object::qobject_cast", XS_qobject_qt_metacast, __FILE__);
    newXS("Qt::qRegisterResourceData", XS_q_register_resource_data, __FILE__);
    newXS("Qt::qUnregisterResourceData", XS_q_unregister_resource_data, __FILE__);
    newXS(" Qt::AbstractItemModel::columnCount", XS_qabstract_item_model_columncount, __FILE__);
    newXS(" Qt::AbstractItemModel::data", XS_qabstract_item_model_data, __FILE__);
    newXS(" Qt::AbstractItemModel::insertColumns", XS_qabstract_item_model_insertcolumns, __FILE__);
    newXS(" Qt::AbstractItemModel::insertRows", XS_qabstract_item_model_insertrows, __FILE__);
    newXS(" Qt::AbstractItemModel::removeColumns", XS_qabstract_item_model_removecolumns, __FILE__);
    newXS(" Qt::AbstractItemModel::removeRows", XS_qabstract_item_model_removerows, __FILE__);
    newXS(" Qt::AbstractItemModel::rowCount", XS_qabstract_item_model_rowcount, __FILE__);
    newXS(" Qt::AbstractItemModel::setData", XS_qabstract_item_model_setdata, __FILE__);
    newXS(" Qt::AbstractItemModel::createIndex", XS_qabstractitemmodel_createindex, __FILE__);
    newXS("Qt::AbstractItemModel::createIndex", XS_qabstractitemmodel_createindex, __FILE__);
    newXS(" Qt::ModelIndex::internalPointer", XS_qmodelindex_internalpointer, __FILE__);
    newXS(" Qt::ByteArray::data", XS_qbytearray_data, __FILE__);
    newXS(" Qt::ByteArray::constData", XS_qbytearray_data, __FILE__);
    newXS(" Qt::IODevice::read", XS_qiodevice_read, __FILE__);
    newXS(" Qt::Buffer::read", XS_qiodevice_read, __FILE__);
    newXS(" Qt::TcpSocket::read", XS_qiodevice_read, __FILE__);
    newXS(" Qt::TcpServer::read", XS_qiodevice_read, __FILE__);
    newXS(" Qt::File::read", XS_qiodevice_read, __FILE__);
    newXS(" Qt::DataStream::readRawData", XS_qdatastream_readrawdata, __FILE__);

    newXS(" Qt::XmlStreamAttributes::EXISTS"   , XS_QXmlStreamAttributes_exists, __FILE__);
    newXS(" Qt::XmlStreamAttributes::FETCH"    , XS_QXmlStreamAttributes_at, __FILE__);
    newXS(" Qt::XmlStreamAttributes::FETCHSIZE", XS_QXmlStreamAttributes_size, __FILE__);
    newXS(" Qt::XmlStreamAttributes::STORE"    , XS_QXmlStreamAttributes_store, __FILE__);
    newXS(" Qt::XmlStreamAttributes::STORESIZE", XS_QXmlStreamAttributes_storesize, __FILE__);
    newXS(" Qt::XmlStreamAttributes::DELETE"   , XS_QXmlStreamAttributes_delete, __FILE__);
    newXS(" Qt::XmlStreamAttributes::CLEAR"    , XS_QXmlStreamAttributes_clear, __FILE__);
    newXS(" Qt::XmlStreamAttributes::PUSH"     , XS_QXmlStreamAttributes_push, __FILE__);
    newXS(" Qt::XmlStreamAttributes::POP"      , XS_QXmlStreamAttributes_pop, __FILE__);
    newXS(" Qt::XmlStreamAttributes::SHIFT"    , XS_QXmlStreamAttributes_shift, __FILE__);
    newXS(" Qt::XmlStreamAttributes::UNSHIFT"  , XS_QXmlStreamAttributes_unshift, __FILE__);
    newXS(" Qt::XmlStreamAttributes::SPLICE"   , XS_QXmlStreamAttributes_splice, __FILE__);
    newXS("Qt::XmlStreamAttributes::_overload::op_equality", XS_QXmlStreamAttributes__overload_op_equality, __FILE__);


    sv_this = newSV(0);
    sv_qapp = newSV(0);

#line 995 "QtCore4.c"

    /* End of Initialisation Section */

#if (PERL_REVISION == 5 && PERL_VERSION >= 9)
  if (PL_unitcheckav)
       call_list(PL_scopestack_ix, PL_unitcheckav);
#endif
    XSRETURN_YES;
}

