.gitignore added
[dotfiles/.git] / .local / include / python3.9 / pygame / pgcompat.h
1 /* Python 2.x/3.x compatibility tools (internal)
2  */
3 #ifndef PGCOMPAT_INTERNAL_H
4 #define PGCOMPAT_INTERNAL_H
5
6 #include "include/pgcompat.h"
7
8 #if PY_MAJOR_VERSION >= 3
9
10 #define PY3 1
11
12 /* Define some aliases for the removed PyInt_* functions */
13 #define PyInt_Check(op) PyLong_Check(op)
14 #define PyInt_FromString PyLong_FromString
15 #define PyInt_FromLong PyLong_FromLong
16 #define PyInt_FromSize_t PyLong_FromSize_t
17 #define PyInt_FromSsize_t PyLong_FromSsize_t
18 #define PyInt_AsLong PyLong_AsLong
19 #define PyInt_AsSsize_t PyLong_AsSsize_t
20 #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
21 #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
22 #define PyInt_AS_LONG PyLong_AS_LONG
23 #define PyNumber_Int PyNumber_Long
24 /* Int and Long are identical in Py3 so only check one */
25 #define INT_CHECK(op) PyLong_Check(op)
26
27 /* Weakrefs flags changed in 3.x */
28 #define Py_TPFLAGS_HAVE_WEAKREFS 0
29
30 /* Module init function returns new module instance. */
31 #define MODINIT_RETURN(x) return x
32 #define MODINIT_DEFINE(mod_name) PyMODINIT_FUNC PyInit_##mod_name (void)
33 #define DECREF_MOD(mod) Py_DECREF (mod)
34
35 /* Text interface. Use unicode strings. */
36 #define Text_Type PyUnicode_Type
37 #define Text_Check PyUnicode_Check
38
39 #ifndef PYPY_VERSION
40 #define Text_FromLocale(s) PyUnicode_DecodeLocale((s), "strict")
41 #else /* PYPY_VERSION */
42 /* workaround: missing function for pypy */
43 #define Text_FromLocale PyUnicode_FromString
44 #endif /* PYPY_VERSION */
45
46 #define Text_FromUTF8 PyUnicode_FromString
47 #define Text_FromUTF8AndSize PyUnicode_FromStringAndSize
48 #define Text_FromFormat PyUnicode_FromFormat
49 #define Text_GetSize PyUnicode_GetSize
50 #define Text_GET_SIZE PyUnicode_GET_SIZE
51
52 /* Binary interface. Use bytes. */
53 #define Bytes_Type PyBytes_Type
54 #define Bytes_Check PyBytes_Check
55 #define Bytes_Size PyBytes_Size
56 #define Bytes_AsString PyBytes_AsString
57 #define Bytes_AsStringAndSize PyBytes_AsStringAndSize
58 #define Bytes_FromStringAndSize PyBytes_FromStringAndSize
59 #define Bytes_FromFormat PyBytes_FromFormat
60 #define Bytes_AS_STRING PyBytes_AS_STRING
61 #define Bytes_GET_SIZE PyBytes_GET_SIZE
62 #define Bytes_AsDecodeObject PyBytes_AsDecodedObject
63
64 #define Object_Unicode PyObject_Str
65
66 #define IsTextObj(x) (PyUnicode_Check(x) || PyBytes_Check(x))
67
68 /* Renamed builtins */
69 #define BUILTINS_MODULE "builtins"
70 #define BUILTINS_UNICODE "str"
71 #define BUILTINS_UNICHR "chr"
72
73 /* Defaults for unicode file path encoding */
74 #define UNICODE_DEF_FS_CODEC Py_FileSystemDefaultEncoding
75 #if defined(MS_WIN32)
76 #define UNICODE_DEF_FS_ERROR "replace"
77 #else
78 #define UNICODE_DEF_FS_ERROR "surrogateescape"
79 #endif
80
81 #else /* #if PY_MAJOR_VERSION >= 3 */
82
83 #define PY3 0
84
85 /* Check both Int and Long in PY2 */
86 #define INT_CHECK(op) (PyInt_Check(op) || PyLong_Check(op))
87
88 /* Module init function returns nothing. */
89 #define MODINIT_RETURN(x) return
90 #define MODINIT_DEFINE(mod_name) PyMODINIT_FUNC init##mod_name (void)
91 #define DECREF_MOD(mod)
92
93 /* Text interface. Use ascii strings. */
94 #define Text_Type PyString_Type
95 #define Text_Check PyString_Check
96 #define Text_FromLocale PyString_FromString
97 #define Text_FromUTF8 PyString_FromString
98 #define Text_FromUTF8AndSize PyString_FromStringAndSize
99 #define Text_FromFormat PyString_FromFormat
100 #define Text_GetSize PyString_GetSize
101 #define Text_GET_SIZE PyString_GET_SIZE
102
103 /* Binary interface. Use ascii strings. */
104 #define Bytes_Type PyString_Type
105 #define Bytes_Check PyString_Check
106 #define Bytes_Size PyString_Size
107 #define Bytes_AsString PyString_AsString
108 #define Bytes_AsStringAndSize PyString_AsStringAndSize
109 #define Bytes_FromStringAndSize PyString_FromStringAndSize
110 #define Bytes_FromFormat PyString_FromFormat
111 #define Bytes_AS_STRING PyString_AS_STRING
112 #define Bytes_GET_SIZE PyString_GET_SIZE
113 #define Bytes_AsDecodedObject PyString_AsDecodedObject
114
115 #define Object_Unicode PyObject_Unicode
116
117 /* Renamed builtins */
118 #define BUILTINS_MODULE "__builtin__"
119 #define BUILTINS_UNICODE "unicode"
120 #define BUILTINS_UNICHR "unichr"
121
122 /* Defaults for unicode file path encoding */
123 #define UNICODE_DEF_FS_CODEC Py_FileSystemDefaultEncoding
124 #define UNICODE_DEF_FS_ERROR "strict"
125
126 #endif /* #if PY_MAJOR_VERSION >= 3 */
127
128 #define PY2 (!PY3)
129
130 #define MODINIT_ERROR MODINIT_RETURN (NULL)
131
132 /* Module state. These macros are used to define per-module macros.
133  * v - global state variable (Python 2.x)
134  * s - global state structure (Python 3.x)
135  */
136 #define PY2_GETSTATE(v) (&(v))
137 #define PY3_GETSTATE(s, m) ((struct s *) PyModule_GetState (m))
138
139 /* Pep 3123: Making PyObject_HEAD conform to standard C */
140 #if !defined(Py_TYPE)
141 #define Py_TYPE(o)    (((PyObject *)(o))->ob_type)
142 #define Py_REFCNT(o)  (((PyObject *)(o))->ob_refcnt)
143 #define Py_SIZE(o)    (((PyVarObject *)(o))->ob_size)
144 #endif
145
146 /* Encode a unicode file path */
147 #define Unicode_AsEncodedPath(u) \
148     PyUnicode_AsEncodedString ((u), UNICODE_DEF_FS_CODEC, UNICODE_DEF_FS_ERROR)
149
150 #define RELATIVE_MODULE(m) ("." m)
151
152 #define HAVE_OLD_BUFPROTO PY2
153
154 #if !defined(PG_ENABLE_OLDBUF)  /* allow for command line override */
155 #if HAVE_OLD_BUFPROTO
156 #define PG_ENABLE_OLDBUF 1
157 #else
158 #define PG_ENABLE_OLDBUF 0
159 #endif
160 #endif
161
162 #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
163 #define Py_TPFLAGS_HAVE_NEWBUFFER 0
164 #endif
165
166 #ifndef Py_TPFLAGS_HAVE_CLASS
167 #define Py_TPFLAGS_HAVE_CLASS 0
168 #endif
169
170 #ifndef Py_TPFLAGS_CHECKTYPES
171 #define Py_TPFLAGS_CHECKTYPES 0
172 #endif
173
174 #if PY_VERSION_HEX >= 0x03020000
175 #define Slice_GET_INDICES_EX(slice, length, start, stop, step, slicelength) \
176     PySlice_GetIndicesEx(slice, length, start, stop, step, slicelength)
177 #else
178 #define Slice_GET_INDICES_EX(slice, length, start, stop, step, slicelength) \
179     PySlice_GetIndicesEx((PySliceObject *)(slice), length, \
180                          start, stop, step, slicelength)
181 #endif
182
183 #if defined(SDL_VERSION_ATLEAST)
184 #if (SDL_VERSION_ATLEAST(2, 0, 0)) && !(SDL_VERSION_ATLEAST(2, 0, 5))
185 /* These functions require SDL 2.0.5 or greater.
186
187   https://wiki.libsdl.org/SDL_SetWindowResizable
188 */
189 void SDL_SetWindowResizable(SDL_Window *window, SDL_bool resizable);
190 int SDL_GetWindowOpacity(SDL_Window *window, float *opacity);
191 int SDL_SetWindowOpacity(SDL_Window *window, float opacity);
192 int SDL_SetWindowModalFor(SDL_Window *modal_window, SDL_Window *parent_window);
193 int SDL_SetWindowInputFocus(SDL_Window *window);
194 SDL_Surface * SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,
195                                Uint32 format);
196 #endif
197 #endif /* defined(SDL_VERSION_ATLEAST) */
198
199 // Currently needed to build scrap.c, event.c, display.c
200 // with Windows SDK 10.0.18362.0 and SDL1 build
201 #ifdef _MSC_VER
202     #ifndef WINDOWS_IGNORE_PACKING_MISMATCH
203         #define WINDOWS_IGNORE_PACKING_MISMATCH
204     #endif
205 #endif
206
207 #endif /* ~PGCOMPAT_INTERNAL_H */