mirror of
https://github.com/python/cpython.git
synced 2025-09-25 09:50:37 +00:00
Use PyObject_CheckReadBuffer().
This commit is contained in:
parent
89c3a22a27
commit
9f64caaf00
3 changed files with 5 additions and 23 deletions
|
@ -153,12 +153,7 @@ new_code(PyObject* unused, PyObject* args)
|
||||||
Py_DECREF(empty);
|
Py_DECREF(empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
pb = code->ob_type->tp_as_buffer;
|
if (!PyObject_CheckReadBuffer(code)) {
|
||||||
if (pb == NULL ||
|
|
||||||
pb->bf_getreadbuffer == NULL ||
|
|
||||||
pb->bf_getsegcount == NULL ||
|
|
||||||
(*pb->bf_getsegcount)(code, NULL) != 1)
|
|
||||||
{
|
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"bytecode object must be a single-segment read-only buffer");
|
"bytecode object must be a single-segment read-only buffer");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -268,7 +268,6 @@ PyCode_New(int argcount, int nlocals, int stacksize, int flags,
|
||||||
{
|
{
|
||||||
PyCodeObject *co;
|
PyCodeObject *co;
|
||||||
int i;
|
int i;
|
||||||
PyBufferProcs *pb;
|
|
||||||
/* Check argument types */
|
/* Check argument types */
|
||||||
if (argcount < 0 || nlocals < 0 ||
|
if (argcount < 0 || nlocals < 0 ||
|
||||||
code == NULL ||
|
code == NULL ||
|
||||||
|
@ -279,16 +278,8 @@ PyCode_New(int argcount, int nlocals, int stacksize, int flags,
|
||||||
cellvars == NULL || !PyTuple_Check(cellvars) ||
|
cellvars == NULL || !PyTuple_Check(cellvars) ||
|
||||||
name == NULL || !PyString_Check(name) ||
|
name == NULL || !PyString_Check(name) ||
|
||||||
filename == NULL || !PyString_Check(filename) ||
|
filename == NULL || !PyString_Check(filename) ||
|
||||||
lnotab == NULL || !PyString_Check(lnotab)) {
|
lnotab == NULL || !PyString_Check(lnotab) ||
|
||||||
PyErr_BadInternalCall();
|
!PyObject_CheckReadBuffer(code)) {
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
pb = code->ob_type->tp_as_buffer;
|
|
||||||
if (pb == NULL ||
|
|
||||||
pb->bf_getreadbuffer == NULL ||
|
|
||||||
pb->bf_getsegcount == NULL ||
|
|
||||||
(*pb->bf_getsegcount)(code, NULL) != 1)
|
|
||||||
{
|
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,6 @@ static void
|
||||||
w_object(PyObject *v, WFILE *p)
|
w_object(PyObject *v, WFILE *p)
|
||||||
{
|
{
|
||||||
int i, n;
|
int i, n;
|
||||||
PyBufferProcs *pb;
|
|
||||||
|
|
||||||
p->depth++;
|
p->depth++;
|
||||||
|
|
||||||
|
@ -249,13 +248,10 @@ w_object(PyObject *v, WFILE *p)
|
||||||
w_short(co->co_firstlineno, p);
|
w_short(co->co_firstlineno, p);
|
||||||
w_object(co->co_lnotab, p);
|
w_object(co->co_lnotab, p);
|
||||||
}
|
}
|
||||||
else if ((pb = v->ob_type->tp_as_buffer) != NULL &&
|
else if (PyObject_CheckReadBuffer(v)) {
|
||||||
pb->bf_getsegcount != NULL &&
|
|
||||||
pb->bf_getreadbuffer != NULL &&
|
|
||||||
(*pb->bf_getsegcount)(v, NULL) == 1)
|
|
||||||
{
|
|
||||||
/* Write unknown buffer-style objects as a string */
|
/* Write unknown buffer-style objects as a string */
|
||||||
char *s;
|
char *s;
|
||||||
|
PyBufferProcs *pb = v->ob_type->tp_as_buffer;
|
||||||
w_byte(TYPE_STRING, p);
|
w_byte(TYPE_STRING, p);
|
||||||
n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s);
|
n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s);
|
||||||
w_long((long)n, p);
|
w_long((long)n, p);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue