1
- # Copyright (c) 2018, 2019 , Oracle and/or its affiliates. All rights reserved.
1
+ # Copyright (c) 2018, 2020 , Oracle and/or its affiliates. All rights reserved.
2
2
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3
3
#
4
4
# The Universal Permissive License (UPL), Version 1.0
@@ -493,10 +493,7 @@ def compile_module(self, name):
493
493
(2 , bytearray ([0x30 , 0x20 , 0x3C , 0x20 ]), 2 , "‰‼" ),
494
494
),
495
495
code = '''PyObject* wrap_PyUnicode_FromKindAndData(int kind, Py_buffer buffer, Py_ssize_t size, PyObject* dummy) {
496
- PyObject* res;
497
- res = PyUnicode_FromKindAndData(kind, (const char *)buffer.buf, size);
498
- Py_XINCREF(res);
499
- return res;
496
+ return PyUnicode_FromKindAndData(kind, (const char *)buffer.buf, size);
500
497
}
501
498
''' ,
502
499
resultspec = "O" ,
@@ -523,3 +520,28 @@ def compile_module(self, name):
523
520
cmpfunc = unhandled_error_compare
524
521
)
525
522
523
+
524
+ # NOTE: this test assumes that Python uses UTF-8 encoding for source files
525
+ test_PyUnicode_FromWideChar = CPyExtFunction (
526
+ lambda args : args [3 ],
527
+ lambda : (
528
+ (4 , bytearray ([0xA2 , 0x0E , 0x02 , 0x00 ]), 1 , "𠺢" ),
529
+ (4 , bytearray ([0xA2 , 0x0E , 0x02 , 0x00 , 0x4C , 0x0F , 0x02 , 0x00 ]), 2 , "𠺢𠽌" ),
530
+ (2 , bytearray ([0x30 , 0x20 ]), 1 , "‰" ),
531
+ (2 , bytearray ([0x30 , 0x20 , 0x3C , 0x20 ]), 2 , "‰‼" ),
532
+ ),
533
+ code = '''PyObject* wrap_PyUnicode_FromWideChar(int expectedWcharSize, Py_buffer buffer, Py_ssize_t size, PyObject* dummy) {
534
+ if (SIZEOF_WCHAR_T == expectedWcharSize) {
535
+ return PyUnicode_FromWideChar((const wchar_t *) buffer.buf, size);
536
+ }
537
+ return dummy;
538
+ }
539
+ ''' ,
540
+ resultspec = "O" ,
541
+ argspec = 'iy*nO' ,
542
+ arguments = ["int expectedWcharSize" , "Py_buffer buffer" , "Py_ssize_t size" , "PyObject* dummy" ],
543
+ callfunction = "wrap_PyUnicode_FromWideChar" ,
544
+ cmpfunc = unhandled_error_compare
545
+ )
546
+
547
+
0 commit comments