mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Preserve backward compatibility of the ctypes module.
"This file should be kept compatible with Python 2.3, see PEP 291."
This commit is contained in:
parent
9e7a4c9738
commit
eba2aca4bd
1 changed files with 11 additions and 0 deletions
|
@ -1076,16 +1076,23 @@ CharArray_set_raw(CDataObject *self, PyObject *value)
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
Py_ssize_t size;
|
Py_ssize_t size;
|
||||||
|
#if (PY_VERSION_HEX >= 0x02060000)
|
||||||
Py_buffer view = { 0 };
|
Py_buffer view = { 0 };
|
||||||
|
#endif
|
||||||
if (PyBuffer_Check(value)) {
|
if (PyBuffer_Check(value)) {
|
||||||
size = Py_TYPE(value)->tp_as_buffer->bf_getreadbuffer(value, 0, (void *)&ptr);
|
size = Py_TYPE(value)->tp_as_buffer->bf_getreadbuffer(value, 0, (void *)&ptr);
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
} else {
|
} else {
|
||||||
|
#if (PY_VERSION_HEX >= 0x02060000)
|
||||||
if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
|
if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
size = view.len;
|
size = view.len;
|
||||||
ptr = view.buf;
|
ptr = view.buf;
|
||||||
|
#else
|
||||||
|
if (-1 == PyString_AsStringAndSize(value, &ptr, &size))
|
||||||
|
goto fail;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (size > self->b_size) {
|
if (size > self->b_size) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
|
@ -1095,11 +1102,15 @@ CharArray_set_raw(CDataObject *self, PyObject *value)
|
||||||
|
|
||||||
memcpy(self->b_ptr, ptr, size);
|
memcpy(self->b_ptr, ptr, size);
|
||||||
|
|
||||||
|
#if (PY_VERSION_HEX >= 0x02060000)
|
||||||
PyBuffer_Release(&view);
|
PyBuffer_Release(&view);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
fail:
|
fail:
|
||||||
|
|
||||||
|
#if (PY_VERSION_HEX >= 0x02060000)
|
||||||
PyBuffer_Release(&view);
|
PyBuffer_Release(&view);
|
||||||
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue