# define XS_VERSION_BOOTCHECK
#endif
+/*
+ The DBM_setFilter & DBM_ckFilter macros are only used by
+ the *DB*_File modules
+*/
+
+#define DBM_setFilter(db_type,code) \
+ { \
+ if (db_type) \
+ RETVAL = sv_mortalcopy(db_type) ; \
+ ST(0) = RETVAL ; \
+ if (db_type && (code == &PL_sv_undef)) { \
+ SvREFCNT_dec(db_type) ; \
+ db_type = NULL ; \
+ } \
+ else if (code) { \
+ if (db_type) \
+ sv_setsv(db_type, code) ; \
+ else \
+ db_type = newSVsv(code) ; \
+ } \
+ }
+
+#define DBM_ckFilter(arg,type,name) \
+ if (db->type) { \
+ if (db->filtering) { \
+ croak("recursion detected in %s", name) ; \
+ } \
+ ENTER ; \
+ SAVETMPS ; \
+ SAVEINT(db->filtering) ; \
+ db->filtering = TRUE ; \
+ SAVESPTR(DEFSV) ; \
+ DEFSV = arg ; \
+ SvTEMP_off(arg) ; \
+ PUSHMARK(SP) ; \
+ PUTBACK ; \
+ (void) perl_call_sv(db->type, G_DISCARD); \
+ SPAGAIN ; \
+ PUTBACK ; \
+ FREETMPS ; \
+ LEAVE ; \
+ }
+
#if 1 /* for compatibility */
# define VTBL_sv &PL_vtbl_sv
# define VTBL_env &PL_vtbl_env
#include <fcntl.h>
/* #define TRACE */
-#define DBM_FILTERING
#ifdef TRACE
# define Trace(x) printf x
#ifdef DB_VERSION_MAJOR
DBC * cursor ;
#endif
-#ifdef DBM_FILTERING
SV * filter_fetch_key ;
SV * filter_store_key ;
SV * filter_fetch_value ;
SV * filter_store_value ;
int filtering ;
-#endif /* DBM_FILTERING */
} DB_File_type;
typedef DB_File_type * DB_File ;
typedef DBT DBTKEY ;
-#ifdef DBM_FILTERING
-
-#define ckFilter(arg,type,name) \
- if (db->type) { \
- SV * save_defsv ; \
- /* printf("filtering %s\n", name) ; */ \
- if (db->filtering) \
- croak("recursion detected in %s", name) ; \
- db->filtering = TRUE ; \
- save_defsv = newSVsv(DEFSV) ; \
- sv_setsv(DEFSV, arg) ; \
- PUSHMARK(sp) ; \
- (void) perl_call_sv(db->type, G_DISCARD|G_NOARGS); \
- sv_setsv(arg, DEFSV) ; \
- sv_setsv(DEFSV, save_defsv) ; \
- SvREFCNT_dec(save_defsv) ; \
- db->filtering = FALSE ; \
- /* printf("end of filtering %s\n", name) ; */ \
- }
-
-#else
-
-#define ckFilter(arg,type, name)
-
-#endif /* DBM_FILTERING */
-
#define my_sv_setpvn(sv, d, s) sv_setpvn(sv, (s ? d : (void*)""), s)
#define OutputValue(arg, name) \
{ if (RETVAL == 0) { \
my_sv_setpvn(arg, name.data, name.size) ; \
- ckFilter(arg, filter_fetch_value,"filter_fetch_value") ; \
+ DBM_ckFilter(arg, filter_fetch_value,"filter_fetch_value") ; \
} \
}
} \
else \
sv_setiv(arg, (I32)*(I32*)name.data - 1); \
- ckFilter(arg, filter_fetch_key,"filter_fetch_key") ; \
+ DBM_ckFilter(arg, filter_fetch_key,"filter_fetch_key") ; \
} \
}
Zero(RETVAL, 1, DB_File_type) ;
/* Default to HASH */
-#ifdef DBM_FILTERING
RETVAL->filtering = 0 ;
RETVAL->filter_fetch_key = RETVAL->filter_store_key =
RETVAL->filter_fetch_value = RETVAL->filter_store_value =
-#endif /* DBM_FILTERING */
RETVAL->hash = RETVAL->compare = RETVAL->prefix = NULL ;
RETVAL->type = DB_HASH ;
Zero(RETVAL, 1, DB_File_type) ;
/* Default to HASH */
-#ifdef DBM_FILTERING
RETVAL->filtering = 0 ;
RETVAL->filter_fetch_key = RETVAL->filter_store_key =
RETVAL->filter_fetch_value = RETVAL->filter_store_value =
-#endif /* DBM_FILTERING */
RETVAL->hash = RETVAL->compare = RETVAL->prefix = NULL ;
RETVAL->type = DB_HASH ;
SvREFCNT_dec(db->compare) ;
if (db->prefix)
SvREFCNT_dec(db->prefix) ;
-#ifdef DBM_FILTERING
if (db->filter_fetch_key)
SvREFCNT_dec(db->filter_fetch_key) ;
if (db->filter_store_key)
SvREFCNT_dec(db->filter_fetch_value) ;
if (db->filter_store_value)
SvREFCNT_dec(db->filter_store_value) ;
-#endif /* DBM_FILTERING */
safefree(db) ;
#ifdef DB_VERSION_MAJOR
if (RETVAL > 0)
key
value
-#ifdef DBM_FILTERING
-
-#define setFilter(type) \
- { \
- if (db->type) \
- RETVAL = sv_mortalcopy(db->type) ; \
- ST(0) = RETVAL ; \
- if (db->type && (code == &PL_sv_undef)) { \
- SvREFCNT_dec(db->type) ; \
- db->type = NULL ; \
- } \
- else if (code) { \
- if (db->type) \
- sv_setsv(db->type, code) ; \
- else \
- db->type = newSVsv(code) ; \
- } \
- }
-
-
SV *
filter_fetch_key(db, code)
DB_File db
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_fetch_key) ;
+ DBM_setFilter(db->filter_fetch_key, code) ;
SV *
filter_store_key(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_store_key) ;
+ DBM_setFilter(db->filter_store_key, code) ;
SV *
filter_fetch_value(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_fetch_value) ;
+ DBM_setFilter(db->filter_fetch_value, code) ;
SV *
filter_store_value(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_store_value) ;
+ DBM_setFilter(db->filter_store_value, code) ;
-#endif /* DBM_FILTERING */
INPUT
T_dbtkeydatum
- ckFilter($arg, filter_store_key, \"filter_store_key\");
+ DBM_ckFilter($arg, filter_store_key, \"filter_store_key\");
DBT_clear($var) ;
if (db->type != DB_RECNO) {
$var.data = SvPV($arg, PL_na);
$var.size = (int)sizeof(recno_t);
}
T_dbtdatum
- ckFilter($arg, filter_store_value, \"filter_store_value\");
+ DBM_ckFilter($arg, filter_store_value, \"filter_store_value\");
DBT_clear($var) ;
if (SvOK($arg)) {
$var.data = SvPV($arg, PL_na);
typedef datum datum_value ;
typedef datum datum_key_copy;
-#define ckFilter(arg,type,name) \
- if (db->type) { \
- SV * save_defsv ; \
- /* printf("filtering %s\n", name) ;*/ \
- if (db->filtering) \
- croak("recursion detected in %s", name) ; \
- db->filtering = TRUE ; \
- save_defsv = newSVsv(DEFSV) ; \
- sv_setsv(DEFSV, arg) ; \
- PUSHMARK(sp) ; \
- (void) perl_call_sv(db->type, G_DISCARD|G_NOARGS); \
- sv_setsv(arg, DEFSV) ; \
- sv_setsv(DEFSV, save_defsv) ; \
- SvREFCNT_dec(save_defsv) ; \
- db->filtering = FALSE ; \
- /*printf("end of filtering %s\n", name) ;*/ \
- }
-
-
-
#define GDBM_BLOCKSIZE 0 /* gdbm defaults to stat blocksize */
typedef void (*FATALFUNC)();
int optlen
-#define setFilter(type) \
- { \
- if (db->type) \
- RETVAL = sv_mortalcopy(db->type) ; \
- ST(0) = RETVAL ; \
- if (db->type && (code == &PL_sv_undef)) { \
- SvREFCNT_dec(db->type) ; \
- db->type = NULL ; \
- } \
- else if (code) { \
- if (db->type) \
- sv_setsv(db->type, code) ; \
- else \
- db->type = newSVsv(code) ; \
- } \
- }
-
-
-
SV *
filter_fetch_key(db, code)
GDBM_File db
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_fetch_key) ;
+ DBM_setFilter(db->filter_fetch_key, code) ;
SV *
filter_store_key(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_store_key) ;
+ DBM_setFilter(db->filter_store_key, code) ;
SV *
filter_fetch_value(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_fetch_value) ;
+ DBM_setFilter(db->filter_fetch_value, code) ;
SV *
filter_store_value(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_store_value) ;
+ DBM_setFilter(db->filter_store_value, code) ;
use GDBM_File;
-print "1..74\n";
+print "1..80\n";
unlink <Op.dbmx*>;
unlink <Op.dbmx*>;
}
+{
+ # Check that DBM Filter can cope with read-only $_
+
+ use warnings ;
+ use strict ;
+ my %h ;
+ unlink <Op.dbmx*>;
+
+ ok(75, my $db = tie(%h, 'GDBM_File','Op.dbmx', &GDBM_WRCREAT, 0640));
+
+ $db->filter_fetch_key (sub { }) ;
+ $db->filter_store_key (sub { }) ;
+ $db->filter_fetch_value (sub { }) ;
+ $db->filter_store_value (sub { }) ;
+
+ $_ = "original" ;
+
+ $h{"fred"} = "joe" ;
+ ok(76, $h{"fred"} eq "joe");
+
+ eval { grep { $h{$_} } (1, 2, 3) };
+ ok (77, ! $@);
+
+
+ # delete the filters
+ $db->filter_fetch_key (undef);
+ $db->filter_store_key (undef);
+ $db->filter_fetch_value (undef);
+ $db->filter_store_value (undef);
+
+ $h{"fred"} = "joe" ;
+
+ ok(78, $h{"fred"} eq "joe");
+
+ ok(79, $db->FIRSTKEY() eq "fred") ;
+
+ eval { grep { $h{$_} } (1, 2, 3) };
+ ok (80, ! $@);
+
+ undef $db ;
+ untie %h;
+ unlink <Op.dbmx*>;
+}
exit ;
INPUT
T_DATUM_K
- ckFilter($arg, filter_store_key, \"filter_store_key\");
+ DBM_ckFilter($arg, filter_store_key, \"filter_store_key\");
$var.dptr = SvPV($arg, PL_na);
$var.dsize = (int)PL_na;
T_DATUM_K_C
SV * tmpSV;
if (db->filter_store_key) {
tmpSV = sv_2mortal(newSVsv($arg));
- ckFilter(tmpSV, filter_store_key, \"filter_store_key\");
+ DBM_ckFilter(tmpSV, filter_store_key, \"filter_store_key\");
}
else
tmpSV = $arg;
$var.dsize = (int)PL_na;
}
T_DATUM_V
- ckFilter($arg, filter_store_value, \"filter_store_value\");
+ DBM_ckFilter($arg, filter_store_value, \"filter_store_value\");
if (SvOK($arg)) {
$var.dptr = SvPV($arg, PL_na);
$var.dsize = (int)PL_na;
OUTPUT
T_DATUM_K
output_datum(aTHX_ $arg, $var.dptr, $var.dsize);
- ckFilter($arg, filter_fetch_key,\"filter_fetch_key\");
+ DBM_ckFilter($arg, filter_fetch_key,\"filter_fetch_key\");
T_DATUM_V
output_datum(aTHX_ $arg, $var.dptr, $var.dsize);
- ckFilter($arg, filter_fetch_value,\"filter_fetch_value\");
+ DBM_ckFilter($arg, filter_fetch_value,\"filter_fetch_value\");
T_PTROBJ
sv_setref_pv($arg, dbtype, (void*)$var);
* by DB3 and Perl. We drop the Perl definition now.
* See also INSTALL section on DB3.
* -- Stanislav Brabec <utx@penguin.cz> */
-#undef ENTER
#include <ndbm.h>
typedef struct {
typedef datum datum_key ;
typedef datum datum_value ;
-#define ckFilter(arg,type,name) \
- if (db->type) { \
- SV * save_defsv ; \
- /* printf("filtering %s\n", name) ;*/ \
- if (db->filtering) \
- croak("recursion detected in %s", name) ; \
- db->filtering = TRUE ; \
- save_defsv = newSVsv(DEFSV) ; \
- sv_setsv(DEFSV, arg) ; \
- PUSHMARK(sp) ; \
- (void) perl_call_sv(db->type, G_DISCARD|G_NOARGS); \
- sv_setsv(arg, DEFSV) ; \
- sv_setsv(DEFSV, save_defsv) ; \
- SvREFCNT_dec(save_defsv) ; \
- db->filtering = FALSE ; \
- /*printf("end of filtering %s\n", name) ;*/ \
- }
-
-
MODULE = NDBM_File PACKAGE = NDBM_File PREFIX = ndbm_
NDBM_File
NDBM_File db
-#define setFilter(type) \
- { \
- if (db->type) \
- RETVAL = sv_mortalcopy(db->type) ; \
- ST(0) = RETVAL ; \
- if (db->type && (code == &PL_sv_undef)) { \
- SvREFCNT_dec(db->type) ; \
- db->type = NULL ; \
- } \
- else if (code) { \
- if (db->type) \
- sv_setsv(db->type, code) ; \
- else \
- db->type = newSVsv(code) ; \
- } \
- }
-
-
-
SV *
filter_fetch_key(db, code)
NDBM_File db
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_fetch_key) ;
+ DBM_setFilter(db->filter_fetch_key, code) ;
SV *
filter_store_key(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_store_key) ;
+ DBM_setFilter(db->filter_store_key, code) ;
SV *
filter_fetch_value(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_fetch_value) ;
+ DBM_setFilter(db->filter_fetch_value, code) ;
SV *
filter_store_value(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_store_value) ;
+ DBM_setFilter(db->filter_store_value, code) ;
#If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT
use Fcntl;
-print "1..71\n";
+print "1..77\n";
unlink <Op.dbmx*>;
unlink <Op.dbmx*>;
}
+
+{
+ # Check that DBM Filter can cope with read-only $_
+
+ use warnings ;
+ use strict ;
+ my %h ;
+ unlink <Op.dbmx*>;
+
+ ok(72, my $db = tie(%h, 'NDBM_File','Op.dbmx', O_RDWR|O_CREAT, 0640)) ;
+
+ $db->filter_fetch_key (sub { }) ;
+ $db->filter_store_key (sub { }) ;
+ $db->filter_fetch_value (sub { }) ;
+ $db->filter_store_value (sub { }) ;
+
+ $_ = "original" ;
+
+ $h{"fred"} = "joe" ;
+ ok(73, $h{"fred"} eq "joe");
+
+ eval { grep { $h{$_} } (1, 2, 3) };
+ ok (74, ! $@);
+
+
+ # delete the filters
+ $db->filter_fetch_key (undef);
+ $db->filter_store_key (undef);
+ $db->filter_fetch_value (undef);
+ $db->filter_store_value (undef);
+
+ $h{"fred"} = "joe" ;
+
+ ok(75, $h{"fred"} eq "joe");
+
+ ok(76, $db->FIRSTKEY() eq "fred") ;
+
+ eval { grep { $h{$_} } (1, 2, 3) };
+ ok (77, ! $@);
+
+ undef $db ;
+ untie %h;
+ unlink <Op.dbmx*>;
+}
exit ;
INPUT
T_DATUM_K
- ckFilter($arg, filter_store_key, \"filter_store_key\");
+ DBM_ckFilter($arg, filter_store_key, \"filter_store_key\");
$var.dptr = SvPV($arg, PL_na);
$var.dsize = (int)PL_na;
T_DATUM_V
- ckFilter($arg, filter_store_value, \"filter_store_value\");
+ DBM_ckFilter($arg, filter_store_value, \"filter_store_value\");
if (SvOK($arg)) {
$var.dptr = SvPV($arg, PL_na);
$var.dsize = (int)PL_na;
OUTPUT
T_DATUM_K
sv_setpvn($arg, $var.dptr, $var.dsize);
- ckFilter($arg, filter_fetch_key,\"filter_fetch_key\");
+ DBM_ckFilter($arg, filter_fetch_key,\"filter_fetch_key\");
T_DATUM_V
sv_setpvn($arg, $var.dptr, $var.dsize);
- ckFilter($arg, filter_fetch_value,\"filter_fetch_value\");
+ DBM_ckFilter($arg, filter_fetch_value,\"filter_fetch_value\");
T_GDATUM
sv_usepvn($arg, $var.dptr, $var.dsize);
T_PTROBJ
typedef datum datum_key_copy ;
typedef datum datum_value ;
-#define ckFilter(arg,type,name) \
- if (db->type) { \
- SV * save_defsv ; \
- /* printf("filtering %s\n", name) ;*/ \
- if (db->filtering) \
- croak("recursion detected in %s", name) ; \
- db->filtering = TRUE ; \
- save_defsv = newSVsv(DEFSV) ; \
- sv_setsv(DEFSV, arg) ; \
- PUSHMARK(sp) ; \
- (void) perl_call_sv(db->type, G_DISCARD|G_NOARGS); \
- sv_setsv(arg, DEFSV) ; \
- sv_setsv(DEFSV, save_defsv) ; \
- SvREFCNT_dec(save_defsv) ; \
- db->filtering = FALSE ; \
- /*printf("end of filtering %s\n", name) ;*/ \
- }
-
-
#define odbm_FETCH(db,key) fetch(key)
#define odbm_STORE(db,key,value,flags) store(key,value)
#define odbm_DELETE(db,key) delete(key)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_fetch_key) ;
+ DBM_setFilter(db->filter_fetch_key, code) ;
SV *
filter_store_key(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_store_key) ;
+ DBM_setFilter(db->filter_store_key, code) ;
SV *
filter_fetch_value(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_fetch_value) ;
+ DBM_setFilter(db->filter_fetch_value, code) ;
SV *
filter_store_value(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_store_value) ;
+ DBM_setFilter(db->filter_store_value, code) ;
#If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT
use Fcntl;
-print "1..72\n";
+print "1..78\n";
unlink <Op.dbmx*>;
unlink <Op.dbmx*>;
}
+
+{
+ # Check that DBM Filter can cope with read-only $_
+
+ use warnings ;
+ use strict ;
+ my %h ;
+ unlink <Op.dbmx*>;
+
+ ok(73, my $db = tie(%h, 'ODBM_File','Op.dbmx', O_RDWR|O_CREAT, 0640)) ;
+
+ $db->filter_fetch_key (sub { }) ;
+ $db->filter_store_key (sub { }) ;
+ $db->filter_fetch_value (sub { }) ;
+ $db->filter_store_value (sub { }) ;
+
+ $_ = "original" ;
+
+ $h{"fred"} = "joe" ;
+ ok(74, $h{"fred"} eq "joe");
+
+ eval { grep { $h{$_} } (1, 2, 3) };
+ ok (75, ! $@);
+
+
+ # delete the filters
+ $db->filter_fetch_key (undef);
+ $db->filter_store_key (undef);
+ $db->filter_fetch_value (undef);
+ $db->filter_store_value (undef);
+
+ $h{"fred"} = "joe" ;
+
+ ok(76, $h{"fred"} eq "joe");
+
+ ok(77, $db->FIRSTKEY() eq "fred") ;
+
+ eval { grep { $h{$_} } (1, 2, 3) };
+ ok (78, ! $@);
+
+ undef $db ;
+ untie %h;
+ unlink <Op.dbmx*>;
+}
exit ;
if ($^O eq 'hpux') {
print <<EOM;
INPUT
T_DATUM_K
- ckFilter($arg, filter_store_key, \"filter_store_key\");
+ DBM_ckFilter($arg, filter_store_key, \"filter_store_key\");
$var.dptr = SvPV($arg, PL_na);
$var.dsize = (int)PL_na;
T_DATUM_K_C
SV * tmpSV ;
if (db->filter_store_key){
tmpSV = sv_2mortal(newSVsv($arg));
- ckFilter(tmpSV, filter_store_key, \"filter_store_key\");
+ DBM_ckFilter(tmpSV, filter_store_key, \"filter_store_key\");
}
else
tmpSV = $arg;
$var.dsize = (int)PL_na;
}
T_DATUM_V
- ckFilter($arg, filter_store_value, \"filter_store_value\");
+ DBM_ckFilter($arg, filter_store_value, \"filter_store_value\");
if (SvOK($arg)) {
$var.dptr = SvPV($arg, PL_na);
$var.dsize = (int)PL_na;
OUTPUT
T_DATUM_K
sv_setpvn($arg, $var.dptr, $var.dsize);
- ckFilter($arg, filter_fetch_key,\"filter_fetch_key\");
+ DBM_ckFilter($arg, filter_fetch_key,\"filter_fetch_key\");
T_DATUM_V
sv_setpvn($arg, $var.dptr, $var.dsize);
- ckFilter($arg, filter_fetch_value,\"filter_fetch_value\");
+ DBM_ckFilter($arg, filter_fetch_value,\"filter_fetch_value\");
T_GDATUM
sv_usepvn($arg, $var.dptr, $var.dsize);
typedef datum datum_key ;
typedef datum datum_value ;
-#define ckFilter(arg,type,name) \
- if (db->type) { \
- SV * save_defsv ; \
- /* printf("filtering %s\n", name) ;*/ \
- if (db->filtering) \
- croak("recursion detected in %s", name) ; \
- db->filtering = TRUE ; \
- save_defsv = newSVsv(DEFSV) ; \
- sv_setsv(DEFSV, arg) ; \
- PUSHMARK(sp) ; \
- (void) perl_call_sv(db->type, G_DISCARD|G_NOARGS); \
- sv_setsv(arg, DEFSV) ; \
- sv_setsv(DEFSV, save_defsv) ; \
- SvREFCNT_dec(save_defsv) ; \
- db->filtering = FALSE ; \
- /*printf("end of filtering %s\n", name) ;*/ \
- }
-
#define sdbm_TIEHASH(dbtype,filename,flags,mode) sdbm_open(filename,flags,mode)
#define sdbm_FETCH(db,key) sdbm_fetch(db->dbp,key)
#define sdbm_STORE(db,key,value,flags) sdbm_store(db->dbp,key,value,flags)
RETVAL
-#define setFilter(type) \
- { \
- if (db->type) \
- RETVAL = sv_mortalcopy(db->type) ; \
- ST(0) = RETVAL ; \
- if (db->type && (code == &PL_sv_undef)) { \
- SvREFCNT_dec(db->type) ; \
- db->type = NULL ; \
- } \
- else if (code) { \
- if (db->type) \
- sv_setsv(db->type, code) ; \
- else \
- db->type = newSVsv(code) ; \
- } \
- }
-
-
-
SV *
filter_fetch_key(db, code)
SDBM_File db
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_fetch_key) ;
+ DBM_setFilter(db->filter_fetch_key, code) ;
SV *
filter_store_key(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_store_key) ;
+ DBM_setFilter(db->filter_store_key, code) ;
SV *
filter_fetch_value(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_fetch_value) ;
+ DBM_setFilter(db->filter_fetch_value, code) ;
SV *
filter_store_value(db, code)
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
- setFilter(filter_store_value) ;
+ DBM_setFilter(db->filter_store_value, code) ;
#If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT
use Fcntl;
-print "1..74\n";
+print "1..80\n";
unlink <Op_dbmx.*>;
unlink <Op.dbmx*>;
}
+
+{
+ # Check that DBM Filter can cope with read-only $_
+
+ use warnings ;
+ use strict ;
+ my %h ;
+ unlink <Op1.dbmx*>;
+
+ ok(75, my $db = tie(%h, 'SDBM_File','Op1_dbmx', O_RDWR|O_CREAT, 0640)) ;
+
+ $db->filter_fetch_key (sub { }) ;
+ $db->filter_store_key (sub { }) ;
+ $db->filter_fetch_value (sub { }) ;
+ $db->filter_store_value (sub { }) ;
+
+ $_ = "original" ;
+
+ $h{"fred"} = "joe" ;
+ ok(76, $h{"fred"} eq "joe");
+
+ eval { grep { $h{$_} } (1, 2, 3) };
+ ok (77, ! $@);
+
+
+ # delete the filters
+ $db->filter_fetch_key (undef);
+ $db->filter_store_key (undef);
+ $db->filter_fetch_value (undef);
+ $db->filter_store_value (undef);
+
+ $h{"fred"} = "joe" ;
+
+ ok(78, $h{"fred"} eq "joe");
+
+ ok(79, $db->FIRSTKEY() eq "fred") ;
+
+ eval { grep { $h{$_} } (1, 2, 3) };
+ ok (80, ! $@);
+
+ undef $db ;
+ untie %h;
+ unlink <Op1.dbmx*>;
+}
exit ;
INPUT
T_DATUM_K
- ckFilter($arg, filter_store_key, \"filter_store_key\");
+ DBM_ckFilter($arg, filter_store_key, \"filter_store_key\");
$var.dptr = SvPV($arg, PL_na);
$var.dsize = (int)PL_na;
T_DATUM_V
- ckFilter($arg, filter_store_value, \"filter_store_value\");
+ DBM_ckFilter($arg, filter_store_value, \"filter_store_value\");
if (SvOK($arg)) {
$var.dptr = SvPV($arg, PL_na);
$var.dsize = (int)PL_na;
OUTPUT
T_DATUM_K
sv_setpvn($arg, $var.dptr, $var.dsize);
- ckFilter($arg, filter_fetch_key,\"filter_fetch_key\");
+ DBM_ckFilter($arg, filter_fetch_key,\"filter_fetch_key\");
T_DATUM_V
sv_setpvn($arg, $var.dptr, $var.dsize);
- ckFilter($arg, filter_fetch_value,\"filter_fetch_value\");
+ DBM_ckFilter($arg, filter_fetch_value,\"filter_fetch_value\");
T_GDATUM
sv_usepvn($arg, $var.dptr, $var.dsize);
T_PTROBJ