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-41798: Allocate socket extension module CAPI on the heap#24126
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7033,16 +7033,36 @@ os_init(void) | ||
| } | ||
| #endif | ||
| static void | ||
| sock_free_api(PySocketModule_APIObject *capi) | ||
| { | ||
| Py_DECREF(capi->Sock_Type); | ||
| Py_DECREF(capi->error); | ||
| Py_DECREF(capi->timeout_error); | ||
| PyMem_Free(capi); | ||
| } | ||
| /* C API table - always add new things to the end for binary | ||
| compatibility. */ | ||
| static | ||
| PySocketModule_APIObject PySocketModuleAPI = | ||
| static void | ||
| sock_destroy_api(PyObject *capsule) | ||
| { | ||
| &sock_type, | ||
| NULL, | ||
| NULL | ||
| }; | ||
| void *capi = PyCapsule_GetPointer(capsule, PySocket_CAPSULE_NAME); | ||
| sock_free_api(capi); | ||
| } | ||
| static PySocketModule_APIObject * | ||
| sock_get_api(void) | ||
| { | ||
| PySocketModule_APIObject *capi = PyMem_Malloc(sizeof(PySocketModule_APIObject)); | ||
| if (capi == NULL){ | ||
| PyErr_NoMemory(); | ||
| return NULL; | ||
| } | ||
| capi->Sock_Type = (PyTypeObject *)Py_NewRef(&sock_type); | ||
| capi->error = Py_NewRef(PyExc_OSError); | ||
| capi->timeout_error = Py_NewRef(PyExc_TimeoutError); | ||
| return capi; | ||
| } | ||
| /* Initialize the _socket module. | ||
| @@ -7091,8 +7111,6 @@ PyInit__socket(void) | ||
| if (m == NULL) | ||
| return NULL; | ||
| Py_INCREF(PyExc_OSError); | ||
| PySocketModuleAPI.error = PyExc_OSError; | ||
| Py_INCREF(PyExc_OSError); | ||
| PyModule_AddObject(m, "error", PyExc_OSError); | ||
| socket_herror = PyErr_NewException("socket.herror", | ||
| @@ -7107,8 +7125,6 @@ PyInit__socket(void) | ||
| return NULL; | ||
| Py_INCREF(socket_gaierror); | ||
| PyModule_AddObject(m, "gaierror", socket_gaierror); | ||
| PySocketModuleAPI.timeout_error = PyExc_TimeoutError; | ||
| PyModule_AddObjectRef(m, "timeout", PyExc_TimeoutError); | ||
| Py_INCREF((PyObject *)&sock_type); | ||
| @@ -7129,10 +7145,24 @@ PyInit__socket(void) | ||
| PyModule_AddObject(m, "has_ipv6", has_ipv6); | ||
| /* Export C API */ | ||
| if (PyModule_AddObject(m, PySocket_CAPI_NAME, | ||
| PyCapsule_New(&PySocketModuleAPI, PySocket_CAPSULE_NAME, NULL) | ||
| ) != 0) | ||
| PySocketModule_APIObject *capi = sock_get_api(); | ||
| if (capi == NULL){ | ||
| Py_DECREF(m); | ||
| return NULL; | ||
| } | ||
| PyObject *capsule = PyCapsule_New(capi, | ||
| PySocket_CAPSULE_NAME, | ||
| sock_destroy_api); | ||
| if (capsule == NULL){ | ||
| sock_free_api(capi); | ||
| Py_DECREF(m); | ||
| return NULL; | ||
| } | ||
| if (PyModule_AddObject(m, PySocket_CAPI_NAME, capsule) < 0){ | ||
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. How about using ContributorAuthor 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 think we can leave it as it is for now. We can do a thorough clean up of the module init function when we convert it to multi-phase init. Ok? 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. No problem. | ||
| Py_DECREF(capsule); | ||
| Py_DECREF(m); | ||
| return NULL; | ||
| } | ||
| /* Address families (we only support AF_INET and AF_UNIX) */ | ||
| #ifdef AF_UNSPEC | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -342,7 +342,8 @@ typedef struct{ | ||
| */ | ||
| /* C API for usage by other Python modules */ | ||
| /* C API for usage by other Python modules. | ||
| * Always add new things to the end for binary compatibility. */ | ||
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 am not sure this note is correct or not. The binary compatibilty also depends how to use it, no? ContributorAuthor
| ||
| typedef struct{ | ||
| PyTypeObject *Sock_Type; | ||
| PyObject *error; | ||
Uh oh!
There was an error while loading. Please reload this page.