Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Unified Diff: Modules/cPickle.c

Issue 91044: Fix the last regression shown by cvs2svn (Closed) SVN Base: http://unladen-swallow.googlecode.com/svn/trunk/
Patch Set: Created 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side by-side-diff with in-line comments
Download patch
Index: Modules/cPickle.c
===================================================================
--- Modules/cPickle.c (revision 689)
+++ Modules/cPickle.c (working copy)
@@ -351,6 +351,7 @@
STATIC_MEMOTABLE PyMemoTable *
PyMemoTable_Copy(PyMemoTable *self)
{
+ Py_ssize_t i;
PyMemoTable *new = PyMemoTable_New();
if (new == NULL)
return NULL;
@@ -366,6 +367,9 @@
PyMem_FREE(new);
return NULL;
}
+ for (i = 0; i < self->mt_allocated; i++) {
+ Py_XINCREF(self->mt_table[i].me_key);
+ }
memcpy(new->mt_table, self->mt_table,
sizeof(PyMemoEntry) * self->mt_allocated);
@@ -375,6 +379,11 @@
STATIC_MEMOTABLE void
PyMemoTable_Del(PyMemoTable *self)
{
+ Py_ssize_t i;
Jeffrey Yasskin 2009/07/03 01:32:59 Just call PyMemoTable_Clear()? The extra memset sh
+ for (i = 0; i < self->mt_allocated; i++) {
+ Py_XDECREF(self->mt_table[i].me_key);
+ }
+
PyMem_FREE(self->mt_table);
PyMem_FREE(self);
}
@@ -388,6 +397,11 @@
STATIC_MEMOTABLE int
PyMemoTable_Clear(PyMemoTable *self)
{
+ Py_ssize_t i;
+ for (i = 0; i < self->mt_allocated; i++) {
+ Py_XDECREF(self->mt_table[i].me_key);
+ }
+
self->mt_used = 0;
memset(self->mt_table, 0, self->mt_allocated * sizeof(PyMemoEntry));
return 0;
@@ -396,7 +410,7 @@
/* Since entries cannot be deleted from this hashtable, _PyMemoTable_Lookup()
can be considerably simpler than dictobject.c's lookdict(). */
static PyMemoEntry *
-_PyMemoTable_Lookup(PyMemoTable *self, void *key)
+_PyMemoTable_Lookup(PyMemoTable *self, PyObject *key)
{
size_t i;
size_t perturb;
@@ -477,7 +491,7 @@
/* Returns NULL on failure, a pointer to the value otherwise. */
STATIC_MEMOTABLE long *
-PyMemoTable_Get(PyMemoTable *self, void *key)
+PyMemoTable_Get(PyMemoTable *self, PyObject *key)
{
PyMemoEntry *entry = _PyMemoTable_Lookup(self, key);
if (entry->me_key == NULL)
@@ -487,7 +501,7 @@
/* Returns -1 on failure, 0 on success. */
STATIC_MEMOTABLE int
-PyMemoTable_Set(PyMemoTable *self, void *key, long value)
+PyMemoTable_Set(PyMemoTable *self, PyObject *key, long value)
{
PyMemoEntry *entry;
@@ -498,6 +512,7 @@
entry->me_value = value;
return 0;
}
+ Py_INCREF(key);
entry->me_key = key;
entry->me_value = value;
self->mt_used++;
@@ -1066,7 +1081,7 @@
static int
-get(Picklerobject *self, void *id)
+get(Picklerobject *self, PyObject *id)
{
long *value;
char s[30];
@@ -1074,7 +1089,7 @@
value = PyMemoTable_Get(self->memo, id);
if (value == NULL) {
- PyErr_SetObject(PyExc_KeyError, PyLong_FromVoidPtr(id));
+ PyErr_SetObject(PyExc_KeyError, PyLong_FromVoidPtr((void *)id));
return -1;
}
@@ -1129,7 +1144,7 @@
/* PyMemoTable_{Get,Set} doesn't accept null pointers as keys. */
p = PyMemoTable_Size(self->memo) + 1;
- if (PyMemoTable_Set(self->memo, (void *)ob, p) < 0)
+ if (PyMemoTable_Set(self->memo, ob, p) < 0)
return -1;
if (!self->bin) {
@@ -3494,10 +3509,8 @@
p->memo = PyMemoTable_New();
while (PyDict_Next(pymemo, &i, &pykey, &pyval)) {
- long val;
- void *key = (void *)PyLong_AsLong(pykey);
- val = PyLong_AsLong(pyval);
- if (PyMemoTable_Set(p->memo, key, val) < 0)
+ long val = PyLong_AsLong(pyval);
+ if (PyMemoTable_Set(p->memo, pykey, val) < 0)
return -1;
}
« Modules/_testcapimodule.c ('k') | no next file »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497