-
Notifications
You must be signed in to change notification settings - Fork 6
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
Use of features specific to the C language #35
Comments
@davidhewitt wrote:
As for the "issues" in the OP, thus we handle them as so:
We get humans to do this bit. To keep things easier we try to match the structure of the
The Rust standard library has
Rust has
We've reproduced most of these as |
I think that providing some convenience helpers specific for C is fine, but any C specific should be left out from the ABI, or have alternative non-C specific variants in the ABI. For example, Edit: now I see you don't list varargs, but I'd add them to the list too? |
What is the problem with variadic arguments? Are there programming languages which cannot use them and are used to write Python extensions? Are you saying that we should not add functions using variadic arguments in their defintion, like How do you implement a function with a variable number of arguments in these languages? For example, how do you bind I looked at PyO3 (Rust), it seems to happily bind these functions: PyO3 also has PyUnicode_FromFormatV(), but its implementation is commented. |
The question of variadic arguments arised in my issue proposing to add |
I don't think we should avoid functions like For For For C, the varargs variants might still be the right way to do things. But alternatives should (and do) exist. |
Note: IMO this API is bad since it creates an uninitialized Python tuple object, see: #56
Yep, |
Go's cgo does not (and probably won't ever) support calls to variadic C functions. When in developing Pygolo (to embed and extend Python in Go) I need some functionality they provide I hope to find some other way. Example, Another case is I'm not bound to expose the whole C API to Go, some part of it do not make sense at all (for Go) and others are just used to build higher level or more idiomatic constructs. I think it's not only acceptable but sometimes also necessary to have a low-level error-prone difficult-to-handle API, it's just that they should not be first choice or maybe the only option. I love the Python C API, it's a great tool, good documentation, it's powerful and it's a lot of fun to use and to build upon. Of course, as everything, it can be improved but please do try to make it too ideal, ok? edit: I see I'm mostly echoing @encukou, just more verbosely :) |
What said @encukou for PySys_Audit() now makes sense to me: if we add an API with variadic arguments, we should offer a similar API without it. PySys_Audit() builds a tuple: the second flavor would be an API which already takes a tuple. So people would can use variadic arguments just use it (it's a convenient API), and there is a backup plan for other people. Thanks @cavokz, I didn't want to add a new function and have to maintain it to solve an hypothetical problem. I didn't know that Go doesn't support variadic arguments and that Python can be used with Go, two things that I learned today 👍 |
To further clarify what I meant:
|
AFAIK, C standards say nothing about ABI. This kind of stuff is left to platforms/distributors, see the disclaimer in the docs
That's the general idea of the direction I want to go in: a very portable base, and optional C-specific niceties. |
I see this mentioned in many places, but the enum size is actually mandated by the platform ABI, which the compiler is supposed to comply with. For example the SysV ABI for x86-64 (used on GNU/Linux) mandates that enum have size 4 and alignment 4, except when some enum values wouldn't fit (which is unlikely): Similarly, Microsoft's x86-64 ABI has a similar provision and doesn't even seem to make rooms for enums larger than 32 bits ("enums are constant integers and are treated as 32-bit integers"): That said, I agree that having to think about enum size when using a non-C/C++ language is annoying in itself. |
Non-C languages struggle with:
Some related problems have their own issues here:
int
, by necessity)The text was updated successfully, but these errors were encountered: