From 9f64caaf00340fce95c2980435ef819e385cf5ff Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Fri, 9 Nov 2001 22:02:48 +0000 Subject: [PATCH] Use PyObject_CheckReadBuffer(). --- Modules/newmodule.c | 7 +------ Python/compile.c | 13 ++----------- Python/marshal.c | 8 ++------ 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/Modules/newmodule.c b/Modules/newmodule.c index 9a9cbf16855..6c29fe43150 100644 --- a/Modules/newmodule.c +++ b/Modules/newmodule.c @@ -153,12 +153,7 @@ new_code(PyObject* unused, PyObject* args) 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; diff --git a/Python/compile.c b/Python/compile.c index 1a46064dd47..b477513dc1f 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -268,7 +268,6 @@ PyCode_New(int argcount, int nlocals, int stacksize, int flags, { PyCodeObject *co; int i; - PyBufferProcs *pb; /* Check argument types */ if (argcount < 0 || nlocals < 0 || code == NULL || @@ -279,16 +278,8 @@ PyCode_New(int argcount, int nlocals, int stacksize, int flags, 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; } diff --git a/Python/marshal.c b/Python/marshal.c index 806b91c71d4..0d21e847b77 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -108,7 +108,6 @@ static void w_object(PyObject *v, WFILE *p) { int i, n; - PyBufferProcs *pb; p->depth++; @@ -249,13 +248,10 @@ w_object(PyObject *v, WFILE *p) 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);