-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-86542: New C-APIs to simplify module attribute declaration #23286
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
Changes from 1 commit
436c1b0
d93f2da
a1c8240
a277939
22e4f7f
31f8189
366e810
bb41d82
751c560
c34a4df
3e50f44
00236fe
8458120
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,40 +75,44 @@ typedef struct PyModuleDef_Slot{ | |
| struct PyModuleConst_Def; | ||
| #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03100000 | ||
| /* New in 3.10 */ | ||
| enum PyModuleConst_type { | ||
| PyModuleConst_none_type = 1, | ||
| PyModuleConst_long_type = 2, | ||
| PyModuleConst_bool_type = 3, | ||
| PyModuleConst_double_type = 4, | ||
| PyModuleConst_string_type = 5, | ||
| PyModuleConst_call_type = 6, | ||
| enum _PyModuleConst_type { | ||
| _PyModuleConst_none_type = 1, | ||
| _PyModuleConst_long_type = 2, | ||
| _PyModuleConst_ulong_type = 3, | ||
| _PyModuleConst_bool_type = 4, | ||
| _PyModuleConst_double_type = 5, | ||
| _PyModuleConst_string_type = 6, | ||
| _PyModuleConst_call_type = 7, | ||
| }; | ||
|
|
||
| typedef struct PyModuleConst_Def { | ||
| const char *name; | ||
| enum PyModuleConst_type type; | ||
| enum _PyModuleConst_type type; | ||
| union { | ||
| const char *m_str; | ||
| long m_long; | ||
| unsigned long m_ulong; | ||
| double m_double; | ||
| PyObject* (*m_call)(void); | ||
| PyObject* (*m_call)(PyObject *module); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how to make this member future-proof in term of stable ABI. We should try to put a max_align_t inside, but this type requires C11. GCC defines it with: Maybe we can at least put long long and long double:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only issue I found here :) |
||
| } value; | ||
| } PyModuleConst_Def; | ||
|
|
||
| PyAPI_FUNC(int) PyModule_AddConstants(PyObject *, PyModuleConst_Def *); | ||
|
|
||
| #define PyModuleConst_None(name) \ | ||
| {(name), PyModuleConst_none_type, {.m_long=0}} | ||
| {(name), _PyModuleConst_none_type, {.m_long=0}} | ||
| #define PyModuleConst_Long(name, value) \ | ||
| {(name), PyModuleConst_long_type, {.m_long=(value)}} | ||
| {(name), _PyModuleConst_long_type, {.m_long=(value)}} | ||
| #define PyModuleConst_ULong(name, value) \ | ||
| {(name), _PyModuleConst_ulong_type, {.m_ulong=(value)}} | ||
| #define PyModuleConst_Bool(name, value) \ | ||
| {(name), PyModuleConst_bool_type, {.m_long=(value)}} | ||
| {(name), _PyModuleConst_bool_type, {.m_long=(value)}} | ||
| #define PyModuleConst_Double(name, value) \ | ||
| {(name), PyModuleConst_double_type, {.m_double=(value)}} | ||
| {(name), _PyModuleConst_double_type, {.m_double=(value)}} | ||
| #define PyModuleConst_String(name, value) \ | ||
| {(name), PyModuleConst_string_type, {.m_string=(value)}} | ||
| {(name), _PyModuleConst_string_type, {.m_str=(value)}} | ||
| #define PyModuleConst_Call(name, value) \ | ||
| {(name), PyModuleConst_call_type, {.m_call=(value)}} | ||
| {(name), _PyModuleConst_call_type, {.m_call=(value)}} | ||
|
|
||
| #define PyModuleConst_LongMacro(m) PyModuleConst_Long(#m, m) | ||
| #define PyModuleConst_StringMacro(m) PyModuleConst_String(#m, m) | ||
|
|
||
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.
nitpick:
static PyObject *in here.