fontforge/fontforge — pull request #1765 by tshinnic (2014-10-04 20:12:37+00:00)
Title: SFD unpickle usage outside of Python scripting crash

This change fixes the issue #1756 "why this script failed to generate
ttf for oxygen-fonts?"

There are a number of ways that embedded Python is used from FontForge,
such as script files, source from STDIN, entered via UI dialog, and
even via a socket (!?). And also it can be used as part of a convenient
way to encode/decode complex object data through SFD files, in font and
glyph `PickledData:` sections.

When native scripts were used with FontForge, the embedded Python was not
initialized for running, because it wasn't going to be used. :) Except,
if the script was opening SFD files that happened to contain `PickledData:`
sections, fontforge/sfd.c `SFD_GetFont()` and `SFDGetChar()` routines
would call `SFDUnPickle()` and thence `PyFF_UnPickleMeToObjects()`.
Trying to use the Python pickle/unpickle APIs without having initialized
Python would then crash.

This change simply adds a call to `FontForge_InitializeEmbeddedPython()`
to the initialization of the FF pickle/unpickle routines. It does not
address when the now needed Python cleanup at program end should happen.

This change should logically also address part of issue #1687, but it
seems that the problem there is not completely covered by this fix.

Tested with both Python 2 and 3, with native and Python scripts, and
using the UI.