fixes deferred/release blocker issue #3797: Fixed the dbm, marshal, mmap,
ossaudiodev, & winreg modules to return bytes objects instead of bytearray objects.
This commit is contained in:
parent
7e958d1ceb
commit
0a608fdaac
|
@ -144,6 +144,9 @@ Extension Modules
|
||||||
- Issue #3492 and #3790: Fixed the zlib module and zipimport module uses of
|
- Issue #3492 and #3790: Fixed the zlib module and zipimport module uses of
|
||||||
mutable bytearray objects where they should have been using immutable bytes.
|
mutable bytearray objects where they should have been using immutable bytes.
|
||||||
|
|
||||||
|
- Issue #3797: Fixed the dbm, marshal, mmap, ossaudiodev, & winreg modules to
|
||||||
|
return bytes objects instead of bytearray objects.
|
||||||
|
|
||||||
|
|
||||||
Tools/Demos
|
Tools/Demos
|
||||||
-----------
|
-----------
|
||||||
|
|
|
@ -111,7 +111,7 @@ dbm_subscript(dbmobject *dp, register PyObject *key)
|
||||||
PyErr_SetString(DbmError, "");
|
PyErr_SetString(DbmError, "");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return PyByteArray_FromStringAndSize(drec.dptr, drec.dsize);
|
return PyBytes_FromStringAndSize(drec.dptr, drec.dsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -188,7 +188,7 @@ dbm_keys(register dbmobject *dp, PyObject *unused)
|
||||||
return NULL;
|
return NULL;
|
||||||
for (key = dbm_firstkey(dp->di_dbm); key.dptr;
|
for (key = dbm_firstkey(dp->di_dbm); key.dptr;
|
||||||
key = dbm_nextkey(dp->di_dbm)) {
|
key = dbm_nextkey(dp->di_dbm)) {
|
||||||
item = PyByteArray_FromStringAndSize(key.dptr, key.dsize);
|
item = PyBytes_FromStringAndSize(key.dptr, key.dsize);
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -260,7 +260,7 @@ dbm_get(register dbmobject *dp, PyObject *args)
|
||||||
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)
|
||||||
return PyByteArray_FromStringAndSize(val.dptr, val.dsize);
|
return PyBytes_FromStringAndSize(val.dptr, val.dsize);
|
||||||
else {
|
else {
|
||||||
Py_INCREF(defvalue);
|
Py_INCREF(defvalue);
|
||||||
return defvalue;
|
return defvalue;
|
||||||
|
@ -283,9 +283,9 @@ dbm_setdefault(register dbmobject *dp, PyObject *args)
|
||||||
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)
|
||||||
return PyByteArray_FromStringAndSize(val.dptr, val.dsize);
|
return PyBytes_FromStringAndSize(val.dptr, val.dsize);
|
||||||
if (defvalue == NULL) {
|
if (defvalue == NULL) {
|
||||||
defvalue = PyByteArray_FromStringAndSize(NULL, 0);
|
defvalue = PyBytes_FromStringAndSize(NULL, 0);
|
||||||
if (defvalue == NULL)
|
if (defvalue == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
val.dptr = NULL;
|
val.dptr = NULL;
|
||||||
|
|
|
@ -228,7 +228,7 @@ mmap_read_line_method(mmap_object *self,
|
||||||
else
|
else
|
||||||
++eol; /* we're interested in the position after the
|
++eol; /* we're interested in the position after the
|
||||||
newline. */
|
newline. */
|
||||||
result = PyByteArray_FromStringAndSize(start, (eol - start));
|
result = PyBytes_FromStringAndSize(start, (eol - start));
|
||||||
self->pos += (eol - start);
|
self->pos += (eol - start);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ mmap_read_method(mmap_object *self,
|
||||||
if (num_bytes > self->size - self->pos) {
|
if (num_bytes > self->size - self->pos) {
|
||||||
num_bytes -= (self->pos+num_bytes) - self->size;
|
num_bytes -= (self->pos+num_bytes) - self->size;
|
||||||
}
|
}
|
||||||
result = PyByteArray_FromStringAndSize(self->data+self->pos, num_bytes);
|
result = PyBytes_FromStringAndSize(self->data+self->pos, num_bytes);
|
||||||
self->pos += num_bytes;
|
self->pos += num_bytes;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -679,7 +679,7 @@ mmap_item(mmap_object *self, Py_ssize_t i)
|
||||||
PyErr_SetString(PyExc_IndexError, "mmap index out of range");
|
PyErr_SetString(PyExc_IndexError, "mmap index out of range");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return PyByteArray_FromStringAndSize(self->data + i, 1);
|
return PyBytes_FromStringAndSize(self->data + i, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -769,14 +769,14 @@ mmap_ass_item(mmap_object *self, Py_ssize_t i, PyObject *v)
|
||||||
"mmap object doesn't support item deletion");
|
"mmap object doesn't support item deletion");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (! (PyByteArray_Check(v) && PyByteArray_Size(v)==1) ) {
|
if (! (PyBytes_Check(v) && PyBytes_Size(v)==1) ) {
|
||||||
PyErr_SetString(PyExc_IndexError,
|
PyErr_SetString(PyExc_IndexError,
|
||||||
"mmap assignment must be length-1 bytes()");
|
"mmap assignment must be length-1 bytes()");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!is_writable(self))
|
if (!is_writable(self))
|
||||||
return -1;
|
return -1;
|
||||||
buf = PyByteArray_AsString(v);
|
buf = PyBytes_AsString(v);
|
||||||
self->data[i] = buf[0];
|
self->data[i] = buf[0];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,10 +366,10 @@ oss_read(oss_audio_t *self, PyObject *args)
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "i:read", &size))
|
if (!PyArg_ParseTuple(args, "i:read", &size))
|
||||||
return NULL;
|
return NULL;
|
||||||
rv = PyByteArray_FromStringAndSize(NULL, size);
|
rv = PyBytes_FromStringAndSize(NULL, size);
|
||||||
if (rv == NULL)
|
if (rv == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
cp = PyByteArray_AS_STRING(rv);
|
cp = PyBytes_AS_STRING(rv);
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
count = read(self->fd, cp, size);
|
count = read(self->fd, cp, size);
|
||||||
|
@ -381,7 +381,7 @@ oss_read(oss_audio_t *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
self->icount += count;
|
self->icount += count;
|
||||||
PyByteArray_Resize(rv, count);
|
_PyBytes_Resize(&rv, count);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -896,7 +896,7 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ)
|
||||||
obData = Py_None;
|
obData = Py_None;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
obData = PyByteArray_FromStringAndSize(
|
obData = PyBytes_FromStringAndSize(
|
||||||
(char *)retDataBuf, retDataSize);
|
(char *)retDataBuf, retDataSize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1093,7 +1093,7 @@ PyMarshal_WriteObjectToString(PyObject *x, int version)
|
||||||
}
|
}
|
||||||
if (wf.str != NULL) {
|
if (wf.str != NULL) {
|
||||||
/* XXX Quick hack -- need to do this differently */
|
/* XXX Quick hack -- need to do this differently */
|
||||||
res = PyByteArray_FromObject(wf.str);
|
res = PyBytes_FromObject(wf.str);
|
||||||
Py_DECREF(wf.str);
|
Py_DECREF(wf.str);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -1134,9 +1134,9 @@ marshal_load(PyObject *self, PyObject *f)
|
||||||
rf.ptr = PyBytes_AS_STRING(data);
|
rf.ptr = PyBytes_AS_STRING(data);
|
||||||
rf.end = rf.ptr + PyBytes_GET_SIZE(data);
|
rf.end = rf.ptr + PyBytes_GET_SIZE(data);
|
||||||
}
|
}
|
||||||
else if (PyByteArray_Check(data)) {
|
else if (PyBytes_Check(data)) {
|
||||||
rf.ptr = PyByteArray_AS_STRING(data);
|
rf.ptr = PyBytes_AS_STRING(data);
|
||||||
rf.end = rf.ptr + PyByteArray_GET_SIZE(data);
|
rf.end = rf.ptr + PyBytes_GET_SIZE(data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
|
|
Loading…
Reference in New Issue