Skip to content

Commit 7cab372

Browse files
committed
Remove old py2.x cruft from pywintypes.h
1 parent 7518670 commit 7cab372

File tree

1 file changed

+6
-82
lines changed

1 file changed

+6
-82
lines changed

win32/src/PyWinTypes.h

Lines changed: 6 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,6 @@
88
#undef _POSIX_C_SOURCE
99
#endif
1010

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-
2511
// windows rpc.h defines "small" as "char" which breaks Python's accu.h,
2612
// so we undefine it before including python.
2713
#ifdef small
@@ -46,29 +32,12 @@
4632
// Some macros to help the pywin32 modules co-exist in py2x and py3k.
4733
// Creates and initializes local variables called 'module' and 'dict'.
4834

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!)
6940

70-
#else
71-
// py3k module helpers.
7241
// Use to define the function itself (ie, its name, linkage, params)
7342
#define PYWIN_MODULE_INIT_FUNC(module_name) extern "C" __declspec(dllexport) PyObject *PyInit_##module_name(void)
7443

@@ -88,14 +57,8 @@
8857
return NULL; \
8958
if (!(dict = PyModule_GetDict(module))) \
9059
return NULL;
91-
#endif // PY_VERSION_HEX
9260

9361
// 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
9962
// Macro to handle PyObject layout changes in Py3k
10063
#define PYWIN_OBJECT_HEAD PyVarObject_HEAD_INIT(NULL, 0)
10164

@@ -128,25 +91,8 @@
12891
#define PyInt_AsSsize_t PyLong_AsSsize_t
12992
#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
13093
#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
14294

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
14895
typedef Py_ssize_t Py_hash_t;
149-
#endif
15096

15197
// This only enables runtime checks in debug builds - so we use
15298
// our own so we can enable it always should we desire...
@@ -155,13 +101,6 @@ typedef Py_ssize_t Py_hash_t;
155101
// Lars: for WAVEFORMATEX
156102
#include "mmsystem.h"
157103

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
165104
#ifdef BUILD_PYWINTYPES
166105
/* We are building pywintypesxx.dll */
167106
#define PYWINTYPES_EXPORT __declspec(dllexport)
@@ -176,13 +115,10 @@ typedef Py_ssize_t Py_hash_t;
176115
#endif // DEBUG/_DEBUG
177116
#endif // _MSC_VER
178117
#endif // BUILD_PYWINTYPES
179-
#endif // FREEZE_PYWINTYPES
180118

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.
183120
extern PYWINTYPES_EXPORT PyObject *PyBuffer_New(Py_ssize_t size);
184121
extern PYWINTYPES_EXPORT PyObject *PyBuffer_FromMemory(void *buf, Py_ssize_t size);
185-
#endif
186122

187123
// Formats a python traceback into a character string - result must be free()ed
188124
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
224160
// And free it when finished.
225161
PYWINTYPES_EXPORT void PyWinObject_FreeWCHAR(WCHAR *pResult);
226162

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
238163
inline BOOL PyWinObject_AsWCHAR(PyObject *stringObject, unsigned short **pResult, BOOL bNoneOK = FALSE,
239164
DWORD *pResultLen = NULL)
240165
{
241166
return PyWinObject_AsWCHAR(stringObject, (WCHAR **)pResult, bNoneOK, pResultLen);
242167
}
243168
inline void PyWinObject_FreeWCHAR(unsigned short *pResult) { PyWinObject_FreeWCHAR((WCHAR *)pResult); }
244-
#endif
245169

246170
// Given a PyObject (string, Unicode, etc) create a "char *" with the value
247171
// if pResultLen != NULL, it will be set to the result size NOT INCLUDING

0 commit comments

Comments
 (0)