<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, 13 Jul 2017 at 09:12 Ronald Oussoren <<a href="mailto:ronaldoussoren@mac.com">ronaldoussoren@mac.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div dir="auto" style="word-wrap:break-word"><div><blockquote type="cite"><div>On 12 Jul 2017, at 20:51, Brett Cannon <<a href="mailto:brett@python.org" target="_blank">brett@python.org</a>> wrote:</div><br class="m_6796110656865638962Apple-interchange-newline"><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, 12 Jul 2017 at 01:25 Ronald Oussoren <<a href="mailto:ronaldoussoren@mac.com" target="_blank">ronaldoussoren@mac.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>> On 11 Jul 2017, at 12:19, Victor Stinner <<a href="mailto:victor.stinner@gmail.com" target="_blank">victor.stinner@gmail.com</a>> wrote:<br></blockquote></div></div></div></blockquote></div></div></div><div style="word-wrap:break-word"><div dir="auto" style="word-wrap:break-word"><div>[SNIP]<blockquote type="cite"><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">><br>> Step 3: first pass of implementation detail removal<br>> ---------------------------------------------------<br>><br>> Modify the ``python`` API:<br>><br>> * Add a new ``API`` subdirectory in the Python source code which will<br>>  "implement" the Python C API<br>> * Replace macros with functions. The implementation of new functions<br>>  will be written in the ``API/`` directory. For example, Py_INCREF()<br>>  becomes the function ``void Py_INCREF(PyObject *op)`` and its<br>>  implementation will be written in the ``API`` directory.<br><br>In this particular case (Py_INCREF/DECREF) making them functions isn’t really useful and is likely to be harmful for performance. It is not useful because these macros manipulate state in a struct that must be public because that struct is included into the structs for custom objects (PyObject_HEAD). Having them as macro’s also doesn’t preclude moving to indirect reference counts. Moving to anything that isn’t reference counts likely needs changes to the API (but not necessarily, see PyPy’s cpext).<br></blockquote><div><br></div><div>I think Victor has long-term plans to try and hide the struct details at a higher-level and so that would make macros a bad thing. But ignoring the specific Py_INCREF/DECREF example, switching to functions does buy us the ability to actually change the function implementations between Python versions compared to having to worry about what a macro used to do (which is a possibility with the stable ABI).<br></div></div></div></div></blockquote><div><br></div></div></div></div><div style="word-wrap:break-word"><div dir="auto" style="word-wrap:break-word"><div><div>I don’t understand. Moving too functions instead of macros for some thing doesn’t really help with keeping the public API stable (for the non-stable ABI).</div></div></div></div></blockquote><div><br></div><div>Sorry, I didn't specify which ABI/API I was talking about; my point was from the stable ABI.<br><br></div><div>I think this is quickly showing how naming is going to play into this since e.g. we say "stable ABI" but call it "Py_LIMITED_API" in the code which is rather confusing.<br><br></div><div>Just to make sure I'm not missing anything, it seems we have a few levels here:<br><br></div><div>1. The stable A**B**I which is compatible across versions<br></div><div>2. A stable A**P**I which hides enough details that if we change a struct your code won't require an update, just a recompile<br></div><div>3. An API that exposes CPython-specific details such as structs and other details that might not be entirely portable to e.g. PyPy easily but that we try not to break<br></div><div>4. An internal API that we use for implementing the interpreter but don't expect anyone else to use, so we can break it between feature releases (although if e.g. Cython chooses to use it they can)<br><br></div><div>(There's also an API local to a single file, but since that is never exported to the linker it doesn't come into play here.)<br><br></div><div>So, a portable API/ABI, a stable API, a CPython API, and then an internal/core/interpreter API. Correct?<br></div></div></div>