[Pythonmac-SIG] C module creation on MacPython

Corran Webster cwebster@nevada.edu
Mon, 25 Oct 1999 16:02:54 -0700 (PDT)


> > > What is needed to create a c module in MacPython?
> > 
> > Doug Wyatt gave some pointers for compiling with CodeWarrior.  If you
> > don't have CodeWarrior, you can download MPW from Apple's ftp site for
> > free and compile using that.

FWIW, in my original post, I forgot to mention that you need to change the
:Mac:Include:config.h file to add support for forward static declarations 
if you are using MrC in MPW:

#ifdef __MRC__
#define BAD_STATIC_FORWARD
#endif

needs to be added at the appropriate point.

> Corran,
> I'm very surprised that your recipe works, as it mixes MPW libraries (in the 
> extension module) with CodeWarrior libraries (in PythonCore). I would expect 
> all sort of trouble with I/O, malloc/free, and possibly loads of other places.

I hadn't considered this possibility - and yes, there ar warnings about
symbols appearing in PythonCore plus some other library, but I had been
ignoring them for the large part, assuming that MPW would choose sensibly
between possible options.  As I said, I basically hacked around until I
got stuff to compile and run. 

I haven't really pushed these compiled modules to the limits, so I
wouldn't have noticed slow memory leaks or the like which would result
from malloc/free not working properly.

> If you're actually using this method, could you post a bit of information on 
> what works, what doesn't work and whether there are specific things you should 
> do (like calling printf, I can imagine)?

The main things I've tried have been pretty much pure C modules like
Marc-Andre Lemburg's various mx modules, so I/O and so forth haven't been 
major issues.

I just did a quick check with printf, and it appears that the order that
MPW links is important - if PythonCore is linked before StdCLib, then
printf appears to work fine; if linked in the other order then it simply
does nothing - no error, nothing printed to standard output, etc. which
makes sense because MPW StdCLib wouldn't know about SIOUX and would be
trying to use SIOW or the like, although it is interesting that it didn't
cause a crash.

Testing in the IDE, nothing appears either way - whether it was run in the
interactive window or as a script. 

StdCLib only appears to be required for linking by MPW if you are using
input/output in your module, so most of the modules I worked with weren't
using it at all, and so were using Python's versions of things like malloc
and free. 

I'm going to have to look at this a bit more closely, but my guess is that
you probably want PythonCore linked first so that you're using the same
versions of the basic C libraries.

The only other multiply defined symbols between PythonCore and the
standard MPW libraries are the cursor utilities, and only Mac-specific
modules would be using that.  So I suspect that most other modules will
compile and run fine as long as they aren't relying on OS specific
features.

The long and the short of it is that you seem to be able to get basic
stuff to work fine in MPW, but there may be subtle bugs in extreme
situations; stuff which requires I/O seems trickier, but with the right
linking order can probably be made to work.

I hope all this makes sense. I'd be more than interested in what more
experienced people have to say - my Macintosh coding experience is
limited.

Regards,
Corran