Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-1635741: Port resource extension module to multiphase initialization(PEP 489)#19252
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
8 commits Select commit Hold shift + click to select a range
274da20 Port resource extension module to multiphase initialization(PEP 489)
shihai1991 6b46c86 update code
shihai1991 90504f7 fix some potential refleaks
shihai1991 7a82976 Simplify the code
shihai1991 a0dcd68 remove file's ADD_INT macro
shihai1991 7add9ba Use PyModule_AddIntConstant to replace PyModule_AddIntMacro
shihai1991 41d6bf8 move position of claim of v
shihai1991 6fdb19a Fix style issues
shihai1991 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/Core and Builtins/2020-04-01-00-08-18.bpo-1635741.bhGWam.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Port :mod:`resource` to multiphase initialization (:pep:`489`). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -340,155 +340,174 @@ resource_methods[] ={ | ||
| /* Module initialization */ | ||
| static struct PyModuleDef resourcemodule ={ | ||
| PyModuleDef_HEAD_INIT, | ||
| "resource", | ||
| NULL, | ||
| -1, | ||
| resource_methods, | ||
| NULL, | ||
| NULL, | ||
| NULL, | ||
| NULL | ||
| }; | ||
| PyMODINIT_FUNC | ||
| PyInit_resource(void) | ||
| static int | ||
| resource_exec(PyObject *module) | ||
| { | ||
| PyObject *m, *v; | ||
| /* Create the module and add the functions */ | ||
| m = PyModule_Create(&resourcemodule); | ||
| if (m == NULL) | ||
| return NULL; | ||
| #define ADD_INT(module, value) \ | ||
| do{\ | ||
| if (PyModule_AddIntConstant(module, #value, value) < 0){\ | ||
| return -1; \ | ||
| } \ | ||
| } while (0) | ||
| /* Add some symbolic constants to the module */ | ||
| Py_INCREF(PyExc_OSError); | ||
| PyModule_AddObject(m, "error", PyExc_OSError); | ||
| if (PyModule_AddObject(module, "error", PyExc_OSError) < 0){ | ||
| Py_DECREF(PyExc_OSError); | ||
| return -1; | ||
| } | ||
| if (!initialized){ | ||
| if (PyStructSequence_InitType2(&StructRUsageType, | ||
| &struct_rusage_desc) < 0) | ||
| return NULL; | ||
| return -1; | ||
| } | ||
| Py_INCREF(&StructRUsageType); | ||
| PyModule_AddObject(m, "struct_rusage", | ||
| (PyObject*) &StructRUsageType); | ||
| if(PyModule_AddType(module, &StructRUsageType) < 0){ | ||
| return -1; | ||
| } | ||
| /* insert constants */ | ||
| #ifdef RLIMIT_CPU | ||
| PyModule_AddIntMacro(m, RLIMIT_CPU); | ||
| ADD_INT(module, RLIMIT_CPU); | ||
| #endif | ||
| #ifdef RLIMIT_FSIZE | ||
| PyModule_AddIntMacro(m, RLIMIT_FSIZE); | ||
| ADD_INT(module, RLIMIT_FSIZE); | ||
| #endif | ||
| #ifdef RLIMIT_DATA | ||
| PyModule_AddIntMacro(m, RLIMIT_DATA); | ||
| ADD_INT(module, RLIMIT_DATA); | ||
| #endif | ||
| #ifdef RLIMIT_STACK | ||
| PyModule_AddIntMacro(m, RLIMIT_STACK); | ||
| ADD_INT(module, RLIMIT_STACK); | ||
| #endif | ||
| #ifdef RLIMIT_CORE | ||
| PyModule_AddIntMacro(m, RLIMIT_CORE); | ||
| ADD_INT(module, RLIMIT_CORE); | ||
| #endif | ||
| #ifdef RLIMIT_NOFILE | ||
| PyModule_AddIntMacro(m, RLIMIT_NOFILE); | ||
| ADD_INT(module, RLIMIT_NOFILE); | ||
| #endif | ||
| #ifdef RLIMIT_OFILE | ||
| PyModule_AddIntMacro(m, RLIMIT_OFILE); | ||
| ADD_INT(module, RLIMIT_OFILE); | ||
| #endif | ||
| #ifdef RLIMIT_VMEM | ||
| PyModule_AddIntMacro(m, RLIMIT_VMEM); | ||
| ADD_INT(module, RLIMIT_VMEM); | ||
| #endif | ||
| #ifdef RLIMIT_AS | ||
| PyModule_AddIntMacro(m, RLIMIT_AS); | ||
| ADD_INT(module, RLIMIT_AS); | ||
| #endif | ||
| #ifdef RLIMIT_RSS | ||
| PyModule_AddIntMacro(m, RLIMIT_RSS); | ||
| ADD_INT(module, RLIMIT_RSS); | ||
| #endif | ||
| #ifdef RLIMIT_NPROC | ||
| PyModule_AddIntMacro(m, RLIMIT_NPROC); | ||
| ADD_INT(module, RLIMIT_NPROC); | ||
| #endif | ||
| #ifdef RLIMIT_MEMLOCK | ||
| PyModule_AddIntMacro(m, RLIMIT_MEMLOCK); | ||
| ADD_INT(module, RLIMIT_MEMLOCK); | ||
| #endif | ||
| #ifdef RLIMIT_SBSIZE | ||
| PyModule_AddIntMacro(m, RLIMIT_SBSIZE); | ||
| ADD_INT(module, RLIMIT_SBSIZE); | ||
| #endif | ||
| /* Linux specific */ | ||
| #ifdef RLIMIT_MSGQUEUE | ||
| PyModule_AddIntMacro(m, RLIMIT_MSGQUEUE); | ||
| ADD_INT(module, RLIMIT_MSGQUEUE); | ||
| #endif | ||
| #ifdef RLIMIT_NICE | ||
| PyModule_AddIntMacro(m, RLIMIT_NICE); | ||
| ADD_INT(module, RLIMIT_NICE); | ||
| #endif | ||
| #ifdef RLIMIT_RTPRIO | ||
| PyModule_AddIntMacro(m, RLIMIT_RTPRIO); | ||
| ADD_INT(module, RLIMIT_RTPRIO); | ||
| #endif | ||
| #ifdef RLIMIT_RTTIME | ||
| PyModule_AddIntMacro(m, RLIMIT_RTTIME); | ||
| ADD_INT(module, RLIMIT_RTTIME); | ||
| #endif | ||
| #ifdef RLIMIT_SIGPENDING | ||
| PyModule_AddIntMacro(m, RLIMIT_SIGPENDING); | ||
| ADD_INT(module, RLIMIT_SIGPENDING); | ||
| #endif | ||
| /* target */ | ||
| #ifdef RUSAGE_SELF | ||
| PyModule_AddIntMacro(m, RUSAGE_SELF); | ||
| ADD_INT(module, RUSAGE_SELF); | ||
| #endif | ||
| #ifdef RUSAGE_CHILDREN | ||
| PyModule_AddIntMacro(m, RUSAGE_CHILDREN); | ||
| ADD_INT(module, RUSAGE_CHILDREN); | ||
| #endif | ||
| #ifdef RUSAGE_BOTH | ||
| PyModule_AddIntMacro(m, RUSAGE_BOTH); | ||
| ADD_INT(module, RUSAGE_BOTH); | ||
| #endif | ||
| #ifdef RUSAGE_THREAD | ||
| PyModule_AddIntMacro(m, RUSAGE_THREAD); | ||
| ADD_INT(module, RUSAGE_THREAD); | ||
| #endif | ||
| /* FreeBSD specific */ | ||
| #ifdef RLIMIT_SWAP | ||
| PyModule_AddIntMacro(m, RLIMIT_SWAP); | ||
| ADD_INT(module, RLIMIT_SWAP); | ||
| #endif | ||
| #ifdef RLIMIT_SBSIZE | ||
| PyModule_AddIntMacro(m, RLIMIT_SBSIZE); | ||
| ADD_INT(module, RLIMIT_SBSIZE); | ||
| #endif | ||
| #ifdef RLIMIT_NPTS | ||
| PyModule_AddIntMacro(m, RLIMIT_NPTS); | ||
| ADD_INT(module, RLIMIT_NPTS); | ||
| #endif | ||
| PyObject *v; | ||
| if (sizeof(RLIM_INFINITY) > sizeof(long)){ | ||
| v = PyLong_FromLongLong((long long) RLIM_INFINITY); | ||
| } else | ||
| { | ||
| v = PyLong_FromLong((long) RLIM_INFINITY); | ||
| } | ||
| if (v){ | ||
| PyModule_AddObject(m, "RLIM_INFINITY", v); | ||
| if (!v){ | ||
| return -1; | ||
| } | ||
shihai1991 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| if (PyModule_AddObject(module, "RLIM_INFINITY", v) < 0){ | ||
| Py_DECREF(v); | ||
| return -1; | ||
| } | ||
| initialized = 1; | ||
| return m; | ||
| return 0; | ||
| #undef ADD_INT | ||
| } | ||
| static struct PyModuleDef_Slot resource_slots[] ={ | ||
| {Py_mod_exec, resource_exec}, | ||
| {0, NULL} | ||
| }; | ||
| static struct PyModuleDef resourcemodule ={ | ||
| PyModuleDef_HEAD_INIT, | ||
| .m_name = "resource", | ||
| .m_size = 0, | ||
| .m_methods = resource_methods, | ||
| .m_slots = resource_slots, | ||
| }; | ||
| PyMODINIT_FUNC | ||
| PyInit_resource(void) | ||
| { | ||
| return PyModuleDef_Init(&resourcemodule); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.