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.
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 @@
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;
}