Lots of fixes for SV hacking in get video driver for SDL::Video
Kartik Thakore [Fri, 23 Oct 2009 20:28:51 +0000 (16:28 -0400)]
src/Core/Video.xs
t/core_video.t

index b0f9d2b..29a18ee 100644 (file)
@@ -40,16 +40,16 @@ video_get_video_info()
        OUTPUT:
                RETVAL
 
-char *
-video_video_driver_name( maxlen )
-       int maxlen
+SV *
+video_video_driver_name( )
+       
        CODE:
-               char* buffer = safemalloc(sizeof(char) * maxlen);
-               char* str = SvPV( newSVpvn( buffer , maxlen), maxlen );
-
-               RETVAL = (char* )SDL_VideoDriverName( str , maxlen);
-               sv_2mortal(buffer);
-               sv_2mortal(str);                
-               
+               char buffer[1024];
+               if ( SDL_VideoDriverName(buffer, 1024) != NULL ) 
+               { 
+                       RETVAL =  newSVpv(buffer, 0);
+               } 
+               else 
+                        XSRETURN_UNDEF;        
        OUTPUT:
                RETVAL
index ed2e4d5..ffa642d 100644 (file)
@@ -2,7 +2,7 @@
 use strict;
 use SDL;
 use SDL::Config;
-
+use Devel::Peek;
 use Test::More;
 
 plan ( tests => 6 );
@@ -24,7 +24,12 @@ isa_ok(SDL::Video::get_video_surface(), 'SDL::Surface', 'Checking if we get a su
 
 isa_ok(SDL::Video::get_video_info(), 'SDL::VideoInfo', 'Checking if we get videoinfo ref back');
 
-pass 'This is your driver name: '.SDL::Video::video_driver_name(10);
+my $driver_name = SDL::Video::video_driver_name();
+
+pass 'This is your driver name: '.$driver_name;
+
+#Dump( $driver_name);
+
 pass "Are we still alive?";
 
 =skip