[Pythonmac-SIG] error trying to run c extension from carbon P ython

Magladry, Stephen stephenm@humongous.com
Thu, 20 Jun 2002 18:24:47 -0700


Thanks for getting me straighten out. I am able to get my sample c library,
named cheese, executing in the release build. I need to be able to build a
slightly stripped down version of Python, though. So I grabbed the source
archive from the Mac Python Site. I started with the PythonStandalone.mcp
and made the following changes;




-change gusi access paths to my access path
-change use of GUSI_Core.CW6.Carb.Lib to GUSI_Core.CW7.Carb.Lib
-change use of GUSI_MSL.CW6.Carb.Lib to GUSI_MSL.CW7.Carb.Lib
-create new prefix file mwerks_HEcarbon_config.h
-change prefix file mwerks_nscarbon_config.h to mwerks_HEcarbon_config.h
-in mwerks_HEcarbon_config.h file  turn off USE_TOOLBOX, USE_QT, USE_WASTE,
USE_IMG, USE_GDBM, USE_ZLIB, USE_IC, USE_PYEXPAT
-turn off source files and libs I don't need because of above setting 
	-don't need dbmmodule.c file
	-don't need zlibmodule.c file
	-don't need any Extension:img
	-don't need any img libraries
	-don't need pyexpat.c
	-dont need modulewaste.c
	-don't need gdbm.pcc.gusi.Lib
	-don't need WASTE.carbon.lib
	-don't need any of the Waste (Common) files
	-don't need libexpat.ppc.Lib
	-change strdup in parsermodule.c to be (const char*)
I build and move this newly created app to /application/Python 2.2.1 just in
case there is some weird location problem (though location doesn't seem to
make a difference with these errors). I get to the prompt just fine. The
first command I try, no matter what command I type generates a "LookupError:
no codec search function registered: can't find encoding" Successive simple
python syntax like "i= 4" and "print i" generates proper results. 

When I try to "import cheese" I get the following error 

"Trackback (most recent call last)
File <stdin> line 1 in ?
ImportError:  No module named cheese"



Stepping through code generates some interesting results. Lets take them one
at a time.


first error:"LookupError: no codec search function registered: can't find
encoding"

The PyErr_SetString on line 171 in codecs.c in the function _PyCodec_Lookup
appears to get executed, but the error doesn't get displayed until the first
commands. Looking through the archives, when there is no Unix encoding, the
Mac defaults to MacRoman. I am running under Mac OS X. Can anyone think of a
reason why reason why _PyCodec_lookup would be failing in this case.


Second Error:"ImportError:  No module named cheese"

In looking at the code slb files need to be loaded in case_ok. Line 1148 in
the file import.c has the only reference to slb files. Putting a break point
in case_ok doesn't trip when I try to do my "import cheese". Upon further
examination, the stat on line 992 of import.c in the function find_module is
failing. I guess I'll take a further look at this one tomorrow.

Any insights would be appreciated, though.



-----Original Message-----
From: Jack Jansen [mailto:Jack.Jansen@oratrix.com]
Sent: Thursday, June 20, 2002 1:17 PM
To: Magladry, Stephen
Cc: 'pythonmac-sig@python.org'
Subject: Re: [Pythonmac-SIG] error trying to run c extension from carbon
Python


Stephen,
are you extending Python (building a new module to be imported) 
or embedding Python (putting the whole interpreter into another 
program)?

Some of the things you mention are used for embedding only 
(calls to PyMac_Initialize and such) but in other places you're 
referrring to failures to import something.

If you're extending Python: you don't need to recompile anything 
(except your extension module, of course), if you take the 
standard MacPython binary installer and also select the 
"developer" option (not selected with the easy install) you 
should be all set. If you also use distutils to build your 
extension you should have no problems whatsoever.

If you're embedding Python you may not need source either: you 
just call PyMac_Initialize() and then you can do any call you 
want. You want to read both the "embedding" section of the 
standard Python docs and :Mac:Demo:embed.html from the MacPython 
distribution.

On woensdag, juni 19, 2002, at 07:53 , Magladry, Stephen wrote:

> I am trying to run a c extension for a build of Python Carbon 
> and when I try
> to import the c extension, I get a "Interpreter not initialized 
> (version
> mismatch?)" error. Here's a run down of what I have done.
>
> 1. Tried to use stock Carbon Python. It isn't even able to import a new
> sample library. It come back with a syntax error, some kind of 
> stdin error
> if I remember correctly.
> 2. Needed to modify the Carbon project. As built, It doesn't 
> support Dynamic
> Loading. I added the three options USE_MAC_SHARED_LIBRARIES,
> USE_MAC_APPLETE_SUPPORT and  HAVE_DYNAMIC_LOADING.
> 2.5 Also use the call PYMac_Initialize() instead of PY_Initialize().
> 3. Add the necessary supporting c files in order to get Carbon 
> Python with
> the above library support linking.
> 3.5 Use dyload_mac.c in place of dynload_stub.c.
> 4. Rebuild PythonCarbonCore using the config.h files as the 
> above project.
> 5. Build a simple c extension that weak links to the newly created
> PythonCarbonCore.
> 6. Move the new created, PythonCarbonApp, PythonCarbonCore and 
> myLibrary to
> the same folder.
> 7. Fire up The Python interpreter.
> 8. Enter the command Import myLibrary, with the library file named
> "myLibrary.carbon.slb".
> 9. Get the error "Interpreter not initialized (version mismatch?)".
>
> I have stepped through the code at the interpreter level and 
> the last line
> of code that gets executed, at least at the interpreter level is
> GetDiskFragment, line 86 in dynload_mac.c. If I try to step 
> over this line
> of code, I get the error.
>
> Questions:
>
> 1. Anyone know why I'm getting this error? It doesn't seem like 
> I have a
> version mismatch since everything is running off the same code base.
> 2. Does anyone see something glaring that I have done wrong?
> 3. Has anyone been able to set up a Python Carbon that is able 
> to call c
> extensions?
> 4. Is it even possible in the current state to have the Carbon 
> code call a c
> extensions?
>
>
> Thanks for your time,
>
>
> Stephen Magladry
>
>
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
>
--
- Jack Jansen        <Jack.Jansen@oratrix.com>        
http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution -- 
Emma Goldman -