diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1999-02-18 03:26:43 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-02-18 03:26:43 +0000 |
commit | 097d66a9bb4486e5ece83ced5c687fb1dc2c7503 (patch) | |
tree | f7878517a2638724587ff3486ee42890258fdc60 /ext/GDBM_File | |
parent | 449bc448608ab0510bce029f04816fc3b63d7d6a (diff) | |
download | perl-097d66a9bb4486e5ece83ced5c687fb1dc2c7503.tar.gz |
ensure is data malloc()ed by GDBM is free()d (not Perl_mfree()d)
p4raw-id: //depot/perl@2970
Diffstat (limited to 'ext/GDBM_File')
-rw-r--r-- | ext/GDBM_File/GDBM_File.pm | 2 | ||||
-rw-r--r-- | ext/GDBM_File/GDBM_File.xs | 23 | ||||
-rw-r--r-- | ext/GDBM_File/typemap | 7 |
3 files changed, 20 insertions, 12 deletions
diff --git a/ext/GDBM_File/GDBM_File.pm b/ext/GDBM_File/GDBM_File.pm index 09df4373fb..af9a5dc6a3 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 ac1ca8c68d..808850d849 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 317a8f3886..d122d07a43 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); |