fixes from compiling with warnings#17
fixes from compiling with warnings#17mattip wants to merge 9 commits intohpyproject:graal-team/hpyfrom
Conversation
|
|
||
| NPY_NO_EXPORT PyObject * | ||
| PyArrayIdentityHash_GetItem(PyObject *cache_owner, PyArrayIdentityHash const *tb, PyObject *const *key) | ||
| PyArrayIdentityHash_GetItem(PyArrayIdentityHash const *tb, PyObject *cache_owner, PyObject *const *key) |
There was a problem hiding this comment.
This seems wrong? The argument order should be the same as PyArrayIdentityHash_SetItem
There was a problem hiding this comment.
Okay, makes sense. Seems that I was just not consistent in adding the cache_owner argument.
| { | ||
| const char *s; | ||
| const char *end; | ||
| char *end; |
There was a problem hiding this comment.
this caused many warnings, so either my change or all the uses of end must be const char
| NPY_ITER_ALLOCATE; | ||
|
|
||
| iter = NpyIter_MultiNew(2, op, flags, NPY_KEEPORDER, NPY_UNSAFE_CASTING, | ||
| iter = HNpyIter_MultiNew(ctx, 2, op, flags, NPY_KEEPORDER, NPY_UNSAFE_CASTING, |
There was a problem hiding this comment.
Since op seems to contain handles, calling the new function seems to make sense.
There was a problem hiding this comment.
Yes, we probably just overlooked that.
| if (hpy_get_view_from_index(ctx, self, self_struct, &view, indices, 2, 0) < 0) { | ||
| hpy_indices[1].value = PyArray_NDIM(self_struct) - 1; | ||
| hpy_indices[1].type = HAS_ELLIPSIS; | ||
| if (hpy_get_view_from_index(ctx, self, self_struct, &view, hpy_indices, 2, 0) < 0) { |
There was a problem hiding this comment.
I needed to duplicate the indices struct, since there is a call to legacy get_item_pointer for struct dtypes on line 2672 above
There was a problem hiding this comment.
Should indices be updated here too since both are being maintained?
There was a problem hiding this comment.
No. Only hpy_indices is being maintained. indices is used only in get_item_pointer in a read-only fashion.
| use_min_scalar = should_use_min_scalar(nin, op, 0, NULL); | ||
| hpy_abort_not_implemented("convert op to PyArrayObject**"); | ||
| PyArrayObject ** dummy; | ||
| use_min_scalar = should_use_min_scalar(nin, dummy, 0, NULL); |
There was a problem hiding this comment.
should_use_min_scalar is a legacy interface, op is a HPy *
There was a problem hiding this comment.
Is there something preventing us from calling HPy_AsPyObject(op) here:?
There was a problem hiding this comment.
That might work, but I would prefer not to add more HPy_AsPyObject.
| } | ||
| wrapped_meth = (PyArrayMethodObject *)PyTuple_GET_ITEM(item, 1); | ||
| if (!PyObject_TypeCheck(wrapped_meth, &PyArrayMethod_Type)) { | ||
| wrapped_meth = (PyArrayMethodObject *)PyTuple_GetItem(item, 1); |
There was a problem hiding this comment.
Not sure why the macro GET_ITEM causes problems here, something about the type of item?
There was a problem hiding this comment.
Me either, but using the macro failed on PyPy.
|
Would anyone like to review this? |
|
Added a commit to close #18 |
|
Anyone want to review this? |
| } PyBoundArrayMethodObject; | ||
|
|
||
| HPyType_HELPERS(PyBoundArrayMethodObject) | ||
| HPyType_LEGACY_HELPERS(PyBoundArrayMethodObject) |
There was a problem hiding this comment.
I guess this had to become a legacy type so that someone could call HPy_AsPyObject on it?
There was a problem hiding this comment.
🤔 good point. I don't think we ever specified that.
It is not required on CPython because any object is a PyObject anyway. So, it is always possible to convert.
It is not required for GraalPy because we would return a wrapper that emulates the PyObject.
Is it required for PyPy? If so, we should discuss that and maybe properly specify (and enforce spec in debug mode).
There was a problem hiding this comment.
PyPy works around it but it would be more efficient if the HELPER was correct.
| PyObject *py_range = HPy_AsPyObject(ctx, range); | ||
| CAPI_WARN("calling PyArray_Byteswap"); | ||
| new = PyArray_Byteswap(py_range, 1); | ||
| new = PyArray_Byteswap((PyArrayObject *)py_range, 1); |
There was a problem hiding this comment.
Should we perhaps do PyArrayObject *py_range = (PyArrayObject *) HPy_AsPyObject(ctx, range) where pyrange is defined?
There was a problem hiding this comment.
I think this was has fewer casts, since most places this is used prefer a PyObject*
| */ | ||
| bool python_byte_converters; | ||
| bool c_byte_converters; | ||
| npy_bool python_byte_converters; |
There was a problem hiding this comment.
npy_bool is the correct type used in the structs. This reduces the number of warnings
hodgestar
left a comment
There was a problem hiding this comment.
On the whole these changes look fairly unobjectionable to me. I asked some questions where I didn't understand things.
I would be awesome if someone from the GraalPy team could try this branch and confirm that it works for them, but if they're short on time at the moment, I think it would also be okay to merge it.
This isn't a production branch for anyone -- it's a place to push things forwards and get stuff working.
fangerer
left a comment
There was a problem hiding this comment.
Overall, looks good to me. Thanks you!
| int flags; | ||
| } PyArrayFlagsObject; | ||
|
|
||
| HPyType_HELPERS(PyArrayFlagsObject); |
There was a problem hiding this comment.
Do you know from the top of your head if PyArrayFlagsObject still needs to be legacy? It looks like it could be a pure HPy type but we just forgot to remove PyObject_HEAD.
There was a problem hiding this comment.
No, I don't know. We could check it in a follow-up PR
|
|
||
| NPY_NO_EXPORT PyObject * | ||
| PyArrayIdentityHash_GetItem(PyObject *cache_owner, PyArrayIdentityHash const *tb, PyObject *const *key) | ||
| PyArrayIdentityHash_GetItem(PyArrayIdentityHash const *tb, PyObject *cache_owner, PyObject *const *key) |
There was a problem hiding this comment.
Okay, makes sense. Seems that I was just not consistent in adding the cache_owner argument.
| .name = "numpy._IntegerAbstractDType", | ||
| .basicsize = sizeof(PyArray_Descr), | ||
| .flags = Py_TPFLAGS_DEFAULT, | ||
| .builtin_shape = HPyType_BuiltinShape_Legacy |
There was a problem hiding this comment.
If there is a HPyType(_LEGACY)_HELPERS(PyArray_Descr), we should use SHAPE(PyArray_Descr) here.
There was a problem hiding this comment.
right, but as far as I can tell there is no such use of the HEPLERS.
| } PyBoundArrayMethodObject; | ||
|
|
||
| HPyType_HELPERS(PyBoundArrayMethodObject) | ||
| HPyType_LEGACY_HELPERS(PyBoundArrayMethodObject) |
There was a problem hiding this comment.
🤔 good point. I don't think we ever specified that.
It is not required on CPython because any object is a PyObject anyway. So, it is always possible to convert.
It is not required for GraalPy because we would return a wrapper that emulates the PyObject.
Is it required for PyPy? If so, we should discuss that and maybe properly specify (and enforce spec in debug mode).
| NPY_ITER_ALLOCATE; | ||
|
|
||
| iter = NpyIter_MultiNew(2, op, flags, NPY_KEEPORDER, NPY_UNSAFE_CASTING, | ||
| iter = HNpyIter_MultiNew(ctx, 2, op, flags, NPY_KEEPORDER, NPY_UNSAFE_CASTING, |
There was a problem hiding this comment.
Yes, we probably just overlooked that.
Co-authored-by: Simon Cross <hodgestar+github@gmail.com>
|
@mattip How come this got closed rather than merged? |
|
I deleted the branch by mistake. It has been over a year with no action. I redid it as #21 |
These were almost all the fixes I needed to get a warning-less compilation on PyPy. I used this command line to build a wheel:
PyPy still cannot cleanly load numpy, I get this after running the command above, which suggests something is off with the metaclass handling somewhere: