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.
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 @@
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 @@
&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);