[Python-Dev] Changing PyAPI_DATA(type) into PyAPI_DATA(type, variablename)?

Jukka.P.Laurila at nokia.com Jukka.P.Laurila at nokia.com
Wed Jan 9 17:26:08 CET 2008


Hello, python-dev!

One-liner summary: Would it be possible to change PyAPI_DATA(type) into
PyAPI_DATA(type, variablename) to help portability to funny platforms?

We've been working on porting the Python 2.5.1 core to the Symbian S60
smartphone platform. Unlike the previous 2.2.2 port, this time we're
trying really hard to keep our changes clean so that they could some day
be accepted into the main Python codebase. One problem we've encountered
is that Symbian doesn't properly support exporting data from a DLL, and
instead we must export a function that returns a pointer to the variable
in question, and hide this from client applications using a macro:

In a generated header, dataexports.h:

	#define Py_Verbose (*__DATAEXPORT_Py_Verbose())
 	extern __declspec(dllimport) int *__DATAEXPORT_Py_Verbose();

In a generated C file, dataexport.c:

	__declspec(dllexport) int *__DATAEXPORT_Py_Verbose() { return
&Py_Verbose; }

dataexports.h is included into Python.h when Py_BUILD_CORE isn't
defined.

Now, the problem is that we haven't figured out any way to define the
PyAPI_DATA macro in its one-argument form so that this scheme would
work, since when compiling client applications we'd like all the
PyAPI_DATA declarations to expand to nothing, and get the declarations
from dataexport.h instead. The best solution we've come up with is to
change PyAPI_DATA into a two-argument form and change all declarations
accordingly. Whether to export data with this mechanism or directly
could be a pyconfig.h option, DATA_EXPORT_AS_FUNCTIONS (or
HAVE_DATA_EXPORT?). Briefly the changes would touch:

pyport.h:
	#ifdef Py_BUILD_CORE
	#define PyAPI_DATA(RTYPE,NAME) extern RTYPE NAME // data item
not exported from the Python DLL
	#else 
	#define PyAPI_DATA(RTYPE,NAME) // PyAPI_DATA can be blank since
then the real declarations come from dataexports.h
	#endif

pydebug.h and all other files that declare exported data:
	PyAPI_DATA(int) Py_VerboseFlag;
	-->
	PyAPI_DATA(int, Py_VerboseFlag)

In addition, complex types such as function pointers and arrays would
need to be typedef'ed, e.g.:

	PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE
*, char *);
	-->
	typedef char *(*t_PyOS_ReadlineFunctionPointer)(FILE *, FILE *,
char *);
	PyAPI_DATA(t_PyOS_ReadlineFunctionPointer,
PyOS_ReadlineFunctionPointer)

and multiple PyAPI_DATA declarations on a line would need to be split to
several PyAPI_DATA declarations.

If this change isn't acceptable then we'd pretty much have to fork this
aspect of the interpreter - either by just maintaining a patch that's
applied to the headers or by making a preprocessor that fixes the
headers on the fly.

Does this sound reasonable? Any better ideas?

-Jukka


More information about the Python-Dev mailing list