# DB_File.pm -- Perl 5 interface to Berkeley DB
#
# written by Paul Marquess (pmarquess@bfsec.bt.co.uk)
-# last modified 27th Apr 1997
-# version 1.13
+# last modified 30th Apr 1997
+# version 1.14
#
# Copyright (c) 1995, 1996, 1997 Paul Marquess. All rights reserved.
# This program is free software; you can redistribute it and/or
use Carp;
-$VERSION = "1.13" ;
+$VERSION = "1.14" ;
#typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
$DB_BTREE = new DB_File::BTREEINFO ;
# Preloaded methods go here. Autoload methods go after __END__, and are
# processed by the autosplit program.
-sub TIEHASH
+sub tie_hash_or_array
{
my (@arg) = @_ ;
+ my $tieHASH = ( (caller(1))[3] =~ /TIEHASH/ ) ;
$arg[4] = tied %{ $arg[4] }
if @arg >= 5 && ref $arg[4] && $arg[4] =~ /=HASH/ && tied %{ $arg[4] } ;
- DoTie_(@arg) ;
+ DoTie_($tieHASH, @arg) ;
}
-*TIEARRAY = \&TIEHASH ;
+sub TIEHASH
+{
+ tie_hash_or_array(@_) ;
+}
+
+sub TIEARRAY
+{
+ tie_hash_or_array(@_) ;
+}
sub get_dup
{
Minor changes to DB_FIle.xs and DB_File.pm
+=item 1.14
+
+Made it illegal to tie an associative array to a RECNO database and an
+ordinary array to a HASH or BTREE database.
+
=back
=head1 BUGS
DB_File.xs -- Perl 5 interface to Berkeley DB
written by Paul Marquess (pmarquess@bfsec.bt.co.uk)
- last modified 27th Apr 1997
- version 1.13
+ last modified 30th Apr 1997
+ version 1.14
All comments/suggestions/problems are welcome
1.11 - No change to DB_File.xs
1.12 - No change to DB_File.xs
1.13 - Tidied up a few casts.
+ 1.14 - Made it illegal to tie an associative array to a RECNO
+ database and an ordinary array to a HASH or BTREE database.
*/
}
static DB_File
-ParseOpenInfo(name, flags, mode, sv)
+ParseOpenInfo(isHASH, name, flags, mode, sv)
+int isHASH ;
char * name ;
int flags ;
int mode ;
if (sv_isa(sv, "DB_File::HASHINFO"))
{
+
+ if (!isHASH)
+ croak("DB_File can only tie an associative array to a DB_HASH database") ;
+
RETVAL->type = DB_HASH ;
openinfo = (void*)info ;
}
else if (sv_isa(sv, "DB_File::BTREEINFO"))
{
+ if (!isHASH)
+ croak("DB_File can only tie an associative array to a DB_BTREE database");
+
RETVAL->type = DB_BTREE ;
openinfo = (void*)info ;
}
else if (sv_isa(sv, "DB_File::RECNOINFO"))
{
+ if (isHASH)
+ croak("DB_File can only tie an array to a DB_RECNO database");
+
RETVAL->type = DB_RECNO ;
openinfo = (void *)info ;
DB_File
-db_DoTie_(dbtype, name=undef, flags=O_CREAT|O_RDWR, mode=0666, type=DB_HASH)
+db_DoTie_(isHASH, dbtype, name=undef, flags=O_CREAT|O_RDWR, mode=0666, type=DB_HASH)
+ int isHASH
char * dbtype
int flags
int mode
char * name = (char *) NULL ;
SV * sv = (SV *) NULL ;
- if (items >= 2 && SvOK(ST(1)))
- name = (char*) SvPV(ST(1), na) ;
+ if (items >= 3 && SvOK(ST(2)))
+ name = (char*) SvPV(ST(2), na) ;
- if (items == 5)
- sv = ST(4) ;
+ if (items == 6)
+ sv = ST(5) ;
- RETVAL = ParseOpenInfo(name, flags, mode, sv) ;
+ RETVAL = ParseOpenInfo(isHASH, name, flags, mode, sv) ;
if (RETVAL->dbp == NULL)
RETVAL = NULL ;
}
ST(0) = sv_newmortal();
if (RETVAL == 0)
{
- if (Db->type != DB_RECNO)
+ if (db->type != DB_RECNO)
sv_setpvn(ST(0), key.data, key.size);
else
sv_setiv(ST(0), (I32)*(I32*)key.data - 1);
ST(0) = sv_newmortal();
if (RETVAL == 0)
{
- if (Db->type != DB_RECNO)
+ if (db->type != DB_RECNO)
sv_setpvn(ST(0), key.data, key.size);
else
sv_setiv(ST(0), (I32)*(I32*)key.data - 1);