[New-bugs-announce] [issue2921] enable embedding: declare/#define only py* symbols in #includes

Hallvard B Furuseth report at bugs.python.org
Mon May 19 23:29:23 CEST 2008

New submission from Hallvard B Furuseth <h.b.furuseth at usit.uio.no>:

It can be cumbersome to embed Python in a program which also #includes
a config.h from autoconf, because Python's and the program's autoconf
macros may interfere with each other.  Assuming it compiles at all,
both could define the same features, sometimes the same way and
sometimes differently.  Or one could be compiled with a feature macro
undefined and another with it defined, resulting in binary
incompatibility with the library which was compiled with the macro

So one has to do something like: put the Python calls in one set of
files, the calls to the embedding program in another set, and make
them communicate via some glue code.

For this reason, please do not declare/#define symbols other than
those starting with 'py' in the include files that an embedded program
needs.  Thus, do not #include at least pyconfig.h, pymath.h and
pyport.h as they are today.

Or to keep backwards compatibility, wrap such definitions in
which an application can #define before #including Python files.

Instead, you can #define/declare symbols that match the current
autoconf symbols but are prefixed with PY_, and make use of those in
#ifdefs in the include files.  The files defining this can hopefully
be autogenerated, e.g. generate a .c file like

    #include "pyconfig.h"
    int main() {
    #ifdef HAVE_WHATEVER

Things like acosh() from pymath.h which you define if the system lacks
it, could become something like this:

    #include <math.h> /* get acosh etc */
    extern double py_acosh(double); /* always present in python */
    #if !defined(PYTHON_NAMESPACE_ONLY) && !defined(HAVE_ACOSH)
    /* an other package's autoconf might do the same, so hide this
     * if requested */
    extern double acosh(double);
    #if !defined(PYTHON_NAMESPACE_ONLY) || defined(HAVE_ACOSH)
    #define py_acosh acosh /* optimization - hide wrapper function */

components: None
messages: 67078
nosy: hfuru
severity: normal
status: open
title: enable embedding: declare/#define only py* symbols in #includes
type: feature request
versions: Python 2.6

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list