1 /* This file must be kept in alphabetical order. See test_commontypes.py */
2
3 #define EQ(key, value) key "\0" value /* string concatenation */
4 #ifdef _WIN64
5 # define W32_64(X,Y) Y
6 # else
7 # define W32_64(X,Y) X
8 # endif
9
10
11 static const char *common_simple_types[] = {
12
13 #ifdef MS_WIN32 /* Windows types */
14 EQ("ATOM", "WORD"),
15 EQ("BOOL", "int"),
16 EQ("BOOLEAN", "BYTE"),
17 EQ("BYTE", "unsigned char"),
18 EQ("CCHAR", "char"),
19 EQ("CHAR", "char"),
20 EQ("COLORREF", "DWORD"),
21 EQ("DWORD", "unsigned long"),
22 EQ("DWORD32", "unsigned int"),
23 EQ("DWORD64", "unsigned long long"),
24 EQ("DWORDLONG", "ULONGLONG"),
25 EQ("DWORD_PTR", "ULONG_PTR"),
26 #endif
27
28 EQ("FILE", "struct _IO_FILE"),
29
30 #ifdef MS_WIN32 /* more Windows types */
31 EQ("FLOAT", "float"),
32 EQ("HACCEL", "HANDLE"),
33 EQ("HALF_PTR", W32_64("short","int")),
34 EQ("HANDLE", "PVOID"),
35 EQ("HBITMAP", "HANDLE"),
36 EQ("HBRUSH", "HANDLE"),
37 EQ("HCOLORSPACE", "HANDLE"),
38 EQ("HCONV", "HANDLE"),
39 EQ("HCONVLIST", "HANDLE"),
40 EQ("HCURSOR", "HICON"),
41 EQ("HDC", "HANDLE"),
42 EQ("HDDEDATA", "HANDLE"),
43 EQ("HDESK", "HANDLE"),
44 EQ("HDROP", "HANDLE"),
45 EQ("HDWP", "HANDLE"),
46 EQ("HENHMETAFILE", "HANDLE"),
47 EQ("HFILE", "int"),
48 EQ("HFONT", "HANDLE"),
49 EQ("HGDIOBJ", "HANDLE"),
50 EQ("HGLOBAL", "HANDLE"),
51 EQ("HHOOK", "HANDLE"),
52 EQ("HICON", "HANDLE"),
53 EQ("HINSTANCE", "HANDLE"),
54 EQ("HKEY", "HANDLE"),
55 EQ("HKL", "HANDLE"),
56 EQ("HLOCAL", "HANDLE"),
57 EQ("HMENU", "HANDLE"),
58 EQ("HMETAFILE", "HANDLE"),
59 EQ("HMODULE", "HINSTANCE"),
60 EQ("HMONITOR", "HANDLE"),
61 EQ("HPALETTE", "HANDLE"),
62 EQ("HPEN", "HANDLE"),
63 EQ("HRESULT", "LONG"),
64 EQ("HRGN", "HANDLE"),
65 EQ("HRSRC", "HANDLE"),
66 EQ("HSZ", "HANDLE"),
67 EQ("HWND", "HANDLE"),
68 EQ("INT", "int"),
69 EQ("INT16", "short"),
70 EQ("INT32", "int"),
71 EQ("INT64", "long long"),
72 EQ("INT8", "signed char"),
73 EQ("INT_PTR", W32_64("int","long long")),
74 EQ("LANGID", "WORD"),
75 EQ("LCID", "DWORD"),
76 EQ("LCTYPE", "DWORD"),
77 EQ("LGRPID", "DWORD"),
78 EQ("LONG", "long"),
79 EQ("LONG32", "int"),
80 EQ("LONG64", "long long"),
81 EQ("LONGLONG", "long long"),
82 EQ("LONG_PTR", W32_64("long","long long")),
83 EQ("LPARAM", "LONG_PTR"),
84 EQ("LPBOOL", "BOOL *"),
85 EQ("LPBYTE", "BYTE *"),
86 EQ("LPCOLORREF", "DWORD *"),
87 EQ("LPCSTR", "const char *"),
88 EQ("LPCVOID", "const void *"),
89 EQ("LPCWSTR", "const WCHAR *"),
90 EQ("LPDWORD", "DWORD *"),
91 EQ("LPHANDLE", "HANDLE *"),
92 EQ("LPINT", "int *"),
93 EQ("LPLONG", "long *"),
94 EQ("LPSTR", "CHAR *"),
95 EQ("LPVOID", "void *"),
96 EQ("LPWORD", "WORD *"),
97 EQ("LPWSTR", "WCHAR *"),
98 EQ("LRESULT", "LONG_PTR"),
99 EQ("PBOOL", "BOOL *"),
100 EQ("PBOOLEAN", "BOOLEAN *"),
101 EQ("PBYTE", "BYTE *"),
102 EQ("PCHAR", "CHAR *"),
103 EQ("PCSTR", "const CHAR *"),
104 EQ("PCWSTR", "const WCHAR *"),
105 EQ("PDWORD", "DWORD *"),
106 EQ("PDWORD32", "DWORD32 *"),
107 EQ("PDWORD64", "DWORD64 *"),
108 EQ("PDWORDLONG", "DWORDLONG *"),
109 EQ("PDWORD_PTR", "DWORD_PTR *"),
110 EQ("PFLOAT", "FLOAT *"),
111 EQ("PHALF_PTR", "HALF_PTR *"),
112 EQ("PHANDLE", "HANDLE *"),
113 EQ("PHKEY", "HKEY *"),
114 EQ("PINT", "int *"),
115 EQ("PINT16", "INT16 *"),
116 EQ("PINT32", "INT32 *"),
117 EQ("PINT64", "INT64 *"),
118 EQ("PINT8", "INT8 *"),
119 EQ("PINT_PTR", "INT_PTR *"),
120 EQ("PLCID", "PDWORD"),
121 EQ("PLONG", "LONG *"),
122 EQ("PLONG32", "LONG32 *"),
123 EQ("PLONG64", "LONG64 *"),
124 EQ("PLONGLONG", "LONGLONG *"),
125 EQ("PLONG_PTR", "LONG_PTR *"),
126 EQ("PSHORT", "SHORT *"),
127 EQ("PSIZE_T", "SIZE_T *"),
128 EQ("PSSIZE_T", "SSIZE_T *"),
129 EQ("PSTR", "CHAR *"),
130 EQ("PUCHAR", "UCHAR *"),
131 EQ("PUHALF_PTR", "UHALF_PTR *"),
132 EQ("PUINT", "UINT *"),
133 EQ("PUINT16", "UINT16 *"),
134 EQ("PUINT32", "UINT32 *"),
135 EQ("PUINT64", "UINT64 *"),
136 EQ("PUINT8", "UINT8 *"),
137 EQ("PUINT_PTR", "UINT_PTR *"),
138 EQ("PULONG", "ULONG *"),
139 EQ("PULONG32", "ULONG32 *"),
140 EQ("PULONG64", "ULONG64 *"),
141 EQ("PULONGLONG", "ULONGLONG *"),
142 EQ("PULONG_PTR", "ULONG_PTR *"),
143 EQ("PUSHORT", "USHORT *"),
144 EQ("PVOID", "void *"),
145 EQ("PWCHAR", "WCHAR *"),
146 EQ("PWORD", "WORD *"),
147 EQ("PWSTR", "WCHAR *"),
148 EQ("QWORD", "unsigned long long"),
149 EQ("SC_HANDLE", "HANDLE"),
150 EQ("SC_LOCK", "LPVOID"),
151 EQ("SERVICE_STATUS_HANDLE", "HANDLE"),
152 EQ("SHORT", "short"),
153 EQ("SIZE_T", "ULONG_PTR"),
154 EQ("SSIZE_T", "LONG_PTR"),
155 EQ("UCHAR", "unsigned char"),
156 EQ("UHALF_PTR", W32_64("unsigned short","unsigned int")),
157 EQ("UINT", "unsigned int"),
158 EQ("UINT16", "unsigned short"),
159 EQ("UINT32", "unsigned int"),
160 EQ("UINT64", "unsigned long long"),
161 EQ("UINT8", "unsigned char"),
162 EQ("UINT_PTR", W32_64("unsigned int","unsigned long long")),
163 EQ("ULONG", "unsigned long"),
164 EQ("ULONG32", "unsigned int"),
165 EQ("ULONG64", "unsigned long long"),
166 EQ("ULONGLONG", "unsigned long long"),
167 EQ("ULONG_PTR", W32_64("unsigned long","unsigned long long")),
168 EQ("USHORT", "unsigned short"),
169 EQ("USN", "LONGLONG"),
170 EQ("VOID", "void"),
171 EQ("WCHAR", "wchar_t"),
172 EQ("WINSTA", "HANDLE"),
173 EQ("WORD", "unsigned short"),
174 EQ("WPARAM", "UINT_PTR"),
175 #endif
176
177 EQ("bool", "_Bool"),
178 };
179
180
181 #undef EQ
182 #undef W32_64
183
184 #define num_common_simple_types \
185 (sizeof(common_simple_types) / sizeof(common_simple_types[0]))
186
187
get_common_type(const char * search,size_t search_len)188 static const char *get_common_type(const char *search, size_t search_len)
189 {
190 const char *entry;
191 int index = search_sorted(common_simple_types, sizeof(const char *),
192 num_common_simple_types, search, search_len);
193 if (index < 0)
194 return NULL;
195
196 entry = common_simple_types[index];
197 return entry + strlen(entry) + 1;
198 }
199
b__get_common_types(PyObject * self,PyObject * arg)200 static PyObject *b__get_common_types(PyObject *self, PyObject *arg)
201 {
202 int err;
203 size_t i;
204 for (i = 0; i < num_common_simple_types; i++) {
205 const char *s = common_simple_types[i];
206 PyObject *o = PyText_FromString(s + strlen(s) + 1);
207 if (o == NULL)
208 return NULL;
209 err = PyDict_SetItemString(arg, s, o);
210 Py_DECREF(o);
211 if (err < 0)
212 return NULL;
213 }
214 Py_INCREF(Py_None);
215 return Py_None;
216 }
217