@@ -529,10 +529,118 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
529
529
Exactly what values are considered compact is an implementation detail
530
530
and is subject to change.
531
531
532
+ .. versionadded :: 3.12
533
+
534
+
532
535
.. c :function :: Py_ssize_t PyUnstable_Long_CompactValue (const PyLongObject* op)
533
536
534
537
If *op* is compact, as determined by :c:func:`PyUnstable_Long_IsCompact`,
535
538
return its value.
536
539
537
540
Otherwise, the return value is undefined.
538
541
542
+ .. versionadded:: 3.12
543
+
544
+
545
+ Import/Export API
546
+ ^^^^^^^^^^^^^^^^^
547
+
548
+ .. versionadded:: 3.14
549
+
550
+ .. c:type:: Py_digit
551
+
552
+ A single unsigned digit.
553
+
554
+ It is usually used in an *array of digits*, such as the
555
+ :c:member:`PyUnstable_LongExport.digits` array.
556
+
557
+ Its size depend on the :c:macro:`PYLONG_BITS_IN_DIGIT` macro:
558
+ see the ``configure`` :option:`--enable-big-digits` option.
559
+
560
+ See :c:member:`PyUnstable_Long_LAYOUT.bits_per_digit` for the number of bits per
561
+ digit and :c:member:`PyUnstable_Long_LAYOUT.digit_size` for the size of a digit (in
562
+ bytes).
563
+
564
+
565
+ .. c:struct:: PyUnstable_Long_LAYOUT
566
+
567
+ Internal layout of a Python :class:`int` object.
568
+
569
+ See also :attr:`sys.int_info` which exposes similar information to Python.
570
+
571
+ .. c:member:: uint8_t bits_per_digit;
572
+
573
+ Bits per digit.
574
+
575
+ .. c :member :: uint8_t digit_size;
576
+
577
+ Digit size in bytes.
578
+
579
+ .. c :member :: int8_t word_endian;
580
+
581
+ Word endian:
582
+
583
+ - 1 for most significant byte first (big endian)
584
+ - 0 for least significant first (little endian)
585
+
586
+ .. c:member:: int8_t array_endian;
587
+
588
+ Array endian:
589
+
590
+ - 1 for most significant byte first (big endian)
591
+ - 0 for least significant first (little endian)
592
+
593
+
594
+ .. c:function:: PyObject* PyUnstable_Long_Import(int negative, size_t ndigits, Py_digit *digits)
595
+
596
+ Create a Python :class: `int ` object from an array of digits.
597
+
598
+ * Return a Python :class: `int ` object on success.
599
+ * Set an exception and return ``NULL `` on error.
600
+
601
+ *negative * is ``1 `` if the number is negative, or ``0 `` otherwise.
602
+
603
+ *ndigits * is the number of digits in the *digits * array.
604
+
605
+ *digits * is an array of unsigned digits.
606
+
607
+ See :c:struct: `PyUnstable_Long_LAYOUT ` for the internal layout of an integer.
608
+
609
+
610
+ .. c :struct :: PyUnstable_LongExport
611
+
612
+ A Python :class: `int ` object exported as an array of digits.
613
+
614
+ See :c:struct: `PyUnstable_Long_LAYOUT ` for the internal layout of an integer.
615
+
616
+ .. c :member :: PyLongObject *obj
617
+
618
+ Strong reference to the Python :class: `int ` object.
619
+
620
+ .. c :member :: int negative
621
+
622
+ 1 if the number is negative, 0 otherwise.
623
+
624
+ .. c :member :: size_t ndigits
625
+
626
+ Number of digits in :c:member: `digits ` array.
627
+
628
+ .. c :member :: Py_digit *digits
629
+
630
+ Array of unsigned digits.
631
+
632
+
633
+ .. c :function :: int PyUnstable_Long_Export (PyLongObject *obj, PyUnstable_LongExport *export)
634
+
635
+ Export a Python :class: `int ` object as an array of digits.
636
+
637
+ * Set *\* export * and return 0 on success.
638
+ * Set an exception and return -1 on error.
639
+
640
+ :c:func: `PyUnstable_Long_ReleaseExport ` must be called once done with using
641
+ *export *.
642
+
643
+
644
+ .. c :function :: void PyUnstable_Long_ReleaseExport (PyUnstable_LongExport *export)
645
+
646
+ Release an export created by :c:func: `PyUnstable_Long_Export `.
0 commit comments