[Pythonmac-SIG] OS X import bug?
Manoj Plakal
terabaap@yumpee.org
Thu, 24 Jan 2002 12:58:01 -0600
This is a multi-part message in MIME format.
--------------000802010502030105080006
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hello,
I've just noticed a weird problem with importing modules
on MacOS X 10.1 and Python 2.2.
Say I have two modules foo and bar, both of which
are built with a common file baz.c with some variables
defined in it.
I make a setup.py which specifies that module foo
is built from foomodule.c and baz.c, and module bar
is built from barmodule.c and baz.c.
On Red Hat Linux 7.2 with Python 2.2, this builds fine and I
can import both foo and bar into the same interpreter session.
On OS X 10.1 with Python 2.2, this builds fine but I can
only import *ONE* of foo or bar into the same interpreter
session. E.g., if I import foo first and then bar,
Python craps out saying "Failure linking new module".
Similary for bar first and then foo.
This is both with a version built from the 2.2 source
release, as well as a binary version from Fink
(fink.sourceforge.net).
I've attached the files which can be used to reproduce
this: setup.py, foomodule.c, barmodule.c, baz.c. In
case the attachments don't work, you can grab them
off the web: http://yumpee.org/python/setup.py
http://yumpee.org/python/foomodule.c
http://yumpee.org/python/barmodule.c
http://yumpee.org/python/baz.c
Is this a bug? Undefined behavior? Feature?
Is it a fluke that it works on Linux?
If someone else with OS X can reproduce this error,
(and people on other OSes can confirm that
it's working), that would be great ...
Manoj
--------------000802010502030105080006
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
name="setup.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="setup.py"
#
# Targets: build test install help
#
from distutils.core import setup, Extension
# Distutils setup call
setup (
ext_modules = [Extension('foo',
['foomodule.c',
'baz.c'],
),
Extension('bar',
['barmodule.c',
'baz.c'],
),
]
)
--------------000802010502030105080006
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
name="foomodule.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="foomodule.c"
#include <stdio.h>
#include <Python.h>
extern int var_for_foo;
static char foofun_doc[] = "Function fun in module foo";
static PyObject* foofun(PyObject* self, PyObject* args)
{
printf( "In foofun()\n" );
printf( "var_for_foo = %d\n", var_for_foo);
return NULL;
}
static PyMethodDef kModuleMethods[] = {
{"foofun", foofun, METH_VARARGS, foofun_doc},
{NULL, NULL } /* sentinel */
};
void initfoo()
{
PyObject* module;
module = Py_InitModule("foo", kModuleMethods);
printf( "var_for_foo = %d\n", var_for_foo);
return;
}
--------------000802010502030105080006
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
name="barmodule.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="barmodule.c"
#include <stdio.h>
#include <Python.h>
extern int var_for_bar;
static char barfun_doc[] = "Function fun in module bar";
static PyObject* barfun(PyObject* self, PyObject* args)
{
printf( "In barfun()\n" );
printf( "var_for_bar = %d\n", var_for_bar);
return NULL;
}
static PyMethodDef kModuleMethods[] = {
{"barfun", barfun, METH_VARARGS, barfun_doc},
{NULL, NULL } /* sentinel */
};
void initbar()
{
PyObject* module;
module = Py_InitModule("bar", kModuleMethods);
printf( "var_for_bar = %d\n", var_for_bar);
return;
}
--------------000802010502030105080006
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
name="baz.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="baz.c"
int var_for_foo = 1;
int var_for_bar = 6;
--------------000802010502030105080006--