From: Gurusamy Sarathy Date: Thu, 18 Feb 1999 03:26:43 +0000 (+0000) Subject: ensure is data malloc()ed by GDBM is free()d (not Perl_mfree()d) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=097d66a9bb4486e5ece83ced5c687fb1dc2c7503;p=p5sagit%2Fp5-mst-13.2.git ensure is data malloc()ed by GDBM is free()d (not Perl_mfree()d) p4raw-id: //depot/perl@2970 --- diff --git a/ext/GDBM_File/GDBM_File.pm b/ext/GDBM_File/GDBM_File.pm index 09df437..af9a5dc 100644 --- a/ext/GDBM_File/GDBM_File.pm +++ b/ext/GDBM_File/GDBM_File.pm @@ -59,7 +59,7 @@ require DynaLoader; GDBM_WRITER ); -$VERSION = "1.00"; +$VERSION = "1.01"; sub AUTOLOAD { my($constname); diff --git a/ext/GDBM_File/GDBM_File.xs b/ext/GDBM_File/GDBM_File.xs index ac1ca8c..808850d 100644 --- a/ext/GDBM_File/GDBM_File.xs +++ b/ext/GDBM_File/GDBM_File.xs @@ -18,8 +18,6 @@ typedef GDBM_FILE GDBM_File; #define gdbm_NEXTKEY(db,key) gdbm_nextkey(db,key) #define gdbm_EXISTS(db,key) gdbm_exists(db,key) -typedef datum gdatum; - typedef void (*FATALFUNC)(); static int @@ -29,6 +27,21 @@ not_here(char *s) return -1; } +/* GDBM allocates the datum with system malloc() and expects the user + * to free() it. So we either have to free() it immediately, or have + * perl free() it when it deallocates the SV, depending on whether + * perl uses malloc()/free() or not. */ +static void +output_datum(SV *arg, char *str, int size) +{ +#if !defined(MYMALLOC) || (defined(MYMALLOC) && defined(PERL_POLLUTE_MALLOC)) + sv_usepvn(arg, str, size); +#else + sv_setpvn(arg, str, size); + safesysfree(str); +#endif +} + /* Versions of gdbm prior to 1.7x might not have the gdbm_sync, gdbm_exists, and gdbm_setopt functions. Apparently Slackware (Linux) 2.1 contains gdbm-1.5 (which dates back to 1991). @@ -186,7 +199,7 @@ gdbm_DESTROY(db) CODE: gdbm_close(db); -gdatum +datum gdbm_FETCH(db, key) GDBM_File db datum key @@ -211,11 +224,11 @@ gdbm_DELETE(db, key) GDBM_File db datum key -gdatum +datum gdbm_FIRSTKEY(db) GDBM_File db -gdatum +datum gdbm_NEXTKEY(db, key) GDBM_File db datum key diff --git a/ext/GDBM_File/typemap b/ext/GDBM_File/typemap index 317a8f3..d122d07 100644 --- a/ext/GDBM_File/typemap +++ b/ext/GDBM_File/typemap @@ -3,7 +3,6 @@ # datum T_DATUM -gdatum T_GDATUM NDBM_File T_PTROBJ GDBM_File T_PTROBJ SDBM_File T_PTROBJ @@ -16,12 +15,8 @@ INPUT T_DATUM $var.dptr = SvPV($arg, PL_na); $var.dsize = (int)PL_na; -T_GDATUM - UNIMPLEMENTED OUTPUT T_DATUM - sv_setpvn($arg, $var.dptr, $var.dsize); -T_GDATUM - sv_usepvn($arg, $var.dptr, $var.dsize); + output_datum($arg, $var.dptr, $var.dsize); T_PTROBJ sv_setref_pv($arg, dbtype, (void*)$var);