Skip to content

Commit

Permalink
remove CLONE_SKIP frmo Event and Surface, but associates the object w…
Browse files Browse the repository at this point in the history
…ith the interpreter which owns it so it only gets destroyed once... seems to work, but needs more testing...
  • Loading branch information
ruoso committed Jan 12, 2010
1 parent a4394c0 commit 2be22ba
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 26 deletions.
2 changes: 1 addition & 1 deletion lib/SDL/Event.pm
Expand Up @@ -5,5 +5,5 @@ require Exporter;
require DynaLoader;
our @ISA = qw(Exporter DynaLoader);
bootstrap SDL::Event;
sub CLONE_SKIP { 1 };
#sub CLONE_SKIP { 1 };
1;
2 changes: 1 addition & 1 deletion lib/SDL/Surface.pm
Expand Up @@ -5,5 +5,5 @@ require Exporter;
require DynaLoader;
our @ISA = qw(Exporter DynaLoader);
bootstrap SDL::Surface;
sub CLONE_SKIP { 1 };
#sub CLONE_SKIP { 1 };
1;
33 changes: 21 additions & 12 deletions src/Core/objects/Event.xs
Expand Up @@ -963,17 +963,26 @@ event_syswm_msg ( event, ... )
RETVAL

void
event_DESTROY(self)
SDL_Event *self
event_DESTROY(bag)
SV* bag
CODE:
if(self->type == SDL_USEREVENT)
{
if( (self->user).data1 != NULL )
SvREFCNT_dec( (self->user).data1);
if( (self->user).data2 != NULL )
SvREFCNT_dec( (self->user).data2);
}
safefree(self);


if( sv_isobject(bag) && (SvTYPE(SvRV(bag)) == SVt_PVMG) ) {
void** pointers = (void**)(SvIV((SV*)SvRV( bag )));
SDL_Event* self = (SDL_Event*)(pointers[0]);
if (my_perl == pointers[1]) {
//warn("Freed surface %p and pixels %p \n", surface, surface->pixels);
if(self->type == SDL_USEREVENT) {
if( (self->user).data1 != NULL )
SvREFCNT_dec( (self->user).data1);
if( (self->user).data2 != NULL )
SvREFCNT_dec( (self->user).data2);
}
safefree(self);
free(pointers);
}
} else if (bag == 0) {
XSRETURN(0);
} else {
XSRETURN_UNDEF;
}

19 changes: 15 additions & 4 deletions src/Core/objects/Surface.xs
Expand Up @@ -144,9 +144,20 @@ surface_set_pixels(surface, index, value)
((unsigned int*)surface->pixels)[index] = value;

void
surface_DESTROY(surface)
SDL_Surface *surface
surface_DESTROY(bag)
SV* bag
CODE:
//warn("Freed surface %p and pixels %p \n", surface, surface->pixels);
SDL_FreeSurface(surface);
if( sv_isobject(bag) && (SvTYPE(SvRV(bag)) == SVt_PVMG) ) {
void** pointers = (void**)(SvIV((SV*)SvRV( bag )));
SDL_Surface* surface = (SDL_Surface*)(pointers[0]);
if (my_perl == pointers[1]) {
//warn("Freed surface %p and pixels %p \n", surface, surface->pixels);
SDL_FreeSurface(surface);
free(pointers);
}
} else if (bag == 0) {
XSRETURN(0);
} else {
XSRETURN_UNDEF;
}

20 changes: 12 additions & 8 deletions typemap
Expand Up @@ -102,18 +102,22 @@ OUTPUT
# The Perl object is blessed into 'CLASS', which should be a
# char* having the name of the package for the blessing.
O_OBJECT
sv_setref_pv( $arg, CLASS, (void*)$var );
void** pointers = malloc(2 * sizeof(void*));
pointers[0] = (void*)$var;
pointers[1] = (void*)my_perl;
sv_setref_pv( $arg, CLASS, (void*)pointers );


INPUT

O_OBJECT
if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) )
{ $var = ($type)SvIV((SV*)SvRV( $arg )); }
else if ($arg == 0)
{ XSRETURN(0); }
else{
XSRETURN_UNDEF;
}
if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) ) {
void** pointers = (void**)(SvIV((SV*)SvRV( $arg )));
$var = ($type)(pointers[0]);
} else if ($arg == 0) {
XSRETURN(0);
} else {
XSRETURN_UNDEF;
}


0 comments on commit 2be22ba

Please sign in to comment.