Permalink
Browse files

changed create_rect into create_mortal_rect. Ensures that a morral re…

…ct is returned. Simplified code that no longer require to dec refcnt
  • Loading branch information...
dod38fr committed Oct 15, 2011
1 parent b19027c commit 6678a7f307e9a8125854a4feb8e11429ffb35963
Showing with 13 additions and 19 deletions.
  1. +3 −11 src/SDLx/Surface.xs
  2. +6 −3 src/SDLx/Validate.h
  3. +4 −5 src/SDLx/Validate.xs
View
@@ -189,10 +189,9 @@ surfacex_draw_rect ( surface, rt, color )
if( SvOK(rt) )
{
int newly_created_rect = 0;
- SV* foo = create_rect( rt, &newly_created_rect );
+ SV* foo = create_mortal_rect( rt, &newly_created_rect );
r_rect = *(SDL_Rect*)bag2obj(foo);
SDL_FillRect(surface, &r_rect, m_color);
- SvREFCNT_dec(foo);
}
else
{
@@ -249,13 +248,11 @@ surfacex_blit( src, dest, ... )
SDL_Rect _dest_rect;
int newly_created_rect = 0;
SV* s_rect_sv, *d_rect_sv;
- int mall_sr = 0; int mall_dr = 0;
if( items > 2 && SvOK(ST(2)) )
{
- s_rect_sv = create_rect(ST(2), &newly_created_rect);
+ s_rect_sv = create_mortal_rect(ST(2), &newly_created_rect);
_src_rect = *(SDL_Rect *)bag2obj( s_rect_sv );
- mall_sr = 1;
}
else
{
@@ -267,9 +264,8 @@ surfacex_blit( src, dest, ... )
if( items > 3 && SvOK(ST(3)) )
{
- d_rect_sv = create_rect(ST(3), &newly_created_rect);
+ d_rect_sv = create_mortal_rect(ST(3), &newly_created_rect);
_dest_rect = *(SDL_Rect *)bag2obj( d_rect_sv );
- mall_dr = 1;
}
else
{
@@ -280,9 +276,5 @@ surfacex_blit( src, dest, ... )
}
SDL_BlitSurface( _src, &_src_rect, _dest, &_dest_rect );
- if ( mall_sr == 1 )
- SvREFCNT_dec( s_rect_sv);
- if ( mall_dr == 1 )
- SvREFCNT_dec( d_rect_sv );
View
@@ -2,7 +2,8 @@
#include <SDL.h>
#include "helper.h"
-SV *create_rect( SV *rect, int* new_rect_made)
+/* SV input should be a mortal SV */
+SV *create_mortal_rect( SV *rect, int* new_rect_made)
{
SV *retval = NULL;
/*we hand this over to perl to handle */
@@ -17,6 +18,7 @@ SV *create_rect( SV *rect, int* new_rect_made)
r->w = 0;
r->h = 0;
retval = obj2bag( sizeof( SDL_Rect *), (void *)(r), "SDL::Rect" );
+ sv_2mortal(retval) ;
}
else if( sv_derived_from(rect, "ARRAY") )
{
@@ -38,10 +40,11 @@ SV *create_rect( SV *rect, int* new_rect_made)
r->x = ra[0]; r->y = ra[1]; r->w = ra[2]; r->h= ra[3];
retval = obj2bag( sizeof( SDL_Rect *), (void *)(r), "SDL::Rect" );
+ sv_2mortal(retval) ;
}
else if( sv_isobject(rect) && sv_derived_from(rect, "SDL::Rect") )
{
- /* we already had a good rect. Just pass it along */
+ /* we already had a good mortal rect . Just pass it along */
(*new_rect_made) = 0;
retval = rect;
SvREFCNT_inc(rect);
@@ -50,7 +53,7 @@ SV *create_rect( SV *rect, int* new_rect_made)
croak("Rect must be number or arrayref or SDL::Rect or undef");
//SvREFCNT_inc(rect);
- return retval;
+ return retval;
}
void assert_surface( SV *surface )
View
@@ -108,14 +108,13 @@ val_list_rgba( color )
OUTPUT:
RETVAL
-SV *
+void
val_rect( r )
SV* r
- CODE:
+ PPCODE:
int new_ = 0;
- RETVAL = create_rect( r, &new_ );
- OUTPUT:
- RETVAL
+ ST(0) = create_mortal_rect( r, &new_ );
+ XSRETURN(1);
void *
val_surface( s )

0 comments on commit 6678a7f

Please sign in to comment.