Kaydet (Commit) 8d4c9817 authored tarafından Neal Norwitz's avatar Neal Norwitz

Fix SF # 640557, '64-bit' systems and the dbm module

datum.dsize can apparently be long on some systems.
Ensure we pass an int* to PyArg_Parse("s#"), not &datum.dsize

Will backport.
üst 450cafae
...@@ -94,10 +94,12 @@ static PyObject * ...@@ -94,10 +94,12 @@ static PyObject *
dbm_subscript(dbmobject *dp, register PyObject *key) dbm_subscript(dbmobject *dp, register PyObject *key)
{ {
datum drec, krec; datum drec, krec;
int tmp_size;
if (!PyArg_Parse(key, "s#", &krec.dptr, &krec.dsize) ) if (!PyArg_Parse(key, "s#", &krec.dptr, &tmp_size) )
return NULL; return NULL;
krec.dsize = tmp_size;
check_dbmobject_open(dp); check_dbmobject_open(dp);
drec = dbm_fetch(dp->di_dbm, krec); drec = dbm_fetch(dp->di_dbm, krec);
if ( drec.dptr == 0 ) { if ( drec.dptr == 0 ) {
...@@ -117,12 +119,14 @@ static int ...@@ -117,12 +119,14 @@ static int
dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w) dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
{ {
datum krec, drec; datum krec, drec;
int tmp_size;
if ( !PyArg_Parse(v, "s#", &krec.dptr, &krec.dsize) ) { if ( !PyArg_Parse(v, "s#", &krec.dptr, &tmp_size) ) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"dbm mappings have string indices only"); "dbm mappings have string indices only");
return -1; return -1;
} }
krec.dsize = tmp_size;
if (dp->di_dbm == NULL) { if (dp->di_dbm == NULL) {
PyErr_SetString(DbmError, "DBM object has already been closed"); PyErr_SetString(DbmError, "DBM object has already been closed");
return -1; return -1;
...@@ -136,11 +140,12 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w) ...@@ -136,11 +140,12 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
return -1; return -1;
} }
} else { } else {
if ( !PyArg_Parse(w, "s#", &drec.dptr, &drec.dsize) ) { if ( !PyArg_Parse(w, "s#", &drec.dptr, &tmp_size) ) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"dbm mappings have string elements only"); "dbm mappings have string elements only");
return -1; return -1;
} }
drec.dsize = tmp_size;
if ( dbm_store(dp->di_dbm, krec, drec, DBM_REPLACE) < 0 ) { if ( dbm_store(dp->di_dbm, krec, drec, DBM_REPLACE) < 0 ) {
dbm_clearerr(dp->di_dbm); dbm_clearerr(dp->di_dbm);
PyErr_SetString(DbmError, PyErr_SetString(DbmError,
...@@ -208,9 +213,11 @@ static PyObject * ...@@ -208,9 +213,11 @@ static PyObject *
dbm_has_key(register dbmobject *dp, PyObject *args) dbm_has_key(register dbmobject *dp, PyObject *args)
{ {
datum key, val; datum key, val;
int tmp_size;
if (!PyArg_ParseTuple(args, "s#:has_key", &key.dptr, &key.dsize)) if (!PyArg_ParseTuple(args, "s#:has_key", &key.dptr, &tmp_size))
return NULL; return NULL;
key.dsize = tmp_size;
check_dbmobject_open(dp); check_dbmobject_open(dp);
val = dbm_fetch(dp->di_dbm, key); val = dbm_fetch(dp->di_dbm, key);
return PyInt_FromLong(val.dptr != NULL); return PyInt_FromLong(val.dptr != NULL);
...@@ -221,10 +228,12 @@ dbm_get(register dbmobject *dp, PyObject *args) ...@@ -221,10 +228,12 @@ dbm_get(register dbmobject *dp, PyObject *args)
{ {
datum key, val; datum key, val;
PyObject *defvalue = Py_None; PyObject *defvalue = Py_None;
int tmp_size;
if (!PyArg_ParseTuple(args, "s#|O:get", if (!PyArg_ParseTuple(args, "s#|O:get",
&key.dptr, &key.dsize, &defvalue)) &key.dptr, &tmp_size, &defvalue))
return NULL; return NULL;
key.dsize = tmp_size;
check_dbmobject_open(dp); check_dbmobject_open(dp);
val = dbm_fetch(dp->di_dbm, key); val = dbm_fetch(dp->di_dbm, key);
if (val.dptr != NULL) if (val.dptr != NULL)
...@@ -240,10 +249,12 @@ dbm_setdefault(register dbmobject *dp, PyObject *args) ...@@ -240,10 +249,12 @@ dbm_setdefault(register dbmobject *dp, PyObject *args)
{ {
datum key, val; datum key, val;
PyObject *defvalue = NULL; PyObject *defvalue = NULL;
int tmp_size;
if (!PyArg_ParseTuple(args, "s#|S:setdefault", if (!PyArg_ParseTuple(args, "s#|S:setdefault",
&key.dptr, &key.dsize, &defvalue)) &key.dptr, &tmp_size, &defvalue))
return NULL; return NULL;
key.dsize = tmp_size;
check_dbmobject_open(dp); check_dbmobject_open(dp);
val = dbm_fetch(dp->di_dbm, key); val = dbm_fetch(dp->di_dbm, key);
if (val.dptr != NULL) if (val.dptr != NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment