New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New C API for declaring Python types #50122
Comments
EXECUTIVE SUMMARY I've written a patch against py3k trunk creating a new function-based THE PROBLEM Here's how you create an extension type using the current API.
This approach causes two problems.
THE SOLUTION My patch creates a new function-based extension type definition API. With this API available, extension authors no longer need to directly One feature worth mentioning is that the API is type-safe. Many such SIDE-EFFECTS OF THE API The major change resulting from this API: all PyTypeObjects must now This gives rise to the first headache caused by the API: type casts Hopefully I've already found most of these in CPython itself, but (Pro-tip: if you're working with this patch, and you see a crash, Another irksome side-effect of the API: because of "tp_flags" and
"tp_dealloc", I now have two declarations of PyTypeObject. There's
the externally-visible one in Include/object.h, which lets external
parties see "tp_dealloc" and "tp_flags". Then there's the internal
one in Objects/typeprivate.h which is the real structure. Since
declaring a type twice is a no-no, the external one is gated on
#ifndef PY_TYPEPRIVATE
If you're a normal Python extension programmer, you'd include Python.h
as normal:
#include "Python.h"
Python implementation files that need to see the real PyTypeObject
structure now look like this:
#define PY_TYPEPRIVATE
#include "Python.h"
#include "../Objects/typeprivate.h"
Also, since the structure of PyTypeObject hasn't yet changed, there THE UPGRADE PATH Python internally declares a great many types, and I haven't attempted 1. Where your file currently has this:
#include "Python.h"
change it to this:
#define PY_TYPEPRIVATE
#include "Python.h"
#include "pytypeconvert.h"
The conversion header file *also* redefines PyTypeObject. But this (Why bother with this conversion process, with few py3k extensions THE CURRENT PATCH The patch below applies cleanly to py3k/trunk (r72081). But the
My thanks to Neal Norwitz for suggesting this project, and Brett Cannon |
I think this is great stuff, Larry. It's a definite improvement. Unfortunately with my workload of other Python issues, I'm not going to |
This patch is huge. Some things:
Lastly, since your patch is not ready for consumption, I would advocate |
Antoine: As the patch matured I would obviously provide documentation As for mandatory vs purity: The whole purpose of the patch was to make The patch attempts to mitigate this as much as possible with the p.s. By "huge" I suspect you mean "large", though on first reading I p.p.s. Did this patch get mentioned recently or something? After months p.p.p.s. I have not touched this patch since submitting it. The |
Whoops! I think I'll finish that unfinished sentence. "The patch attempts to mitigate this as much as possible with the header file; it minimizes as much as possible the changes you need to |
What I meant is that it's difficult for me (and perhaps others) to
Hmm. That public interfaces take pointers is one thing, but that doesn't Please note that your approach will make it difficult for third-party C
I meant "large" indeed :)
Well, a nosy+ bumps up the issue at the top of the recently modified |
With PEP-384, this is now obsolete, so closing it as such. If you think that selected features of this patch should still be added, please submit them as separate patches. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: