summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2007-11-01 21:55:08 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2007-11-01 21:55:08 (GMT)
commit568065e9d152ed495775a767968a8749fe78a75c (patch)
tree1df5f9cc6364ed2f4183c65cd3197e2e30fce5dc /Modules
parent48decfe7403bc1dda386cc469b28236c8de018d2 (diff)
downloadcpython-568065e9d152ed495775a767968a8749fe78a75c.zip
cpython-568065e9d152ed495775a767968a8749fe78a75c.tar.gz
cpython-568065e9d152ed495775a767968a8749fe78a75c.tar.bz2
Fixes issue1371 and reenables those tests.
Merge r58757 and r58758 from trunk. Undoes incorrect dbtables fix and errant strdup introduced as described below: r58757 | gregory.p.smith | 2007-11-01 14:08:14 -0700 (Thu, 01 Nov 2007) | 4 lines Fix bug introduced in revision 58385. Database keys could no longer have NULL bytes in them. Replace the errant strdup with a malloc+memcpy. Adds a unit test for the correct behavior. r58758 | gregory.p.smith | 2007-11-01 14:15:36 -0700 (Thu, 01 Nov 2007) | 3 lines Undo revision 58533 58534 fixes. Those were a workaround for a problem introduced by 58385.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_bsddb.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index befdd7b..874b7f7 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -439,8 +439,22 @@ make_key_dbt(DBObject* self, PyObject* keyobj, DBT* key, int* pflags,
if ( !(view = _malloc_view(keyobj)) )
return 0;
- key->data = view->buf;
+ /*
+ * NOTE(gps): I don't like doing a data copy here, it seems
+ * wasteful. But without a clean way to tell FREE_DBT if it
+ * should free key->data or not we have to. Other places in
+ * the code check for DB_THREAD and forceably set DBT_MALLOC
+ * when we otherwise would leave flags 0 to indicate that.
+ */
key->size = Py_SAFE_DOWNCAST(view->len, Py_ssize_t, u_int32_t);
+ key->data = malloc(key->size);
+ if (key->data == NULL) {
+ PyErr_SetString(PyExc_MemoryError, "Key memory allocation failed");
+ key->size = 0;
+ return 0;
+ }
+ memcpy(key->data, view->buf, key->size);
+ key->flags = DB_DBT_REALLOC;
*returned_view_p = view;
}