[Pythonmac-SIG] Embedding problems on the Macintosh

Sean Hummel seanh@unforgettable.com
Tue, 24 Aug 1999 00:11:31 -0700


Hi I'm having some problems using the Py_CompileString function.  Previously
in my application I was using Compiled PYC resources for embedding Python
modules in my application.   However I need to now use plain text files, and
I was looking for a way to do this.

Since I couldn't find an example of this, I went header diving in the Python
source.  I had all ready figure out how to get this to work with already
compiled 'PYC ' resources, and I tried using the Py_CompileString.

The problem is that every time I call "Py_CompileString" it causes my
application to quit.

The following is the segment of code I am using.  I set my heap up to 26000
so that works.  The problem is that the function "Py_CompileString" never
returns, and it dumps the application.


 //
 // Initialize Python
 //
 
 PyMac_Initialize();
 

 
 FSSpec mainfilespec;
 long size;
 PyObject *code;
 PyObject *result;
 char  errortext[4096]={0};
 int   errornumber=0;
 int      inited=0;
 
 inited=Py_IsInitialized();
  
 if (fnfErr != FSMakeFSSpec(0,0,"\pmain.py",&mainfilespec))
 {
  short mfref=0;
  long size=0;
  char* data=NULL;
  
  FSpOpenDF(&mainfilespec,fsCurPerm,&mfref);
  GetEOF(mfref,&size);
  SetFPos(mfref,1,0);
  data=new char[size];
  if (data)
  {
   long inout=size;
   FSRead(mfref,&inout,data);
   code=Py_CompileString(data,"main.py",0);
   delete [] data;
  }
  
  FSClose(mfref);
  
  if (errornumber)
  {
   printf(errortext);
  }
 }
 else
 {
  ExitToShell();
 }