[capi-sig] C/API error handling
Campbell Barton
cbarton at metavr.com
Sun Jul 29 04:16:47 CEST 2007
In the Python C api is that your supposed to check every operation
succeeds. - Append, a new list, a new float etc.
This makes sense, since somebody could append to a list until the system
is out of memory.. or whatever.
The thing that bothers me is theres no good way to test the error cases.
For example in Blender3D and PyGame (the only 2 C API's I'v looked at) -
many checks for failed operations are missing. so its possible somebody
could run out of ram and crash the API with python.
for Blender3D or PyGame it probably dosnt matter a great deal, but in
other cases, you'd want to make sure that doing crazy stuff within an
exception (for example) wont crash the application.
Not just to look at the code and think it should work but actually run
the error case.
Is there any way to do this?
I was thinking there could be a debug mode where python/C API functions
like PyObject_New, PyList_Append etc randomly fail a percentage of the time.
Then you could run unit tests in a debugger and any crashes could be traced.
This isnt an exact approach but if the unit tests run enough times you
could be fairly sure its well tested (assuming the unit tests cover the
API).
Anyone tried this before or does something like this already exist?
--
Campbell J Barton (ideasman42)
More information about the capi-sig
mailing list