Teks sumber — English
Terjemahan — Bahasa Indonesia
On Python 3.12 and older, the macro :c:macro:`!PY_SSIZE_T_CLEAN` must be defined before including :file:`Python.h` to use all ``#`` variants of formats (``s#``, ``y#``, etc.) explained below. This is not necessary on Python 3.13 and later.
Pada Python 3.12 dan yang lebih lama, makro :c:macro:`!PY_SSIZE_T_CLEAN` harus didefinisikan sebelum :file:`Python.h` untuk menggunakan semua varian ``#`` dari format (``s#``, ``y#``, dll.) yang dijelaskan di bawah ini. Ini tidak diperlukan pada Python 3.13 dan yang lebih baru.
These formats allow accessing an object as a contiguous chunk of memory. You don't have to provide raw storage for the returned unicode or bytes area.
Formaty te umożliwiają dostęp do obiektu jako ciągłego fragmentu pamięci. Nie musisz zapewniać nieprzetworzonej pamięci dla zwróconego obszaru unicode lub bajtów.
Formats such as ``y*`` and ``s*`` fill a :c:type:`Py_buffer` structure. This locks the underlying buffer so that the caller can subsequently use the buffer even inside a :c:type:`Py_BEGIN_ALLOW_THREADS` block without the risk of mutable data being resized or destroyed. As a result, **you have to call** :c:func:`PyBuffer_Release` after you have finished processing the data (or in any early abort case).
Format seperti ``y*`` dan ``s*`` mengisi struktur :c:type:`Py_buffer`. Hal ini mengunci buffer yang mendasarinya sehingga pemanggil dapat menggunakan buffer tersebut bahkan di dalam blok :c:type:`Py_BEGIN_ALLOW_THREADS` tanpa risiko data diubah ukurannya atau dihancurkan. Akibatnya, **anda harus memanggil** :c:func:`PyBuffer_Release` setelah anda selesai memproses data (atau dalam kasus pembatalan awal).
The ``es``, ``es#``, ``et`` and ``et#`` formats allocate the result buffer. **You have to call** :c:func:`PyMem_Free` after you have finished processing the data (or in any early abort case).
Format ``es``, ``es#``, ``et`` dan ``et#`` mengalokasikan buffer hasil. **anda harus menghubungi** :c:func:`PyMem_Free` setelah anda selesai memproses data (atau dalam kasus pembatalan awal).
Other formats take a :class:`str` or a read-only :term:`bytes-like object`, such as :class:`bytes`, and provide a ``const char *`` pointer to its buffer. In this case the buffer is "borrowed": it is managed by the corresponding Python object, and shares the lifetime of this object. You won't have to release any memory yourself.
Format lain menggunakan :class:`str` atau read-only :term:`bytes-like object`, seperti :class:`bytes`, dan menyediakan penunjuk ``const char *`` ke buffer-nya. Dalam kasus ini, buffer "dipinjam": buffer dikelola oleh objek Python yang sesuai, dan berbagi masa pakai dengan objek tersebut. Anda tidak perlu mengeluarkan memori sendiri.
These formats allow representing Python numbers or single characters as C numbers. Formats that require :class:`int`, :class:`float` or :class:`complex` can also use the corresponding special methods :meth:`~object.__index__`, :meth:`~object.__float__` or :meth:`~object.__complex__` to convert the Python object to the required type.
Format-format ini memungkinkan untuk merepresentasikan angka Python atau karakter tunggal sebagai angka C. Format yang memerlukan :class:`int`, :class:`float` atau :class:`complex` juga dapat menggunakan metode khusus :meth:`~object.__index__`, :meth:`~object.__float__` atau :meth:`~object.__complex__` untuk mengonversi objek Python ke jenis yang diperlukan.
For signed integer formats, :exc:`OverflowError` is raised if the value is out of range for the C type. For unsigned integer formats, the most significant bits are silently truncated when the receiving field is too small to receive the value, and :exc:`DeprecationWarning` is emitted when the value is larger than the maximal value for the C type or less than the minimal value for the corresponding signed integer type of the same size.
For unsigned integer formats ``B``, ``H``, ``I``, ``k`` and ``K``, :exc:`DeprecationWarning` is emitted when the value is larger than the maximal value for the C type or less than the minimal value for the corresponding signed integer type of the same size.
When memory buffers are passed as parameters to supply data to build objects, as for the ``s`` and ``s#`` formats, the required data is copied. Buffers provided by the caller are never referenced by the objects created by :c:func:`Py_BuildValue`. In other words, if your code invokes :c:func:`malloc` and passes the allocated memory to :c:func:`Py_BuildValue`, your code is responsible for calling :c:func:`free` for that memory once :c:func:`Py_BuildValue` returns.