-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
API: Make descr->f
only accessible through PyDataType_GetArrFuncs
#25812
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
Conversation
1995aa0
to
bcb80b3
Compare
@@ -0,0 +1,5 @@ | |||
* The ``->f`` slot has been removed from ``PyArray_Descr``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You added the slot back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed it, and will remove it completely in a follow up, thought I would add the note here already.
Doesn't need to happen now but if not please add a note to make sure this gets discussed in the transition guide. |
* is only valid after checking for NULL. Checking for NULL is generally | ||
* encouraged. | ||
* | ||
* The public name of this is a macro until 1.x BC is irrelevant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helps but I'm still a little confused why we need to publicly expose a static inline function which calls thing function which calls another static inline function. I guess it's just dealing with naming conflicts but it would be nice to explicitly spell out the problem and maybe expand this comment a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Internally, I thought an inline function is nicer for the simple pointer chasing that is going on.
- Publically, an inline function isn't possible because the struct is fully opaque. So,
- the public static inline is then needed allow defining it in a backcompat way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a few sentences here to try to clarify it. I agree it is an unfortunate dance, necessary due to trying to hide it fully, but also needing the backcompat.
8cae64e
to
35251dd
Compare
This is going to break scipy (looks like just to get at
and pandas:
I'm not sure what other downstream impact there will be but this is enough for me to say we shouldn't merge this without some discussion in the transition guide so there's an obvious place to point people to for migration instructions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyDataType_GetArrFuncs
needs an entry in the C API functions doc too I think, unless the docstring you added automatically populates sphinx somehow.
Can I please create a single brief entry at the end of this (elsize and alignment should change, too and the other PR already doesn't make sense to have seperate entries in the transition guide for)?
Yes, it is but, it is also going to break them in an easy to fix way (just as it was easy to change in NumPy everywhere). |
Yes that's fine, we can expand it later. |
In the interest of shipping the RC sooner rather than later, I'm going to merge this one now. We know this will break a few downstream projects. The fix is to use the new public API for accessing these functions. Please let us know if there's some corner case we didn't anticipate. |
Oops, except there are conflicts. I'll fix this on Monday and merge it if @seberg doesn't get to it first. |
This introduces ``PyDataType_GetArrFuncs`` as public and private API to fetch the ``PyArray_ArrFuncs *`` slot and thus allowing to remove it from ``PyArray_Descr``. Internally, the function is defined as inline in ``dtypemeta.h``.
Fetching the arrayfuncs now requires `dtypemeta.h` internally (externally, we force use of an API function call). So move these inline helpers also to `dtypemeta.h` as they cannot be defined without the header. (This is unfortunate, but I didn't have a better idea)
This allows removing the `->f` fields from the descriptor struct.
Also, use C99 struct initializer to make that work.
@@ -490,6 +482,17 @@ PyArrayDescr_Type and PyArray_Descr | |||
PyArray_ArrFuncs | |||
---------------- | |||
|
|||
.. c:function:: PyArray_ArrFuncs *PyDataType_GetArrFuncs(PyArray_Descr *dtype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyDataType_GetArrFuncs needs an entry in the C API functions doc too I think
I had added a brief entry here.
35251dd
to
d028cc1
Compare
Failures are unrelated, merging. |
The compat include is a bit annoying downstream, |
* Fixes scipygh-20107 * WIP for now because I don't like that I had to manually adjust the NumPy compat shim header... * I confirmed that this branch restored full build/test suite passing on x86_64 Linux with NumPy in the following scenarios: build with NumPy `main`, test with NumPy `main`; build with NumPy `main`, test with NumPy `1.26.4` (and 1.x only of course) * although I did apply the suggestions at or linked from: numpy/numpy#25812 I'm not happy about the fact that I have to modify `npy_2_compat.h` manually (this seems very much not ideal, perhaps I'll open an upstream issue) [skip cirrus] [skip circle]
* Fixes scipygh-20107 * WIP for now because I don't like that I had to manually adjust the NumPy compat shim header... * I confirmed that this branch restored full build/test suite passing on x86_64 Linux with NumPy in the following scenarios: build with NumPy `main`, test with NumPy `main`; build with NumPy `main`, test with NumPy `1.26.4` (and 1.x only of course) * although I did apply the suggestions at or linked from: numpy/numpy#25812 I'm not happy about the fact that I have to modify `npy_2_compat.h` manually (this seems very much not ideal, perhaps I'll open an upstream issue) [skip cirrus] [skip circle]
* Fixes scipygh-20107 * WIP for now because I don't like that I had to manually adjust the NumPy compat shim header... * I confirmed that this branch restored full build/test suite passing on x86_64 Linux with NumPy in the following scenarios: build with NumPy `main`, test with NumPy `main`; build with NumPy `main`, test with NumPy `1.26.4` (and 1.x only of course) * although I did apply the suggestions at or linked from: numpy/numpy#25812 I'm not happy about the fact that I have to modify `npy_2_compat.h` manually (this seems very much not ideal, perhaps I'll open an upstream issue) [skip cirrus] [skip circle]
This is the next step in hiding/refactoring the
PyArray_Descr
struct. It:PyDataType_GetArrFuncs
function. Internally this is a static inlinefunction, but publically, it maps to the
_PyDataType_GetArrFuncs
API functionin a backwards compatible manner.
The unfortunate thing (does anyone have an idea?) thing here is that I had to "duplicate" the
PyArray_GETITEM
andPyArray_SETITEM
intodtypemeta.h
to pull this off, as there is no reasonable way to have diverging versions of the inline functionPyDataType_GetArrFuncs
.Adds some docs, but I intentionally omitted docs in the 2.0 transition guide (they should be part of a larger fixups).
Marking as draft, as there will be small collisions with the previous PR.
(EDIT: Used a slightly modified version of my tool to do most of the
MAINT: Access descr->f-> only through static inline function
commit, I have not fixed the style everywhere.)EDIT: Marked as ready for review, the order of the PRs doesn't really matter after all.