@@ -1427,6 +1427,66 @@ long_to_decimal_string_internal(PyObject *aa,
1427
1427
_PyBytesWriter * bytes_writer ,
1428
1428
char * * bytes_str )
1429
1429
{
1430
+ // GraalPy change: different implementation
1431
+ PyObject * str ;
1432
+
1433
+ // writer or bytes_writer can be used, but not both at the same time.
1434
+ assert (writer == NULL || bytes_writer == NULL );
1435
+
1436
+ if (aa == NULL || !PyLong_Check (aa )) {
1437
+ PyErr_BadInternalCall ();
1438
+ return -1 ;
1439
+ }
1440
+
1441
+ str = PyObject_Repr (aa );
1442
+ if (str == NULL ) {
1443
+ goto error ;
1444
+ }
1445
+ if (!PyUnicode_Check (str )) {
1446
+ PyErr_SetString (PyExc_TypeError ,
1447
+ "long.repr did not return a str" );
1448
+ goto error ;
1449
+ }
1450
+ if (writer ) {
1451
+ Py_ssize_t size = PyUnicode_GET_LENGTH (str );
1452
+ if (_PyUnicodeWriter_Prepare (writer , size , '9' ) == -1 ) {
1453
+ goto error ;
1454
+ }
1455
+ if (_PyUnicodeWriter_WriteStr (writer , str ) < 0 ) {
1456
+ goto error ;
1457
+ }
1458
+ goto success ;
1459
+ }
1460
+ else if (bytes_writer ) {
1461
+ Py_ssize_t size = PyUnicode_GET_LENGTH (str );
1462
+ const void * data = PyUnicode_DATA (str );
1463
+ int kind = PyUnicode_KIND (str );
1464
+ * bytes_str = _PyBytesWriter_Prepare (bytes_writer , * bytes_str , size );
1465
+ if (* bytes_str == NULL ) {
1466
+ goto error ;
1467
+ }
1468
+ char * p = * bytes_str ;
1469
+ for (Py_ssize_t i = 0 ; i < size ; i ++ ) {
1470
+ Py_UCS4 ch = PyUnicode_READ (kind , data , i );
1471
+ * p ++ = (char ) ch ;
1472
+ }
1473
+ (* bytes_str ) = p ;
1474
+ goto success ;
1475
+ }
1476
+ else {
1477
+ * p_output = Py_NewRef (str );
1478
+ goto success ;
1479
+ }
1480
+
1481
+ error :
1482
+ Py_XDECREF (str );
1483
+ return -1 ;
1484
+
1485
+ success :
1486
+ Py_DECREF (str );
1487
+ return 0 ;
1488
+
1489
+ #if 0
1430
1490
PyLongObject * scratch , * a ;
1431
1491
PyObject * str = NULL ;
1432
1492
Py_ssize_t size , strlen , size_a , i , j ;
@@ -1450,7 +1510,6 @@ long_to_decimal_string_internal(PyObject *aa,
1450
1510
1451
1511
explanation in https://github.com/python/cpython/pull/96537
1452
1512
*/
1453
- #if 0 // GraalPy change: interp->long_state not supported yet
1454
1513
if (size_a >= 10 * _PY_LONG_MAX_STR_DIGITS_THRESHOLD
1455
1514
/ (3 * PyLong_SHIFT ) + 2 ) {
1456
1515
PyInterpreterState * interp = _PyInterpreterState_GET ();
@@ -1462,7 +1521,6 @@ long_to_decimal_string_internal(PyObject *aa,
1462
1521
return -1 ;
1463
1522
}
1464
1523
}
1465
- #endif // GraalPy change
1466
1524
1467
1525
#if WITH_PYLONG_MODULE
1468
1526
if (size_a > 1000 ) {
@@ -1516,12 +1574,10 @@ long_to_decimal_string_internal(PyObject *aa,
1516
1574
hi /= _PyLong_DECIMAL_BASE ;
1517
1575
}
1518
1576
/* check for keyboard interrupt */
1519
- #if 0 // GraalPy change
1520
1577
SIGCHECK ({
1521
1578
Py_DECREF (scratch );
1522
1579
return -1 ;
1523
1580
});
1524
- #endif // GraalPy change
1525
1581
}
1526
1582
/* pout should have at least one digit, so that the case when a = 0
1527
1583
works correctly */
@@ -1536,7 +1592,6 @@ long_to_decimal_string_internal(PyObject *aa,
1536
1592
tenpow *= 10 ;
1537
1593
strlen ++ ;
1538
1594
}
1539
- #if 0 // GraalPy change: interp->long_state not supported yet
1540
1595
if (strlen > _PY_LONG_MAX_STR_DIGITS_THRESHOLD ) {
1541
1596
PyInterpreterState * interp = _PyInterpreterState_GET ();
1542
1597
int max_str_digits = interp -> long_state .max_str_digits ;
@@ -1548,7 +1603,6 @@ long_to_decimal_string_internal(PyObject *aa,
1548
1603
return -1 ;
1549
1604
}
1550
1605
}
1551
- #endif // GraalPy change
1552
1606
if (writer ) {
1553
1607
if (_PyUnicodeWriter_Prepare (writer , strlen , '9' ) == -1 ) {
1554
1608
Py_DECREF (scratch );
@@ -1651,6 +1705,7 @@ long_to_decimal_string_internal(PyObject *aa,
1651
1705
* p_output = (PyObject * )str ;
1652
1706
}
1653
1707
return 0 ;
1708
+ #endif // GraalPy change
1654
1709
}
1655
1710
1656
1711
static PyObject *
0 commit comments