Repository navigation
gh-162350: Add AC vectorcall for datetime.timedelta / datetime.timezone - #162500
Conversation
| 0, /* tp_alloc */ | ||
| delta_new, /* tp_new */ | ||
| .tp_vectorcall = delta_vectorcall, | ||
| 0, /* tp_free */ |
There was a problem hiding this comment.
This is no longer tp_free, move it before tp_vectorcall.
There was a problem hiding this comment.
Right. Moved tp_vectorcall to the end.
|
This exposes a reference count issue in |
|
Hmm, I think we'll have to revert for the time being. |
|
I made a patch to add strong references to arguments of |
|
Created a patch PR in #162748 (linked to the same issue number of this PR). |
…162748) Issue introduced in commit 1994e3f, raised in comment #162500 (comment). `delta_new_impl()` calls `accum()`, which in turn calls `PyNumber_Multiply()` and `PyNumber_Add()`, whose arguments could be a subclass of int or float that overloads `__mul__`/`__add__` with arbitrary Python code. `delta_new_impl()` calls `accum()` for 7 times in sequnce, with each of the 7 timeunit arguments, all with borrowed references, from `microseconds` to `weeks`. Chances are that those arbitrary Python code could release strong references of one of the 7 timeunit arguments. When `accum()` is called with an argument whose last references has been destroyed, it operates on a dangling pointer. Should let `delta_new_impl()` hold strong references of its arguments to avoid being released early.
Add
@vectorcalltodatetime.timedelta.__new__anddatetime.timezone.__new__. There is no change of exception text for bad arguments.Benchmark:
Details