Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8388895

Browse files
committed
SF patch [ 545523 ] patch for 514433 bsddb.dbopen (NULL)
closes SF #514433 can now pass 'None' as the filename for the bsddb.*open functions, and you'll get an in-memory temporary store. docs are ripped out of the bsddb dbopen man page. Fred may want to clean them up. Considering this for 2.2, but not 2.1.
1 parent 0494955 commit 8388895

4 files changed

Lines changed: 42 additions & 25 deletions

File tree

Doc/lib/libbsddb.tex

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ \section{\module{bsddb} ---
3737
ffactor\optional{, nelem\optional{,
3838
cachesize\optional{, hash\optional{,
3939
lorder}}}}}}}}}
40-
Open the hash format file named \var{filename}. The optional
40+
Open the hash format file named \var{filename}. Files never intended
41+
to be preserved on disk may be created by passing \code{None} as the
42+
\var{filename}. The optional
4143
\var{flag} identifies the mode used to open the file. It may be
4244
\character{r} (read only), \character{w} (read-write),
4345
\character{c} (read-write - create if necessary) or
@@ -51,7 +53,9 @@ \section{\module{bsddb} ---
5153
mode\optional{, btflags\optional{, cachesize\optional{, maxkeypage\optional{,
5254
minkeypage\optional{, psize\optional{, lorder}}}}}}}}}
5355

54-
Open the btree format file named \var{filename}. The optional
56+
Open the btree format file named \var{filename}. Files never intended
57+
to be preserved on disk may be created by passing \code{None} as the
58+
\var{filename}. The optional
5559
\var{flag} identifies the mode used to open the file. It may be
5660
\character{r} (read only), \character{w} (read-write),
5761
\character{c} (read-write - create if necessary) or
@@ -65,7 +69,9 @@ \section{\module{bsddb} ---
6569
rnflags\optional{, cachesize\optional{, psize\optional{, lorder\optional{,
6670
reclen\optional{, bval\optional{, bfname}}}}}}}}}}
6771

68-
Open a DB record format file named \var{filename}. The optional
72+
Open a DB record format file named \var{filename}. Files never intended
73+
to be preserved on disk may be created by passing \code{None} as the
74+
\var{filename}. The optional
6975
\var{flag} identifies the mode used to open the file. It may be
7076
\character{r} (read only), \character{w} (read-write),
7177
\character{c} (read-write - create if necessary) or

Lib/test/test_bsddb.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
"""Test script for the bsddb C module
33
Roger E. Masse
44
"""
5-
65
import os
76
import bsddb
87
import dbhash # Just so we know it's imported
98
import tempfile
109
from test_support import verbose, verify
1110

12-
def test(openmethod, what):
11+
def test(openmethod, what, ondisk=1):
1312

1413
if verbose:
15-
print '\nTesting: ', what
14+
print '\nTesting: ', what, (ondisk and "on disk" or "in memory")
1615

17-
fname = tempfile.mktemp()
16+
if ondisk:
17+
fname = tempfile.mktemp()
18+
else:
19+
fname = None
1820
f = openmethod(fname, 'c')
1921
verify(f.keys() == [])
2022
if verbose:
@@ -47,30 +49,35 @@ def test(openmethod, what):
4749

4850
f.sync()
4951
f.close()
50-
if verbose:
51-
print 'modification...'
52-
f = openmethod(fname, 'w')
53-
f['d'] = 'discovered'
52+
if ondisk:
53+
# if we're using an in-memory only db, we can't reopen it
54+
# so finish here.
55+
if verbose:
56+
print 'modification...'
57+
f = openmethod(fname, 'w')
58+
f['d'] = 'discovered'
5459

55-
if verbose:
56-
print 'access...'
57-
for key in f.keys():
58-
word = f[key]
5960
if verbose:
60-
print word
61+
print 'access...'
62+
for key in f.keys():
63+
word = f[key]
64+
if verbose:
65+
print word
6166

62-
f.close()
63-
try:
64-
os.remove(fname)
65-
except os.error:
66-
pass
67+
f.close()
68+
try:
69+
os.remove(fname)
70+
except os.error:
71+
pass
6772

6873
types = [(bsddb.btopen, 'BTree'),
6974
(bsddb.hashopen, 'Hash Table'),
75+
(bsddb.btopen, 'BTree', 0),
76+
(bsddb.hashopen, 'Hash Table', 0),
7077
# (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85
7178
# appears broken... at least on
7279
# Solaris Intel - rmasse 1/97
7380
]
7481

7582
for type in types:
76-
test(type[0], type[1])
83+
test(*type)

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ Core and builtins
6464

6565
Extension modules
6666

67+
- The bsddb.*open functions can now take 'None' as a filename.
68+
This will create a temporary in-memory bsddb that won't be
69+
written to disk.
70+
6771
- posix.mknod was added.
6872

6973
- The locale module now exposes the C library's gettext interface.

Modules/bsddbmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ bsdhashopen(PyObject *self, PyObject *args)
687687
int hash = 0; /* XXX currently ignored */
688688
int lorder = 0;
689689

690-
if (!PyArg_ParseTuple(args, "s|siiiiiii:hashopen",
690+
if (!PyArg_ParseTuple(args, "z|siiiiiii:hashopen",
691691
&file, &flag, &mode,
692692
&bsize, &ffactor, &nelem, &cachesize,
693693
&hash, &lorder))
@@ -738,7 +738,7 @@ bsdbtopen(PyObject *self, PyObject *args)
738738
unsigned int psize = 0;
739739
int lorder = 0;
740740

741-
if (!PyArg_ParseTuple(args, "s|siiiiiii:btopen",
741+
if (!PyArg_ParseTuple(args, "z|siiiiiii:btopen",
742742
&file, &flag, &mode,
743743
&btflags, &cachesize, &maxkeypage, &minkeypage,
744744
&psize, &lorder))
@@ -791,7 +791,7 @@ bsdrnopen(PyObject *self, PyObject *args)
791791
char *bval = "";
792792
char *bfname = NULL;
793793

794-
if (!PyArg_ParseTuple(args, "s|siiiiiiss:rnopen",
794+
if (!PyArg_ParseTuple(args, "z|siiiiiiss:rnopen",
795795
&file, &flag, &mode,
796796
&rnflags, &cachesize, &psize, &lorder,
797797
&reclen, &bval, &bfname))

0 commit comments

Comments
 (0)