@@ -1385,6 +1385,58 @@ test_widechar(PyObject *self)
13851385 Py_RETURN_NONE ;
13861386}
13871387
1388+ static PyObject *
1389+ test_aswidechar (PyObject * self , PyObject * args )
1390+ {
1391+ PyObject * unicode , * result ;
1392+ Py_ssize_t buflen , size ;
1393+ wchar_t * buffer ;
1394+
1395+ if (!PyArg_ParseTuple (args , "Un" , & unicode , & buflen ))
1396+ return NULL ;
1397+ buffer = PyMem_Malloc (buflen * sizeof (wchar_t ));
1398+ if (buffer == NULL )
1399+ return PyErr_NoMemory ();
1400+
1401+ size = PyUnicode_AsWideChar ((PyUnicodeObject * )unicode , buffer , buflen );
1402+ if (size == -1 ) {
1403+ PyMem_Free (buffer );
1404+ return NULL ;
1405+ }
1406+
1407+ if (size < buflen )
1408+ buflen = size + 1 ;
1409+ else
1410+ buflen = size ;
1411+ result = PyUnicode_FromWideChar (buffer , buflen );
1412+ PyMem_Free (buffer );
1413+ if (result == NULL )
1414+ return NULL ;
1415+
1416+ return Py_BuildValue ("(Nn)" , result , size );
1417+ }
1418+
1419+ static PyObject *
1420+ test_aswidecharstring (PyObject * self , PyObject * args )
1421+ {
1422+ PyObject * unicode , * result ;
1423+ Py_ssize_t size ;
1424+ wchar_t * buffer ;
1425+
1426+ if (!PyArg_ParseTuple (args , "U" , & unicode ))
1427+ return NULL ;
1428+
1429+ buffer = PyUnicode_AsWideCharString ((PyUnicodeObject * )unicode , & size );
1430+ if (buffer == NULL )
1431+ return NULL ;
1432+
1433+ result = PyUnicode_FromWideChar (buffer , size + 1 );
1434+ PyMem_Free (buffer );
1435+ if (result == NULL )
1436+ return NULL ;
1437+ return Py_BuildValue ("(Nn)" , result , size );
1438+ }
1439+
13881440static PyObject *
13891441getargs_w_star (PyObject * self , PyObject * args )
13901442{
@@ -2262,28 +2314,30 @@ static PyMethodDef TestMethods[] = {
22622314 {"getargs_Z_hash" , getargs_Z_hash , METH_VARARGS },
22632315 {"getargs_w_star" , getargs_w_star , METH_VARARGS },
22642316 {"codec_incrementalencoder" ,
2265- (PyCFunction )codec_incrementalencoder , METH_VARARGS },
2317+ (PyCFunction )codec_incrementalencoder , METH_VARARGS },
22662318 {"codec_incrementaldecoder" ,
2267- (PyCFunction )codec_incrementaldecoder , METH_VARARGS },
2319+ (PyCFunction )codec_incrementaldecoder , METH_VARARGS },
22682320 {"test_s_code" , (PyCFunction )test_s_code , METH_NOARGS },
22692321 {"test_u_code" , (PyCFunction )test_u_code , METH_NOARGS },
22702322 {"test_Z_code" , (PyCFunction )test_Z_code , METH_NOARGS },
22712323 {"test_widechar" , (PyCFunction )test_widechar , METH_NOARGS },
2324+ {"test_aswidechar" , test_aswidechar , METH_VARARGS },
2325+ {"test_aswidecharstring" , test_aswidecharstring , METH_VARARGS },
22722326#ifdef WITH_THREAD
2273- {"_test_thread_state" , test_thread_state , METH_VARARGS },
2327+ {"_test_thread_state" , test_thread_state , METH_VARARGS },
22742328 {"_pending_threadfunc" , pending_threadfunc , METH_VARARGS },
22752329#endif
22762330#ifdef HAVE_GETTIMEOFDAY
2277- {"profile_int" , profile_int , METH_NOARGS },
2331+ {"profile_int" , profile_int , METH_NOARGS },
22782332#endif
2279- {"traceback_print" , traceback_print , METH_VARARGS },
2280- {"exception_print" , exception_print , METH_VARARGS },
2281- {"argparsing" , argparsing , METH_VARARGS },
2282- {"code_newempty" , code_newempty , METH_VARARGS },
2333+ {"traceback_print" , traceback_print , METH_VARARGS },
2334+ {"exception_print" , exception_print , METH_VARARGS },
2335+ {"argparsing" , argparsing , METH_VARARGS },
2336+ {"code_newempty" , code_newempty , METH_VARARGS },
22832337 {"make_exception_with_doc" , (PyCFunction )make_exception_with_doc ,
22842338 METH_VARARGS | METH_KEYWORDS },
22852339 {"crash_no_current_thread" , (PyCFunction )crash_no_current_thread , METH_NOARGS },
2286- {"format_unicode" , format_unicode , METH_VARARGS },
2340+ {"format_unicode" , format_unicode , METH_VARARGS },
22872341 {NULL , NULL } /* sentinel */
22882342};
22892343
0 commit comments