Skip to content

GH-29021: Convert limited API examples to multi-phase init (PEP 489) #29027

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions numpy/_core/tests/examples/limited_api/limited_api1.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@
#include <numpy/arrayobject.h>
#include <numpy/ufuncobject.h>

static PyModuleDef moduledef = {
static int
_limited_api1_exec(void)
{
import_array1(-1);
import_umath1(-1);
return 0;
}

static struct PyModuleDef_Slot limited_api1_slots[] = {
{Py_mod_exec, _limited_api1_exec},
#if PY_VERSION_HEX >= 0x030c00f0 // Python 3.12+
{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
#endif
#if PY_VERSION_HEX >= 0x030d00f0 // Python 3.13+
// signal that this module supports running without an active GIL
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
#endif
{0, NULL},
};

static struct PyModuleDef moduledef = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "limited_api1"
.m_name = "limited_api1",
.m_size = 0,
.m_slots = limited_api1_slots,
};

PyMODINIT_FUNC PyInit_limited_api1(void)
{
import_array();
import_umath();
return PyModule_Create(&moduledef);
return PyModuleDef_Init(&moduledef);
}
30 changes: 25 additions & 5 deletions numpy/_core/tests/examples/limited_api/limited_api_latest.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,34 @@
#include <numpy/arrayobject.h>
#include <numpy/ufuncobject.h>

static PyModuleDef moduledef = {
static int
_limited_api_latest_exec(void)
{
import_array1(-1);
import_umath1(-1);
return 0;
}

static struct PyModuleDef_Slot limited_api_latest_slots[] = {
{Py_mod_exec, _limited_api_latest_exec},
#if PY_VERSION_HEX >= 0x030c00f0 // Python 3.12+
{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
#endif
#if PY_VERSION_HEX >= 0x030d00f0 // Python 3.13+
// signal that this module supports running without an active GIL
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
#endif
{0, NULL},
};

static struct PyModuleDef moduledef = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "limited_api_latest"
.m_name = "limited_api_latest",
.m_size = 0,
.m_slots = limited_api_latest_slots,
};

PyMODINIT_FUNC PyInit_limited_api_latest(void)
{
import_array();
import_umath();
return PyModule_Create(&moduledef);
return PyModuleDef_Init(&moduledef);
}
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy