fontforge/fontforge — pull request #62 by dmeranda (2012-09-05 20:23:28+00:00)
Title: Python extension cleanup to remove leaks and crashes and other bad things

Lots of cleanup to the python extension code to remove crashes and leaks and similar bad things. Done in a private branch across several different commits, so it may be easier to examine the changes commit-by-commit. Summary of changes...

Factor out common "flaglist" code into its own source file (the type "struct flaglist" was defined multiple times in different pieces of code), so move it all to new source files flaglist.c and flaglist.h

Wrong hardcoded value for PYFF_FLAG_UNKNOWN

An unknown flag value in python should raise ValueError
exception, not TypeError

Replace magic numbers with enum values where available, and add
comments to cross-reference enums between python hooks and the
rest of the codebase.

Make python exception message more meaningful when an error
occurs parsing a list of flags

Tighten error code paths by:
* removing memory leaks,
* removing leaked (non-closed) file pointers,
* don't reference freed memory,
* always check for possible failure to parse flags.

Try to raise a python IOError when a file open/create fails if
enough context (and errno) is available.

Open potentially-binary files in binary mode.

General cleanup of python extension for leaks and crashes:
* create BAD_TAG macro to hide magic number 0xffffffff
* check arguments to python methods more carefully to prevent crashes
* prevent memory leaks when functions abort early due to errors
* fix some error message texts which refered to the wrong method name
* fix crashes caused by using PyTuple_GetItem instead of PySequence_GetItem
* fix reporting of argument errors in PyFF_Font_set_size_feature()
* retrieving wrong tuple index in PyFF_Font_set_size_feature()
* create BAD_FEATURE_LIST to hide magic pointer (FeatureScriptLangList*)(-1)
* avoid calling malloc for zero-bytes as malloc(0) may return NULL