Skip to content

Conversation

@tynanford
Copy link
Collaborator

Branches off of #40 with @zhangt58 's changes. It will be easier to work on a branch in pyDevSup than off of Han's branch.

@pheest and I had a chat this morning and the outcome is we hope to work off this branch and get it merged to support the targeted python, OS, and numpy versions. python support is planned to be py >= 3.6

There are a few items still TBD

  • sync makehelper.py changes with @pheest 's work in win32
  • update fix with @pheest change in fc9d696
  • possibly more items? ...

@tynanford tynanford requested review from pheest and zhangt58 October 29, 2025 19:12
@tynanford tynanford changed the title Combine all python/numpy support PRs Combine all python/numpy support PRs, set minimum python version to 3.6 Oct 29, 2025
@tynanford
Copy link
Collaborator Author

Hi @zhangt58 and @pheest , this PR is ready for review.

Copy link
Collaborator

@zhangt58 zhangt58 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running OK in Debian 13.

Copy link
Collaborator

@pheest pheest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to make a single cast in dbfield.c:
PyArrayObject * array = (PyArrayObject *)arr;
and pass that to functions - rather than have multiple casts where these are applied.

I does not make any practical difference, but I wondered if there's a reason for not doing so?

@eddybl
Copy link

eddybl commented Nov 3, 2025

I can report that based on commit 5993a6c (latest commit on the branch) I was able to build the module successfully in our build enviornment for:

  • Ubuntu 20.04
  • Ubuntu 22.04
  • Ubuntu 24.04

(but I have not tested "using" it)

@tynanford
Copy link
Collaborator Author

Thanks all for the review. @pheest I changed to the single cast since I agree that is better. We have tested with rocky 8 and rocky 9 and numpy 1.26.4 and numpy 2.0.2

@zhangt58
Copy link
Collaborator

zhangt58 commented Nov 5, 2025

After reviewing dbfield.c, I fixed some potential memleak due to not calling [X]DECREF.

@mdavidsaver
Copy link
Collaborator

mdavidsaver commented Nov 5, 2025

I fixed some potential memleak due to not calling [X]DECREF.

I do not believe this is a leak. In fact, I think your change would introduce a double decrement on error.

Error handling with PyArray_NewFromDescr() is unfortunately not entirely consistent. Details with current numpy 2. I think unchanged from older versions.

The internal call stack I am looking at is: PyArray_NewFromDescr() -> PyArray_NewFromDescrAndBase() -> PyArray_NewFromDescr_int().

In PyArray_NewFromDescr(), there is one error path which does not decrement. subtype==NULL is a logic error which would be hard to miss.

PyArray_NewFromDescrAndBase() has no error cases.

Once into PyArray_NewFromDescr_int(), errors do Py_DECREF(descr);. eg. this case.

@mdavidsaver
Copy link
Collaborator

As a rule, python C api functions like PyArray_NewFromDescr() documented as "stealing" a reference will do so on error as well. I can not find a authoritative statement to support this now, so I can only point out one case where an exception to this rule is called out.

@mdavidsaver
Copy link
Collaborator

Error handling with PyArray_NewFromDescr() is unfortunately not entirely consistent

numpy/numpy#30152

Details with current numpy 2. I think unchanged from older versions.

Looks like this goes back to numpy 1.23. So not as far back as I first thought.

- PyArray_FromAny handles the refcnt of descr.
@zhangt58
Copy link
Collaborator

zhangt58 commented Nov 5, 2025

Error handling with PyArray_NewFromDescr() is unfortunately not entirely consistent

numpy/numpy#30152

Details with current numpy 2. I think unchanged from older versions.

Looks like this goes back to numpy 1.23. So not as far back as I first thought.

Calling Py_XDECREF should be safe after PyArray_NewFromDescr(), even if the descr is NULL. While for PyArray_FromAny, I removed XDECREF of descr after.

@tynanford
Copy link
Collaborator Author

Thanks @mdavidsaver and @zhangt58 !

Are we ready to merge this @pheest and @zhangt58 ?

@zhangt58
Copy link
Collaborator

@tynanford, it looks good to me, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants