@@ -330,69 +330,42 @@ static int augment_ListCheck(HPyContext ctx, HPy obj) {
330
330
}
331
331
}
332
332
333
+ #define MAX_UNICODE 0x10ffff
333
334
334
335
static HPy augment_UnicodeFromWideChar (HPyContext ctx , const wchar_t * u , HPy_ssize_t size ) {
335
336
if (u == NULL && size != 0 ) {
336
337
return HPy_NULL ;
337
338
}
338
339
340
+ if (sizeof (wchar_t ) != sizeof (uint32_t )) {
341
+ HPyErr_SetString (ctx , ctx -> h_SystemError , "unsupported size of type wchar_t" );
342
+ return HPy_NULL ;
343
+ }
344
+
339
345
if (size == -1 ) {
340
346
size = wcslen (u );
341
347
}
342
348
343
349
if (size > INT32_MAX ) {
344
- /* TODO(fa): error message */
350
+ HPyErr_SetString ( ctx , ctx -> h_SystemError , "wchar_t array is too large" );
345
351
return HPy_NULL ;
346
352
}
347
353
348
- /* If the Unicode data is known at construction time, we can apply
349
- some optimizations which share commonly used objects. */
350
-
351
- /* Optimization for empty strings */
352
- /* TODO(fa)
353
- if (size == 0)
354
- _Py_RETURN_UNICODE_EMPTY();
355
- */
356
-
357
- /* Single character Unicode objects in the Latin-1 range are
358
- shared when using this constructor */
359
- /* TODO(fa)
360
- if (size == 1 && (Py_UCS4)*u < 256)
361
- return get_latin1_char((unsigned char)*u);
362
- */
363
-
364
- /* If not empty and not single character, copy the Unicode data
365
- into the new object */
366
354
uint32_t maxchar = 0 ;
367
355
wchar_t ch ;
368
356
HPy_ssize_t i ;
369
357
for (i = 0 ; i < size ; i ++ ) {
370
- #if SIZEOF_WCHAR_T == 2
371
- if (Py_UNICODE_IS_HIGH_SURROGATE (iter [0 ])
372
- && (iter + 1 ) < end
373
- && Py_UNICODE_IS_LOW_SURROGATE (iter [1 ]))
374
- {
375
- ch = Py_UNICODE_JOIN_SURROGATES (iter [0 ], iter [1 ]);
376
- ++ (* num_surrogates );
377
- iter += 2 ;
378
- }
379
- else
380
- #endif
381
358
ch = u [i ];
382
359
if (ch > maxchar ) {
383
360
maxchar = ch ;
384
- /* TODO(fa): error
385
- if (*maxchar > MAX_UNICODE) {
386
- PyErr_Format(PyExc_ValueError,
387
- "character U+%x is not in range [U+0000; U+10ffff]",
388
- ch);
389
- return -1;
361
+ if (maxchar > MAX_UNICODE ) {
362
+ HPyErr_SetString (ctx , ctx -> h_ValueError , "character is not in range [U+0000; U+10ffff]" );
363
+ return HPy_NULL ;
390
364
}
391
- */
392
365
}
393
366
}
394
367
395
- if (maxchar < 65536 ) {
368
+ if (maxchar < UINT16_MAX ) {
396
369
jarray jCharArray = (* jniEnv )-> NewCharArray (jniEnv , (jsize ) size );
397
370
jchar * content = (* jniEnv )-> GetPrimitiveArrayCritical (jniEnv , jCharArray , 0 );
398
371
HPy_ssize_t i ;
0 commit comments