-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
========================= | ||
Opaque PyObject structure | ||
========================= | ||
|
||
A blocker issue for many :ref:`optimization ideas <optim-ideas>` is that the | ||
``PyObject`` structure fields are exposed in the public C API. Example:: | ||
|
||
PyObject * | ||
PyUnicode_FromObject(PyObject *obj) | ||
{ | ||
... | ||
PyErr_Format(PyExc_TypeError, | ||
"Can't convert '%.100s' object to str implicitly", | ||
Py_TYPE(obj)->tp_name); | ||
return NULL; | ||
} | ||
|
||
with:: | ||
|
||
#define Py_TYPE(ob) (_PyObject_CAST(ob)->ob_type) | ||
#define _PyObject_CAST(op) ((PyObject*)(op)) | ||
|
||
The issue is that ``obj->ob_type`` is accessed directly. It prevents to | ||
implement :ref:`Tagged pointers <tagged-pointer>` for example. | ||
|
||
By the way, ``Py_TYPE()`` returns a :ref:`borrowed reference <borrowed-ref>` | ||
which is another kind of problem. | ||
|
||
In the long term, ``PyObject`` structure should be opaque. Accessing | ||
``ob_refcnt`` and ``ob_type`` fields should always go through functions. | ||
|
||
XXX which functions? | ||
|
||
XXX how to convert old code to these new functions? |