}
}
-SV*
+void
new_object(SV* meta, ...)
CODE:
{
AV* const xc = mouse_get_xc(aTHX_ meta);
HV* const args = mouse_buildargs(aTHX_ meta, NULL, ax, items);
+ SV* object;
- RETVAL = mouse_instance_create(aTHX_ MOUSE_xc_stash(xc));
- mouse_class_initialize_object(aTHX_ meta, RETVAL, args, FALSE);
- mouse_buildall(aTHX_ xc, RETVAL, sv_2mortal(newRV_inc((SV*)args))); /* BUILDALL */
+ object = mouse_instance_create(aTHX_ MOUSE_xc_stash(xc));
+ mouse_class_initialize_object(aTHX_ meta, object, args, FALSE);
+ mouse_buildall(aTHX_ xc, object, sv_2mortal(newRV_inc((SV*)args))); /* BUILDALL */
+ ST(0) = object; /* because object is mortal, we should return it as is */
+ XSRETURN(1);
}
-OUTPUT:
- RETVAL
-SV*
+void
clone_object(SV* meta, SV* object, ...)
CODE:
{
AV* const xc = mouse_get_xc(aTHX_ meta);
HV* const args = mouse_buildargs(aTHX_ meta, NULL, ax + 1, items - 1);
+ SV* proto;
if(!mouse_is_an_instance_of(aTHX_ MOUSE_xc_stash(xc), object)) {
mouse_throw_error(meta, object,
mcall0(meta, mouse_name), object);
}
- RETVAL = mouse_instance_clone(aTHX_ object);
- mouse_class_initialize_object(aTHX_ meta, RETVAL, args, TRUE);
+ proto = mouse_instance_clone(aTHX_ object);
+ mouse_class_initialize_object(aTHX_ meta, proto, args, TRUE);
+ ST(0) = proto; /* because object is mortal, we should return it as is */
+ XSRETURN(1);
}
-OUTPUT:
- RETVAL
-
void
_initialize_object(SV* meta, SV* object, HV* args, bool is_cloning = FALSE)
MODULE = Mouse PACKAGE = Mouse::Object
-SV*
+void
new(SV* klass, ...)
CODE:
{
AV* const xc = mouse_get_xc(aTHX_ meta);
UV const flags = MOUSE_xc_flags(xc);
SV* args;
+ SV* object;
/* BUILDARGS */
if(flags & MOUSEf_XC_HAS_BUILDARGS){
}
/* new_object */
- RETVAL = mouse_instance_create(aTHX_ MOUSE_xc_stash(xc));
- mouse_class_initialize_object(aTHX_ meta, RETVAL, (HV*)SvRV(args), FALSE);
- mouse_buildall(aTHX_ xc, RETVAL, args); /* BUILDALL */
+ object = mouse_instance_create(aTHX_ MOUSE_xc_stash(xc));
+ mouse_class_initialize_object(aTHX_ meta, object, (HV*)SvRV(args), FALSE);
+ mouse_buildall(aTHX_ xc, object, args); /* BUILDALL */
+ ST(0) = object; /* because object is mortal, we should return it as is */
+ XSRETURN(1);
}
-OUTPUT:
- RETVAL
void
DESTROY(SV* object)
#include "mouse.h"
#define CHECK_INSTANCE(instance) STMT_START{ \
+ assert(instance); \
if(!(SvROK(instance) && SvTYPE(SvRV(instance)) == SVt_PVHV)){ \
croak("Invalid object instance: '%"SVf"'", instance); \
} \
SV*
mouse_instance_create(pTHX_ HV* const stash) {
+ SV* instance;
assert(stash);
assert(SvTYPE(stash) == SVt_PVHV);
- return sv_bless( newRV_noinc((SV*)newHV()), stash );
+ instance = sv_bless( newRV_noinc((SV*)newHV()), stash );
+ return sv_2mortal(instance);
}
SV*
mouse_instance_clone(pTHX_ SV* const instance) {
- HV* proto;
- assert(instance);
-
+ SV* proto;
CHECK_INSTANCE(instance);
- proto = newHVhv((HV*)SvRV(instance));
- return sv_bless( newRV_noinc((SV*)proto), SvSTASH(SvRV(instance)) );
+ assert(SvOBJECT(SvRV(instance)));
+
+ proto = newRV_noinc((SV*)newHVhv((HV*)SvRV(instance)));
+ sv_bless(proto, SvSTASH(SvRV(instance)));
+ return sv_2mortal(proto);
}
bool
mouse_instance_has_slot(pTHX_ SV* const instance, SV* const slot) {
- assert(instance);
assert(slot);
CHECK_INSTANCE(instance);
return hv_exists_ent((HV*)SvRV(instance), slot, 0U);
SV*
mouse_instance_get_slot(pTHX_ SV* const instance, SV* const slot) {
HE* he;
- assert(instance);
assert(slot);
CHECK_INSTANCE(instance);
he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U);
mouse_instance_set_slot(pTHX_ SV* const instance, SV* const slot, SV* const value) {
HE* he;
SV* sv;
- assert(instance);
assert(slot);
assert(value);
CHECK_INSTANCE(instance);
void
mouse_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot) {
HE* he;
- assert(instance);
assert(slot);
CHECK_INSTANCE(instance);
he = hv_fetch_ent((HV*)SvRV(instance), slot, FALSE, 0U);