[Pyrex] Pyrex and MSVC

Matthias Baas baas at ira.uka.de
Fri Sep 5 11:00:03 CEST 2003


At 14:15 04.09.2003 +1200, Greg Ewing wrote:
> > staticforward char *__pyx_f[];
>
>It seems that staticforward is incorrectly defined in the
>Python 2.3 version of Python.h.

I'm afraid the Python authors don't regard it as being *incorrectly* 
defined (at least they changed it on purpose, even though I don't know why 
they didn't just leave it as it was in Python 2.2).
My understanding is that the "staticforward" macro shouldn't be used 
anymore in new extensions. Here's what they wrote in the header file 
<python2.3>/include/object.h:

/*
Define staticforward and statichere for source compatibility with old
C extensions.

The staticforward define was needed to support certain broken C
compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the
static keyword when it was used with a forward declaration of a static
initialized structure.  Standard C allows the forward declaration with
static, and we've decided to stop catering to broken C compilers.
(In fact, we expect that the compilers are all fixed eight years later.)
*/
#define staticforward static
#define statichere static

In Python 2.2.2 it looked like this:

/*
A common programming style in Python requires the forward declaration
of static, initialized structures, e.g. for a type object that is used
by the functions whose address must be used in the initializer.
Some compilers (notably SCO ODT 3.0, I seem to remember early AIX as
well) botch this if you use the static keyword for both declarations
(they allocate two objects, and use the first, uninitialized one until
the second declaration is encountered).  Therefore, the forward
declaration should use the 'forwardstatic' keyword.  This expands to
static on most systems, but to extern on a few.  The actual storage
and name will still be static because the second declaration is
static, so no linker visible symbols will be generated.  (Standard C
compilers take offense to the extern forward declaration of a static
object, so I can't just put extern in all cases. :-( )
*/

#ifdef BAD_STATIC_FORWARD
#define staticforward extern
#define statichere static
#else /* !BAD_STATIC_FORWARD */
#define staticforward static
#define statichere static
#endif /* !BAD_STATIC_FORWARD */


But frankly, I'm a bit confused with this issue and currently I don't know 
what would be the correct way how the Pyrex generated code should look like 
(so that it works on all platforms and with Python 2.2 and Python 2.3)......

- Matthias -





More information about the Pyrex mailing list