bpo-41798: Allocate the _curses._C_API on the heap memory.#24186
bpo-41798: Allocate the _curses._C_API on the heap memory.#24186vstinner merged 3 commits intopython:masterfrom
Conversation
| return NULL; | ||
| ModDict = d; /* For PyCurses_InitScr to use later */ | ||
|
|
||
| void **PyCurses_API = PyMem_Calloc(PyCurses_API_pointers, sizeof(void *)); |
There was a problem hiding this comment.
This API is weird. Would you be interested to add a structure of 4 pointers? Something like PyDateTime_CAPI.
The 4 pointers are used by:
#define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
#define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
#define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
Maybe you can name the 4 members as:
PyTypeObject *Window_Type
int SetupTermCalled(void)
int Initialised(void)
int InitialisedColor(void)
Or I can merge this PR and then you work on a new PR to add a structure. As you want, tell me what do you prefer ;-)
There was a problem hiding this comment.
Or I can merge this PR and then you work on a new PR to add a structure. As you want, tell me what do you prefer ;-)
Oh, I perfer to use another PR to add this structure in this weekend :)
| c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME, | ||
| curses_destructor); | ||
| if (c_api_object == NULL) { | ||
| PyMem_Free(PyCurses_API); |
There was a problem hiding this comment.
Hum, there is no a refleak here. Does it work to call curses_destructor() here?
There was a problem hiding this comment.
Oh, thanks, updated.
Weird. ./python Lib/test/regrtest.py -ucurses test_curses -vv -R 3:3 can not catch this refleak.
There was a problem hiding this comment.
Does it work to call curses_destructor() here?
No, it's can not work because capsule object haven't created
There was a problem hiding this comment.
Weird. ./python Lib/test/regrtest.py -ucurses test_curses -vv -R 3:3 can not catch this refleak.
test_curses doesn't test memory allocation failures. See _testcapi.set_nomemory() for that.
There was a problem hiding this comment.
Ah, and _curses doesn't use multiphase init API yet.
https://bugs.python.org/issue41798