@@ -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 ))
1171
1148
{
1172
1149
goto error ;
1173
1150
}
@@ -1181,7 +1158,7 @@ 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" , tmp2 , node )) {
1185
1162
Py_DECREF (tmp2 );
1186
1163
goto error ;
1187
1164
}
@@ -1196,7 +1173,7 @@ hamt_node_bitmap_dump(PyHamtNode_Bitmap *node,
1196
1173
}
1197
1174
1198
1175
if (key_or_null == NULL ) {
1199
- if (_hamt_dump_format (writer , "NULL:\n" )) {
1176
+ if (PyUnicodeWriter_Format (writer , "NULL:\n" )) {
1200
1177
goto error ;
1201
1178
}
1202
1179
@@ -1207,14 +1184,14 @@ hamt_node_bitmap_dump(PyHamtNode_Bitmap *node,
1207
1184
}
1208
1185
}
1209
1186
else {
1210
- if (_hamt_dump_format (writer , "%R: %R" , key_or_null ,
1211
- val_or_node ))
1187
+ if (PyUnicodeWriter_Format (writer , "%R: %R" ,
1188
+ key_or_null , val_or_node ))
1212
1189
{
1213
1190
goto error ;
1214
1191
}
1215
1192
}
1216
1193
1217
- if (_hamt_dump_format (writer , "\n" )) {
1194
+ if (PyUnicodeWriter_WriteUTF8 (writer , "\n" , 1 )) {
1218
1195
goto error ;
1219
1196
}
1220
1197
}
@@ -1548,7 +1525,7 @@ hamt_node_collision_dealloc(PyHamtNode_Collision *self)
1548
1525
#ifdef Py_DEBUG
1549
1526
static int
1550
1527
hamt_node_collision_dump (PyHamtNode_Collision * node ,
1551
- _PyUnicodeWriter * writer , int level )
1528
+ PyUnicodeWriter * writer , int level )
1552
1529
{
1553
1530
/* Debug build: __dump__() method implementation for Collision nodes. */
1554
1531
@@ -1558,7 +1535,7 @@ hamt_node_collision_dump(PyHamtNode_Collision *node,
1558
1535
goto error ;
1559
1536
}
1560
1537
1561
- if (_hamt_dump_format (writer , "CollisionNode(size=%zd id=%p):\n" ,
1538
+ if (PyUnicodeWriter_Format (writer , "CollisionNode(size=%zd id=%p):\n" ,
1562
1539
Py_SIZE (node ), node ))
1563
1540
{
1564
1541
goto error ;
@@ -1572,7 +1549,7 @@ hamt_node_collision_dump(PyHamtNode_Collision *node,
1572
1549
goto error ;
1573
1550
}
1574
1551
1575
- if (_hamt_dump_format (writer , "%R: %R\n" , key , val )) {
1552
+ if (PyUnicodeWriter_Format (writer , "%R: %R\n" , key , val )) {
1576
1553
goto error ;
1577
1554
}
1578
1555
}
@@ -1924,7 +1901,7 @@ hamt_node_array_dealloc(PyHamtNode_Array *self)
1924
1901
#ifdef Py_DEBUG
1925
1902
static int
1926
1903
hamt_node_array_dump (PyHamtNode_Array * node ,
1927
- _PyUnicodeWriter * writer , int level )
1904
+ PyUnicodeWriter * writer , int level )
1928
1905
{
1929
1906
/* Debug build: __dump__() method implementation for Array nodes. */
1930
1907
@@ -1934,7 +1911,7 @@ hamt_node_array_dump(PyHamtNode_Array *node,
1934
1911
goto error ;
1935
1912
}
1936
1913
1937
- if (_hamt_dump_format (writer , "ArrayNode(id=%p):\n" , node )) {
1914
+ if (PyUnicodeWriter_Format (writer , "ArrayNode(id=%p):\n" , node )) {
1938
1915
goto error ;
1939
1916
}
1940
1917
@@ -1947,15 +1924,15 @@ hamt_node_array_dump(PyHamtNode_Array *node,
1947
1924
goto error ;
1948
1925
}
1949
1926
1950
- if (_hamt_dump_format (writer , "%zd::\n" , i )) {
1927
+ if (PyUnicodeWriter_Format (writer , "%zd::\n" , i )) {
1951
1928
goto error ;
1952
1929
}
1953
1930
1954
1931
if (hamt_node_dump (node -> a_array [i ], writer , level + 1 )) {
1955
1932
goto error ;
1956
1933
}
1957
1934
1958
- if (_hamt_dump_format (writer , "\n" )) {
1935
+ if (PyUnicodeWriter_WriteUTF8 (writer , "\n" , 1 )) {
1959
1936
goto error ;
1960
1937
}
1961
1938
}
@@ -2071,7 +2048,7 @@ hamt_node_find(PyHamtNode *node,
2071
2048
#ifdef Py_DEBUG
2072
2049
static int
2073
2050
hamt_node_dump (PyHamtNode * node ,
2074
- _PyUnicodeWriter * writer , int level )
2051
+ PyUnicodeWriter * writer , int level )
2075
2052
{
2076
2053
/* Debug build: __dump__() method implementation for a node.
2077
2054
@@ -2440,22 +2417,23 @@ _PyHamt_New(void)
2440
2417
static PyObject *
2441
2418
hamt_dump (PyHamtObject * self )
2442
2419
{
2443
- _PyUnicodeWriter writer ;
2444
-
2445
- _PyUnicodeWriter_Init (& writer );
2420
+ PyUnicodeWriter * writer = PyUnicodeWriter_Create (0 );
2421
+ if (writer == NULL ) {
2422
+ return NULL ;
2423
+ }
2446
2424
2447
- if (_hamt_dump_format ( & writer , "HAMT(len=%zd):\n" , self -> h_count )) {
2425
+ if (PyUnicodeWriter_Format ( writer , "HAMT(len=%zd):\n" , self -> h_count )) {
2448
2426
goto error ;
2449
2427
}
2450
2428
2451
- if (hamt_node_dump (self -> h_root , & writer , 0 )) {
2429
+ if (hamt_node_dump (self -> h_root , writer , 0 )) {
2452
2430
goto error ;
2453
2431
}
2454
2432
2455
- return _PyUnicodeWriter_Finish ( & writer );
2433
+ return PyUnicodeWriter_Finish ( writer );
2456
2434
2457
2435
error :
2458
- _PyUnicodeWriter_Dealloc ( & writer );
2436
+ PyUnicodeWriter_Discard ( writer );
2459
2437
return NULL ;
2460
2438
}
2461
2439
#endif /* Py_DEBUG */
0 commit comments