[Patches] Extension building on Win32 using Gnu C

Rene Liebscher R.Liebscher@gmx.de
Mon, 19 Jun 2000 12:40:54 +0200


Good news, I tried last weekend an up-to-date version of gcc (2.95.2)
and it works now without these struct-imports.

I used before an older version (2.91.57) which I got from
ftp://go.cygnus.com/pub/sourceware.cygnus.com/cygwin/latest/
but this is quite old (Dec 1998). (Some months ago this site 
was mentioned on cygnus website as the directory
containing the latest release of cygwin.)

So,it was a bug in the compiler. 

I found in its mailing list a bug report concerning this bug.
http://sourceware.cygnus.com/ml/cygwin/1999-02/msg00484.html

Using an up-to-date compiler we don't have these problems anymore.
I think we should warn the user if he is using such a older,buggy
compiler. In config.h's GNUC section we could insert something
like that:

#if (__GNUC__==2) && (__GNUC_MINOR__<=91)
#warning "Please use an up-to-date version of gcc"
#endif

(All what you need to make python gnu-c compatible is this section
in its config.h file. The rest was a "bug workaround".)


kind regards

Rene Liebscher



PS:
++++++++++++++++++++++++++

For those of you who are still interested what the 
problem was, here the complete description.

* C mode

Using of ob_type member of struct _typeobject gives you an warning :

Most type checks are macros !

( arg is of type PyObject* )

PyCObject_Check(arg)
 ==> warning: comparison of distinct pointer types lacks a cast
not only for this, also for
PyTuple_Check(arg)
...
but not for
PyCallable_Check(arg) this is realized as external funtion, not as macro

Also if you initialize you own types. 
/* module initialization */
void initfoo(){

  Foo_Type.ob_type = &PyType_Type; /* this is a workaround for MSVC and
other Windows compilers */
      ==> warning: assignment from incompatible pointer type
...
}
These two can be avoided by importing struct _typeobject.  


Another warning you get if you use dll-imported data in return
statements:

PyObject* f(...)
{
  ...

  Py_INCREF(Py_None);
  return Py_None;
 ==> warning: return from incompatible pointer type
}

If you import PyObject this warning also disappears.

* C++ mode

Compiler crashs:

[main]
C:\CYGNUS\CYGWIN-B20\H-I586-CYGWIN32\LIB\GCC-LIB\I586-CYGWIN32\EGCS-2.91.57\CC1PLUS.EXE
1006 (0) handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
[main] CC1PLUS 1006 (0) handle_exceptions: Dumping stack trace to
CC1PLUS.EXE.core

content of CC1PLUS.EXE.core:
[main] CC1PLUS 1006 (0) exception: trapped!
[main] CC1PLUS 1006 (0) exception: code 0xC0000005 at 0x43929C
[main] CC1PLUS 1006 (0) exception: ax 0x0 bx 0x0 cx 0x270F1BC dx 0x48
[main] CC1PLUS 1006 (0) exception: si 0x270F1BC di 0x2792238 bp
0x270F12C sp 0x270F124
[main] CC1PLUS 1006 (0) exception: exception is: STATUS_ACCESS_VIOLATION
[main] CC1PLUS 1006 (0) stack: Stack trace:
[main] CC1PLUS 1006 (0) stack: frame 0: sp = 0x270EF20, pc = 0x6100A2C3
...
[main] CC1PLUS 1006 (0) stack: frame 15: sp = 0x270FB68, pc = 0x48FB85
[main] CC1PLUS 1006 (0) stack: End of stack trace (more stack frames may
be present)

+++++++++++++++++++++++++++++++++