Py_DECREF(empty);
}
- pb = code->ob_type->tp_as_buffer;
- if (pb == NULL ||
- pb->bf_getreadbuffer == NULL ||
- pb->bf_getsegcount == NULL ||
- (*pb->bf_getsegcount)(code, NULL) != 1)
- {
+ if (!PyObject_CheckReadBuffer(code)) {
PyErr_SetString(PyExc_TypeError,
"bytecode object must be a single-segment read-only buffer");
return NULL;
{
PyCodeObject *co;
int i;
- PyBufferProcs *pb;
/* Check argument types */
if (argcount < 0 || nlocals < 0 ||
code == NULL ||
cellvars == NULL || !PyTuple_Check(cellvars) ||
name == NULL || !PyString_Check(name) ||
filename == NULL || !PyString_Check(filename) ||
- lnotab == NULL || !PyString_Check(lnotab)) {
- PyErr_BadInternalCall();
- 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)
- {
+ lnotab == NULL || !PyString_Check(lnotab) ||
+ !PyObject_CheckReadBuffer(code)) {
PyErr_BadInternalCall();
return NULL;
}
w_object(PyObject *v, WFILE *p)
{
int i, n;
- PyBufferProcs *pb;
p->depth++;
w_short(co->co_firstlineno, p);
w_object(co->co_lnotab, p);
}
- else if ((pb = v->ob_type->tp_as_buffer) != NULL &&
- pb->bf_getsegcount != NULL &&
- pb->bf_getreadbuffer != NULL &&
- (*pb->bf_getsegcount)(v, NULL) == 1)
- {
+ else if (PyObject_CheckReadBuffer(v)) {
/* Write unknown buffer-style objects as a string */
char *s;
+ PyBufferProcs *pb = v->ob_type->tp_as_buffer;
w_byte(TYPE_STRING, p);
n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s);
w_long((long)n, p);