@@ -2333,7 +2333,7 @@ PyUnicodeWriter_WriteUCS4(PyUnicodeWriter *pub_writer,
2333
2333
2334
2334
2335
2335
static int
2336
- unicode_export (PyObject * unicode , Py_buffer * view ,
2336
+ unicode_export (PyObject * unicode , Py_buffer * view , uint32_t * pformat ,
2337
2337
Py_ssize_t len , const void * buf ,
2338
2338
int itemsize , const char * format , uint32_t internal_format )
2339
2339
{
@@ -2344,12 +2344,14 @@ unicode_export(PyObject *unicode, Py_buffer *view,
2344
2344
view -> itemsize = itemsize ;
2345
2345
view -> format = (char * )format ;
2346
2346
view -> internal = (void * )(uintptr_t )internal_format ;
2347
+ * pformat = internal_format ;
2347
2348
return 0 ;
2348
2349
}
2349
2350
2350
2351
2351
2352
int
2352
- PyUnicode_Export (PyObject * unicode , uint32_t requested_formats , Py_buffer * view )
2353
+ PyUnicode_Export (PyObject * unicode , uint32_t requested_formats ,
2354
+ Py_buffer * view , uint32_t * format )
2353
2355
{
2354
2356
#if SIZEOF_INT == 4
2355
2357
# define BUFFER_UCS4 "I"
@@ -2369,7 +2371,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats, Py_buffer *view)
2369
2371
if (PyUnicode_IS_ASCII (unicode )
2370
2372
&& (requested_formats & PyUnicode_FORMAT_ASCII ))
2371
2373
{
2372
- return unicode_export (unicode , view ,
2374
+ return unicode_export (unicode , view , format ,
2373
2375
len , PyUnicode_1BYTE_DATA (unicode ),
2374
2376
1 , "B" , PyUnicode_FORMAT_ASCII );
2375
2377
}
@@ -2379,7 +2381,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats, Py_buffer *view)
2379
2381
if (kind == PyUnicode_1BYTE_KIND
2380
2382
&& (requested_formats & PyUnicode_FORMAT_UCS1 ))
2381
2383
{
2382
- return unicode_export (unicode , view ,
2384
+ return unicode_export (unicode , view , format ,
2383
2385
len , PyUnicode_1BYTE_DATA (unicode ),
2384
2386
1 , "B" , PyUnicode_FORMAT_UCS1 );
2385
2387
}
@@ -2388,7 +2390,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats, Py_buffer *view)
2388
2390
if (kind == PyUnicode_2BYTE_KIND
2389
2391
&& (requested_formats & PyUnicode_FORMAT_UCS2 ))
2390
2392
{
2391
- return unicode_export (unicode , view ,
2393
+ return unicode_export (unicode , view , format ,
2392
2394
len , PyUnicode_2BYTE_DATA (unicode ),
2393
2395
2 , "H" , PyUnicode_FORMAT_UCS2 );
2394
2396
}
@@ -2409,7 +2411,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats, Py_buffer *view)
2409
2411
ucs2 );
2410
2412
ucs2 [len ] = 0 ;
2411
2413
2412
- return unicode_export (unicode , view ,
2414
+ return unicode_export (unicode , view , format ,
2413
2415
len , ucs2 ,
2414
2416
2 , "H" , PyUnicode_FORMAT_UCS2 );
2415
2417
}
@@ -2418,7 +2420,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats, Py_buffer *view)
2418
2420
if (kind == PyUnicode_4BYTE_KIND
2419
2421
&& (requested_formats & PyUnicode_FORMAT_UCS4 ))
2420
2422
{
2421
- return unicode_export (unicode , view ,
2423
+ return unicode_export (unicode , view , format ,
2422
2424
len , PyUnicode_4BYTE_DATA (unicode ),
2423
2425
4 , BUFFER_UCS4 , PyUnicode_FORMAT_UCS4 );
2424
2426
}
@@ -2429,7 +2431,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats, Py_buffer *view)
2429
2431
if (ucs4 == NULL ) {
2430
2432
return -1 ;
2431
2433
}
2432
- return unicode_export (unicode , view ,
2434
+ return unicode_export (unicode , view , format ,
2433
2435
len , ucs4 ,
2434
2436
4 , BUFFER_UCS4 , PyUnicode_FORMAT_UCS4 );
2435
2437
}
@@ -2441,7 +2443,7 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats, Py_buffer *view)
2441
2443
if (utf8 == NULL ) {
<
10000
tr class="diff-line-row">2442
2444
return -1 ;
2443
2445
}
2444
- return unicode_export (unicode , view ,
2446
+ return unicode_export (unicode , view , format ,
2445
2447
nbytes , utf8 ,
2446
2448
1 , "B" , PyUnicode_FORMAT_UTF8 );
2447
2449
}
@@ -2454,33 +2456,6 @@ PyUnicode_Export(PyObject *unicode, uint32_t requested_formats, Py_buffer *view)
2454
2456
}
2455
2457
2456
2458
2457
- int
2458
- PyUnicode_GetBufferFormat (const Py_buffer * view , uint32_t * format )
2459
- {
2460
- if (view -> obj == NULL || !PyUnicode_Check (view -> obj )) {
2461
- PyErr_SetString (PyExc_ValueError , "not a str export" );
2462
- return -1 ;
2463
- }
2464
-
2465
- uintptr_t internal_format = (uintptr_t )view -> internal ;
2466
- switch (internal_format )
2467
- {
2468
- case PyUnicode_FORMAT_ASCII :
2469
- case PyUnicode_FORMAT_UCS1 :
2470
- case PyUnicode_FORMAT_UCS2 :
2471
- case PyUnicode_FORMAT_UCS4 :
2472
- case PyUnicode_FORMAT_UTF8 :
2473
- break ;
2474
- default :
2475
- PyErr_SetString (PyExc_ValueError , "invalid format" );
2476
- return -1 ;
2477
- }
2478
-
2479
- * format = (uint32_t )internal_format ;
2480
- return 0 ;
2481
- }
2482
-
2483
-
2484
2459
static void
2485
2460
unicode_releasebuffer (PyObject * unicode , Py_buffer * view )
2486
2461
{
0 commit comments