| 1 |
|
| 2 |
#undef NDEBUG |
| 3 |
|
| 4 |
#include "Python.h" |
| 5 |
|
| 6 |
static PyObject * |
| 7 |
test_widechar(PyObject *self) |
| 8 |
{ |
| 9 |
const wchar_t invalid[1] = {(wchar_t)0x110000u}; |
| 10 |
PyObject *wide; |
| 11 |
|
| 12 |
wide = PyUnicode_FromUnicode(NULL, 1); |
| 13 |
if (wide == NULL) |
| 14 |
return NULL; |
| 15 |
_Py_COMP_DIAG_PUSH |
| 16 |
_Py_COMP_DIAG_IGNORE_DEPR_DECLS |
| 17 |
PyUnicode_AS_UNICODE(wide)[0] = invalid[0]; |
| 18 |
_Py_COMP_DIAG_POP |
| 19 |
if (_PyUnicode_Ready(wide) < 0) { |
| 20 |
return NULL; |
| 21 |
} |
| 22 |
return wide; |
| 23 |
} |
| 24 |
|
| 25 |
static PyObject * |
| 26 |
get_sizeof_wchar(PyObject *self) |
| 27 |
{ |
| 28 |
return PyLong_FromLong(sizeof(wchar_t)); |
| 29 |
} |
| 30 |
|
| 31 |
static PyMethodDef TestMethods[] = { |
| 32 |
{"test_widechar", (PyCFunction)test_widechar, METH_NOARGS}, |
| 33 |
{"get_sizeof_wchar", (PyCFunction)get_sizeof_wchar,METH_NOARGS}, |
| 34 |
{NULL, NULL} |
| 35 |
}; |
| 36 |
|
| 37 |
static struct PyModuleDef _testcapimodule = { |
| 38 |
PyModuleDef_HEAD_INIT, |
| 39 |
"_widechar", |
| 40 |
NULL, |
| 41 |
-1, |
| 42 |
NULL, |
| 43 |
}; |
| 44 |
|
| 45 |
PyMODINIT_FUNC |
| 46 |
PyInit__widechar(void) |
| 47 |
{ |
| 48 |
PyObject *m; |
| 49 |
m = PyModule_Create(&_testcapimodule); |
| 50 |
if (m == NULL) |
| 51 |
return NULL; |
| 52 |
PyModule_AddFunctions(m, TestMethods); |
| 53 |
return m; |
| 54 |
} |