8
8
#undef _POSIX_C_SOURCE
9
9
#endif
10
10
11
- // early msvc versions complain about pragma #s it doesn't understand
12
- // C:\mssdk\VC\INCLUDE\string.h(142) : warning C4616: #pragma warning : warning number '6059' out of range, must be
13
- // between '4001' and '4999' and: C:\mssdk\include\wingdi.h(4340) : warning C4068: unknown pragma I doubt we ever care
14
- // about that warning, so unconditionally nuke em!
15
- #pragma warning(disable : 4616 4068)
16
- // Python.h and Windows.h both protect themselves from multiple
17
- // includes - so it is safe to do here (and provides a handy
18
- // choke point for #include vagaries
19
-
20
- // Some other warnings generated by MSVC6 which we don't care about
21
- #if (PY_VERSION_HEX < 0x02060000)
22
- #pragma warning(disable : 4035)
23
- #endif
24
-
25
11
// windows rpc.h defines "small" as "char" which breaks Python's accu.h,
26
12
// so we undefine it before including python.
27
13
#ifdef small
46
32
// Some macros to help the pywin32 modules co-exist in py2x and py3k.
47
33
// Creates and initializes local variables called 'module' and 'dict'.
48
34
49
- #if (PY_VERSION_HEX < 0x03000000)
50
-
51
- // Use to define the function itself (ie, its name, linkage, params)
52
- #define PYWIN_MODULE_INIT_FUNC (module_name ) extern " C" __declspec(dllexport) void init##module_name(void )
53
-
54
- // If the module needs to early-exit on an error condition.
55
- #define PYWIN_MODULE_INIT_RETURN_ERROR return ;
56
-
57
- // When the module has successfully initialized.
58
- #define PYWIN_MODULE_INIT_RETURN_SUCCESS return ;
59
-
60
- // To setup the module object itself and the module's dictionary.
61
- #define PYWIN_MODULE_INIT_PREPARE (module_name, functions, docstring ) \
62
- PyObject *dict, *module ; \
63
- if (PyWinGlobals_Ensure() == -1 ) \
64
- return ; \
65
- if (!(module = Py_InitModule(#module_name, functions))) \
66
- return ; \
67
- if (!(dict = PyModule_GetDict(module ))) \
68
- return ;
35
+ // Maybe these should all be removed - they existed to help in the py2->3
36
+ // transition.
37
+ // On one hand: the code would be cleaner if they were all just re-inlined?
38
+ // On the other: high confidence everything uses the exact same patterns?
39
+ // (Regardless, *some*, eg, PYWIN_MODULE_INIT_RETURN_* should be re-inlined!)
69
40
70
- #else
71
- // py3k module helpers.
72
41
// Use to define the function itself (ie, its name, linkage, params)
73
42
#define PYWIN_MODULE_INIT_FUNC (module_name ) extern " C" __declspec(dllexport) PyObject *PyInit_##module_name(void )
74
43
88
57
return NULL ; \
89
58
if (!(dict = PyModule_GetDict(module ))) \
90
59
return NULL ;
91
- #endif // PY_VERSION_HEX
92
60
93
61
// Helpers for our types.
94
- #if (PY_VERSION_HEX < 0x03000000)
95
- #define PYWIN_OBJECT_HEAD PyObject_HEAD_INIT (&PyType_Type) 0,
96
- #define PYWIN_ATTR_CONVERT PyString_AsString
97
-
98
- #else // Py3k definitions
99
62
// Macro to handle PyObject layout changes in Py3k
100
63
#define PYWIN_OBJECT_HEAD PyVarObject_HEAD_INIT (NULL , 0 )
101
64
128
91
#define PyInt_AsSsize_t PyLong_AsSsize_t
129
92
#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
130
93
#define PyNumber_Int PyNumber_Long
131
- #endif // (PY_VERSION_HEX < 0x03000000)
132
-
133
- // See PEP-353 - this is the "official" test...
134
- #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
135
- // 2.3 and before have no Py_ssize_t
136
- typedef int Py_ssize_t;
137
- #define PyInt_FromSsize_t PyInt_FromLong
138
- #define PyInt_AsSsize_t PyInt_AsLong
139
- #define PY_SSIZE_T_MAX INT_MAX
140
- #define PY_SSIZE_T_MIN INT_MIN
141
- #endif
142
94
143
- // Py_hash_t was introduced as the size of a pointer in python 3.2 - it
144
- // was a simple long before that.
145
- #if PY_VERSION_HEX < 0x03020000
146
- typedef long Py_hash_t;
147
- #else
148
95
typedef Py_ssize_t Py_hash_t;
149
- #endif
150
96
151
97
// This only enables runtime checks in debug builds - so we use
152
98
// our own so we can enable it always should we desire...
@@ -155,13 +101,6 @@ typedef Py_ssize_t Py_hash_t;
155
101
// Lars: for WAVEFORMATEX
156
102
#include " mmsystem.h"
157
103
158
- // *** NOTE *** FREEZE_PYWINTYPES is deprecated. It used to be used
159
- // by the 'freeze' tool, but now py2exe etc do a far better job, and
160
- // don't require a custom built pywintypes DLL.
161
- #ifdef FREEZE_PYWINTYPES
162
- /* The pywintypes module is being included in a frozen .EXE/.DLL */
163
- #define PYWINTYPES_EXPORT
164
- #else
165
104
#ifdef BUILD_PYWINTYPES
166
105
/* We are building pywintypesxx.dll */
167
106
#define PYWINTYPES_EXPORT __declspec (dllexport)
@@ -176,13 +115,10 @@ typedef Py_ssize_t Py_hash_t;
176
115
#endif // DEBUG/_DEBUG
177
116
#endif // _MSC_VER
178
117
#endif // BUILD_PYWINTYPES
179
- #endif // FREEZE_PYWINTYPES
180
118
181
- #if (PY_VERSION_HEX >= 0x03000000)
182
- // Py3k uses memoryview object in place of buffer
119
+ // Py3k uses memoryview object in place of buffer, and we don't yet.
183
120
extern PYWINTYPES_EXPORT PyObject *PyBuffer_New (Py_ssize_t size);
184
121
extern PYWINTYPES_EXPORT PyObject *PyBuffer_FromMemory (void *buf, Py_ssize_t size);
185
- #endif
186
122
187
123
// Formats a python traceback into a character string - result must be free()ed
188
124
PYWINTYPES_EXPORT char *GetPythonTraceback (PyObject *exc_type, PyObject *exc_value, PyObject *exc_tb);
@@ -224,24 +160,12 @@ PYWINTYPES_EXPORT BOOL PyWinObject_AsWCHAR(PyObject *stringObject, WCHAR **pResu
224
160
// And free it when finished.
225
161
PYWINTYPES_EXPORT void PyWinObject_FreeWCHAR (WCHAR *pResult);
226
162
227
- // As of Python 2.6, Python switched to 'wchar_t' for unicode, so old
228
- // win32 structures that still use 'unsigned short' now fail from C++ with
229
- // VS8 so we provide a couple of helpers.
230
- // XXX - but, when trying to use VC2003 with x64, the SDK x64 compiler
231
- // reports itself as 14.00.40310.41 - so this breaks under that compiler
232
- // Its not clear how to resolve this, but while VS2003 is the default
233
- // compiler, that is what must work.
234
- // py2.5 on x64 also needs it, and that is min x64 we support
235
- // The main difference seems to be whether the compiler has /Zc:wchar_t (Treat wchar_t as a builtin type)
236
- // on by default, and according to MSDN, _NATIVE_WCHAR_T_DEFINED is the way to check for it
237
- #ifdef _NATIVE_WCHAR_T_DEFINED
238
163
inline BOOL PyWinObject_AsWCHAR (PyObject *stringObject, unsigned short **pResult, BOOL bNoneOK = FALSE ,
239
164
DWORD *pResultLen = NULL )
240
165
{
241
166
return PyWinObject_AsWCHAR (stringObject, (WCHAR **)pResult, bNoneOK, pResultLen);
242
167
}
243
168
inline void PyWinObject_FreeWCHAR (unsigned short *pResult) { PyWinObject_FreeWCHAR ((WCHAR *)pResult); }
244
- #endif
245
169
246
170
// Given a PyObject (string, Unicode, etc) create a "char *" with the value
247
171
// if pResultLen != NULL, it will be set to the result size NOT INCLUDING
0 commit comments