@@ -349,7 +349,7 @@ hamt_node_find(PyHamtNode *node,
349
349
#ifdef Py_DEBUG
350
350
static int
351
351
hamt_node_dump (PyHamtNode * node ,
352
- _PyUnicodeWriter * writer , int level );
352
+ PyUnicodeWriter * writer , int level );
353
353
#endif
354
354
355
355
static PyHamtNode *
@@ -444,7 +444,7 @@ hamt_bitindex(uint32_t bitmap, uint32_t bit)
444
444
#ifdef Py_DEBUG
445
445
446
446
static int
447
- _hamt_dump_ident (_PyUnicodeWriter * writer , int level )
447
+ _hamt_dump_ident (PyUnicodeWriter * writer , int level )
448
448
{
449
449
/* Write `' ' * level` to the `writer` */
450
450
PyObject * str = NULL ;
@@ -467,7 +467,7 @@ _hamt_dump_ident(_PyUnicodeWriter *writer, int level)
467
467
goto error ;
468
468
}
469
469
470
- ret = _PyUnicodeWriter_WriteStr (writer , res );
470
+ ret = PyUnicodeWriter_WriteStr (writer , res );
471
471
472
472
error :
473
473
Py_XDECREF (res );
@@ -476,29 +476,6 @@ _hamt_dump_ident(_PyUnicodeWriter *writer, int level)
476
476
return ret ;
477
477
}
478
478
479
- static int
480
- _hamt_dump_format (_PyUnicodeWriter * writer , const char * format , ...)
481
- {
482
- /* A convenient helper combining _PyUnicodeWriter_WriteStr and
483
- PyUnicode_FromFormatV.
484
- */
485
- PyObject * msg ;
486
- int ret ;
487
-
488
- va_list vargs ;
489
- va_start (vargs , format );
490
- msg = PyUnicode_FromFormatV (format , vargs );
491
- va_end (vargs );
492
-
493
- if (msg == NULL ) {
494
- return -1 ;
495
- }
496
-
497
- ret = _PyUnicodeWriter_WriteStr (writer , msg );
498
- Py_DECREF (msg );
499
- return ret ;
500
- }
501
-
502
479
#endif /* Py_DEBUG */
503
480
/////////////////////////////////// Bitmap Node
504
481
@@ -1154,7 +1131,7 @@ hamt_node_bitmap_dealloc(PyHamtNode_Bitmap *self)
1154
1131
#ifdef Py_DEBUG
1155
1132
static int
1156
1133
hamt_node_bitmap_dump (PyHamtNode_Bitmap * node ,
1157
- _PyUnicodeWriter * writer , int level )
1134
+ PyUnicodeWriter * writer , int level )
1158
1135
{
1159
1136
/* Debug build: __dump__() method implementation for Bitmap nodes. */
1160
1137
@@ -1166,8 +1143,8 @@ hamt_node_bitmap_dump(PyHamtNode_Bitmap *node,
1166
1143
goto error ;
1167
1144
}
1168
1145
1169
- if (_hamt_dump_format (writer , "BitmapNode(size=%zd count=%zd " ,
1170
- Py_SIZE (node ), Py_SIZE (node ) / 2 ))
1146
+ if (PyUnicodeWriter_Format (writer , "BitmapNode(size=%zd count=%zd " ,
1147
+ Py_SIZE (node ), Py_SIZE (node ) / 2 ) < 0 )
1171
1148
{
1172
1149
goto error ;
1173
1150
}
@@ -1181,7 +1158,9 @@ hamt_node_bitmap_dump(PyHamtNode_Bitmap *node,
1181
1158
if (tmp2 == NULL ) {
1182
1159
goto error ;
1183
1160
}
1184
- if (_hamt_dump_format (writer , "bitmap=%S id=%p):\n" , tmp2 , node )) {
1161
+ if (PyUnicodeWriter_Format (writer , "bitmap=%S id=%p):\n" ,
1162
+ tmp2 , node ) < 0 )
1163
+ {
1185
1164
Py_DECREF (tmp2 );
1186
1165
goto error ;
1187
1166
}
@@ -1196,7 +1175,7 @@ hamt_node_bitmap_dump(PyHamtNode_Bitmap *node,
1196
1175
}
1197
1176
1198
1177
if (key_or_null == NULL ) {
1199
- if (_hamt_dump_format (writer , "NULL:\n" ) ) {
1178
+ if (PyUnicodeWriter_WriteUTF8 (writer , "NULL:\n" , -1 ) < 0 ) {
1200
1179
goto error ;
1201
1180
}
1202
1181
@@ -1207,14 +1186,14 @@ hamt_node_bitmap_dump(PyHamtNode_Bitmap *node,
1207
1186
}
1208
1187
}
1209
1188
else {
1210
- if (_hamt_dump_format (writer , "%R: %R" , key_or_null ,
1211
- val_or_node ))
1189
+ if (PyUnicodeWriter_Format (writer , "%R: %R" ,
1190
+ key_or_null , val_or_node ) < 0 )
1212
1191
{
1213
1192
goto error ;
1214
1193
}
1215
1194
}
1216
1195
1217
- if (_hamt_dump_format (writer , "\n" ) ) {
1196
+ if (PyUnicodeWriter_WriteUTF8 (writer , "\n" , 1 ) < 0 ) {
1218
1197
goto error ;
1219
1198
}
1220
1199
}
@@ -1548,7 +1527,7 @@ hamt_node_collision_dealloc(PyHamtNode_Collision *self)
1548
1527
#ifdef Py_DEBUG
1549
1528
static int
1550
1529
hamt_node_collision_dump (PyHamtNode_Collision * node ,
1551
- _PyUnicodeWriter * writer , int level )
1530
+ PyUnicodeWriter * writer , int level )
1552
1531
{
1553
1532
/* Debug build: __dump__() method implementation for Collision nodes. */
1554
1533
@@ -1558,8 +1537,8 @@ hamt_node_collision_dump(PyHamtNode_Collision *node,
1558
1537
goto error ;
1559
1538
}
1560
1539
1561
- if (_hamt_dump_format (writer , "CollisionNode(size=%zd id=%p):\n" ,
1562
- Py_SIZE (node ), node ))
1540
+ if (PyUnicodeWriter_Format (writer , "CollisionNode(size=%zd id=%p):\n" ,
1541
+ Py_SIZE (node ), node ) < 0 )
1563
1542
{
1564
1543
goto error ;
1565
1544
}
@@ -1572,7 +1551,7 @@ hamt_node_collision_dump(PyHamtNode_Collision *node,
1572
1551
goto error ;
1573
1552
}
1574
1553
1575
- if (_hamt_dump_format (writer , "%R: %R\n" , key , val )) {
1554
+ if (PyUnicodeWriter_Format (writer , "%R: %R\n" , key , val ) < 0 ) {
1576
1555
goto error ;
1577
1556
}
1578
1557
}
@@ -1924,7 +1903,7 @@ hamt_node_array_dealloc(PyHamtNode_Array *self)
1924
1903
#ifdef Py_DEBUG
1925
1904
static int
1926
1905
hamt_node_array_dump (PyHamtNode_Array * node ,
1927
- _PyUnicodeWriter * writer , int level )
1906
+ PyUnicodeWriter * writer , int level )
1928
1907
{
1929
1908
/* Debug build: __dump__() method implementation for Array nodes. */
1930
1909
@@ -1934,7 +1913,7 @@ hamt_node_array_dump(PyHamtNode_Array *node,
1934
1913
goto error ;
1935
1914
}
1936
1915
1937
- if (_hamt_dump_format (writer , "ArrayNode(id=%p):\n" , node )) {
1916
+ if (PyUnicodeWriter_Format (writer , "ArrayNode(id=%p):\n" , node ) < 0 ) {
1938
1917
goto error ;
1939
1918
}
1940
1919
@@ -1947,15 +1926,15 @@ hamt_node_array_dump(PyHamtNode_Array *node,
1947
1926
goto error ;
1948
1927
}
1949
1928
1950
- if (_hamt_dump_format (writer , "%zd::\n" , i )) {
1929
+ if (PyUnicodeWriter_Format (writer , "%zd::\n" , i ) < 0 ) {
1951
1930
goto error ;
1952
1931
}
1953
1932
1954
1933
if (hamt_node_dump (node -> a_array [i ], writer , level + 1 )) {
1955
1934
goto error ;
1956
1935
}
1957
1936
1958
- if (_hamt_dump_format (writer , "\n" ) ) {
1937
+ if (PyUnicodeWriter_WriteUTF8 (writer , "\n" , 1 ) < 0 ) {
1959
1938
goto error ;
1960
1939
}
1961
1940
}
@@ -2071,7 +2050,7 @@ hamt_node_find(PyHamtNode *node,
2071
2050
#ifdef Py_DEBUG
2072
2051
static int
2073
2052
hamt_node_dump (PyHamtNode * node ,
2074
- _PyUnicodeWriter * writer , int level )
2053
+ PyUnicodeWriter * writer , int level )
2075
2054
{
2076
2055
/* Debug build: __dump__() method implementation for a node.
2077
2056
@@ -2440,22 +2419,24 @@ _PyHamt_New(void)
2440
2419
static PyObject *
2441
2420
hamt_dump (PyHamtObject * self )
2442
2421
{
2443
- _PyUnicodeWriter writer ;
2444
-
2445
- _PyUnicodeWriter_Init (& writer );
2422
+ PyUnicodeWriter * writer = PyUnicodeWriter_Create (0 );
2423
+ if (writer == NULL ) {
2424
+ return NULL ;
2425
+ }
2446
2426
2447
- if (_hamt_dump_format (& writer , "HAMT(len=%zd):\n" , self -> h_count )) {
2427
+ if (PyUnicodeWriter_Format (writer , "HAMT(len=%zd):\n" ,
2428
+ self -> h_count ) < 0 ) {
2448
2429
goto error ;
2449
2430
}
2450
2431
2451
- if (hamt_node_dump (self -> h_root , & writer , 0 )) {
2432
+ if (hamt_node_dump (self -> h_root , writer , 0 )) {
2452
2433
goto error ;
2453
2434
}
2454
2435
2455
- return _PyUnicodeWriter_Finish ( & writer );
2436
+ return PyUnicodeWriter_Finish ( writer );
2456
2437
2457
2438
error :
2458
- _PyUnicodeWriter_Dealloc ( & writer );
2439
+ PyUnicodeWriter_Discard ( writer );
2459
2440
return NULL ;
2460
2441
}
2461
2442
#endif /* Py_DEBUG */
0 commit comments