[Pyrex] [PATCH] pyrex module and Win32 API problem
Alexander Belchenko
bialix at ukr.net
Thu Jul 17 21:09:08 CEST 2008
Today I found small problem with Pyrex (0.9.6.4 and 0.9.8.4) when I'm trying
to build new pyrex extension in codebase of Bazaar VCS. After some experiments
with compiling of auto-generated C-file with custom setup.py that does not call
Pyrex, I discover that problem lies in next "standard" code that Pyrex emits
in each file:
#ifndef WIN32
#ifndef __stdcall
#define __stdcall
#endif
#ifndef __cdecl
#define __cdecl
#endif
#endif
My problem is caused by first check: #ifndef WIN32.
My compiler (MSVC .NET 2003) does not set WIN32 symbol (actually it sets _WIN32 symbol).
Pyrex is also don't trying manipulate with this define when running on Windows.
Standard distutils' build_ext is also does not set such define.
I found only one mention of such constant in standard Python's header called pyconfig.h
that always included at the top of Python.h itself.
pyconfig.h claims following:
(see http://svn.python.org/view/python/trunk/PC/pyconfig.h?rev=64214&view=markup)
WINDOWS DEFINES:
The code specific to Windows should be wrapped around one of
the following #defines
MS_WIN64 - Code specific to the MS Win64 API
MS_WIN32 - Code specific to the MS Win32 (and Win64) API (obsolete, this covers all
supported APIs)
MS_WINDOWS - Code specific to Windows, but all versions.
MS_WINCE - Code specific to Windows CE
And further comment explicitly called WIN32 symbol as deprecated:
NOTE: The following symbols are deprecated:
NT, WIN32, USE_DL_EXPORT, USE_DL_IMPORT, DL_EXPORT, DL_IMPORT
MS_CORE_DLL.
So IMO Pyrex generate code that not fully compatible with Python 2.4/2.5.
It should be #ifndef MS_WINDOWS.
I don't know on which Python version WIN32 symbol was deprecated, and I'm not sure
what minimum version of Python supported by Pyrex, so I propose next small patch
that fixes my problem:
=== modified file 'Pyrex/Compiler/ModuleNode.py'
--- old/Pyrex/Compiler/ModuleNode.py
+++ new/Pyrex/Compiler/ModuleNode.py
@@ -312,7 +312,7 @@
code.putln(" #define PyInt_FromSsize_t(z) PyInt_FromLong(z)")
code.putln(" #define PyInt_AsSsize_t(o) PyInt_AsLong(o)")
code.putln("#endif")
- code.putln("#ifndef WIN32")
+ code.putln("#if !defined(WIN32) && !defined(MS_WINDOWS)")
code.putln(" #ifndef __stdcall")
code.putln(" #define __stdcall")
code.putln(" #endif")
Alexander
More information about the Pyrex
mailing list