Issue 1419652: PyImport_AppendInittab stores pointer to parameter (original) (raw)
Issue1419652
Created on 2006-01-31 03:19 by coder_5, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (4) | ||
---|---|---|
msg27388 - (view) | Author: coder_5 (coder_5) | Date: 2006-01-31 03:19 |
signature is: int PyImport_AppendInittab(char *name, void (*initfunc)(void)) if the 'name' pointer is freed or overwritten directly after the call to PyImport_AppendInittab, this call returns true but fails making the module known, and the interpreter crashes on PyFinalize(); this suggests that PyImport_AppendInittab stores the name pointer and uses it later, after leaving this function. this is undocumented and leads to crashes if name is freed in the meantime. (a typical c problem) this function is important to boost::python library to extend python with c++. workaround for c/c++ users: -malloc a char* for the name, -copy the modulename to name -call PyImport_AppendInittab with this name -DONT free name. (leaving a memory-leak) btw, 'char *' should be 'const char*', but this applies to most other Python API functions. | ||
msg27389 - (view) | Author: Georg Brandl (georg.brandl) * ![]() |
Date: 2006-02-17 18:47 |
Logged In: YES user_id=1188172 Should AppendInittab() itself malloc a char buffer? | ||
msg27390 - (view) | Author: coder_5 (coder_5) | Date: 2006-02-19 17:42 |
Logged In: YES user_id=1440178 I see 3 sollutions. 1) (bad) leave as is but document it. (user may free pointer to name AFTER PyFinalize() only) 2) (ok) let AppendInittab() malloc a buffer to store the name for later use there. (dont know about pythons mem alloc policy though) 3) (good) make it: int PyImport_AppendInittab(const char *name, void (*initfunc)(void)) AND realize 2) (malloc buffer). i would prefer to have the interface cleaned in a way that pointers to const* are declared as const. using const is good codingstyle and might even help the compiler on optimization. | ||
msg85153 - (view) | Author: Brett Cannon (brett.cannon) * ![]() |
Date: 2009-04-02 03:42 |
I made the char * a const char *. Committed in r71031 & r71033 for 2.x, r71034 for 3.x. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:15 | admin | set | github: 42850 |
2009-04-02 03:42:10 | brett.cannon | set | status: open -> closedresolution: fixedmessages: + |
2009-02-11 02:59:14 | ajaksu2 | set | assignee: loewis -> brett.cannonversions: + Python 2.7, - Python 2.4nosy: + brett.cannon |
2006-01-31 03:19:28 | coder_5 | create |