summaryrefslogtreecommitdiffstats
path: root/Modules/newmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-10-07 19:42:25 (GMT)
committerGuido van Rossum <guido@python.org>1998-10-07 19:42:25 (GMT)
commitd076c73cc81a974794c9aa7e812931b74d6e03c2 (patch)
tree55b5c7b6c145d5491c2dd63780c9654c51aa2306 /Modules/newmodule.c
parent437ff8600a2959e87194f1491ba99116d73ea543 (diff)
downloadcpython-d076c73cc81a974794c9aa7e812931b74d6e03c2.zip
cpython-d076c73cc81a974794c9aa7e812931b74d6e03c2.tar.gz
cpython-d076c73cc81a974794c9aa7e812931b74d6e03c2.tar.bz2
Changes to support other object types besides strings
as the code string of code objects, as long as they support the (readonly) buffer interface. By Greg Stein.
Diffstat (limited to 'Modules/newmodule.c')
-rw-r--r--Modules/newmodule.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/Modules/newmodule.c b/Modules/newmodule.c
index 52328a9..5c92e0e 100644
--- a/Modules/newmodule.c
+++ b/Modules/newmodule.c
@@ -150,8 +150,9 @@ new_code(unused, args)
PyObject* name;
int firstlineno;
PyObject* lnotab;
-
- if (!PyArg_ParseTuple(args, "iiiiSO!O!O!SSiS",
+ PyBufferProcs *pb;
+
+ if (!PyArg_ParseTuple(args, "iiiiOO!O!O!SSiS",
&argcount, &nlocals, &stacksize, &flags,
&code,
&PyTuple_Type, &consts,
@@ -160,6 +161,18 @@ new_code(unused, args)
&filename, &name,
&firstlineno, &lnotab))
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_SetString(PyExc_TypeError,
+ "bytecode object must be a single-segment read-only buffer");
+ return NULL;
+ }
+
return (PyObject *)PyCode_New(argcount, nlocals, stacksize, flags,
code, consts, names, varnames,
filename, name, firstlineno, lnotab);