En Sun, 14 Sep 2008 08:28:01 -0300,
<[EMAIL PROTECTED]> escribió:
int main (int argc, char * const argv[]) {
Py_Initialize();
FILE* fp = fopen("/Users/test/Desktop/123.pyc","wb");
PyCodeObject* op = (PyCodeObject*)Py_CompileString("import sys
\nprint 'hello'","<string.py>",Py_file_input);
PyMarshal_WriteObjectToFile((PyObject *)op, fp,
Py_MARSHAL_VERSION);
Py_Finalize();
return 0;
}
This Code crashs on Windows, and I can't explain why. I want to
convert a PyCodeObject to a PyObject and save it to the harddisk.
PyMarshal_ReadObjectFromFile(FILE *P) crashs too if I want to read a
byte-compiled object.
Your code should check every operation for errors. fopen may return NULL,
Py_CompileString may fail and return NULL, PyMarshal_xxx might fail
(although it's not documented).
Why "123.pyc"? Do you want to generate a compiled module? Use the
py_compile standard module instead (or write equivalent C code, or see how
import.c does that)
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list