Skip to content

Conversation

@kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Jan 24, 2026


#define PyDateTime_IMPORT \
PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)
static inline PyDateTime_CAPI *
Copy link
Member

Choose a reason for hiding this comment

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

Is it important that the function is a static inline function? Declaring the function as an "opaque" function with PyAPI_FUNC() would hide implementation details (move it to Modules/_datetimemodule.c).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it important that the function is a static inline function?

No, it was just easier to do it this way, OTOH PyDateTimeAPI is already exposed so moving this to a api function doesn't really hides any implementation details.

Copy link
Member

Choose a reason for hiding this comment

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

I'm a little bit worried by the usage of _Py_atomic in the public C API. I'm not sure that it's available in all compilers/use cases. Currently, it's only used if Py_GIL_DISABLED is defined by a few header files (ex: dictobject.h, refcount.h).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'm not sure that it's available in all compilers/use cases. Currently, it's only used if Py_GIL_DISABLED is defined by a few header files (ex: dictobject.h, refcount.h).

No, see pylock.h. It is used in normal builds as well for PyMutex_Lock

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems fine to me to move it to a .c file. The function will need to take a pointer &PyDateTimeAPI though because PyDateTimeAPI is a static variable declared in a header file (ugh), so there's a unique variable per translation unit.

Copy link
Member

Choose a reason for hiding this comment

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

No, see pylock.h. It is used in normal builds as well for PyMutex_Lock

Oh, I didn't notice these functions, you're right. In this case, I have no longer concerns about _Py_atomic usage in a static inline function.

@kumaraditya303 kumaraditya303 marked this pull request as ready for review February 2, 2026 16:27
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants