PyMarshal Commands crash on Windows

G

Guest

Hi!

Can anyone help me with this issue?

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.


Thank your for your help.

donnerChecker
 
G

Gabriel Genellina

En Sun, 14 Sep 2008 08:28:01 -0300,
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)
 
G

Guest

Hi!

I shortened the quode. Everything should be all right and nothing is a
NULL Pointer.
What about PyMarshal_ReadObjectFromFile(FILE* p), this crashs too :-/
hm...

the problem is, on mac everything is all right..

thanks...
 
F

Fredrik Lundh

I shortened the quode. Everything should be all right and nothing is a
NULL Pointer. What about PyMarshal_ReadObjectFromFile(FILE* p), this
> crashs too :-/

the layout of the "FILE" structure isn't standardized. make sure you're
linking everything with the same runtime library.

</F>
 
T

Tim Golden

Hi!

Any ideas on it?

(Haven't got the original post in front of
me, but I'll guess anyway...)

Was the Python you're using built with one compiler
and runtime, while the extension / embedee you're
building is built with another? I ask because the
most frequently-touted example of cross-compiler
or cross-runtime incompatibility on Windows is the
FILE* structure. And I seem to remember you're using
that to write the marshalled objects out....

.... just a wild guess

TJG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top