[Python-Dev] What do PyAPI_FUNC & PyAPI_DATA mean?

"Martin v. Löwis" martin at v.loewis.de
Tue Apr 24 09:27:33 CEST 2012

> What do they mean, exactly? From the name I would expect that they are a
> way of declaring a function or datum to be part of the API, but their
> usage seems to be more to do with linkage.

It means that they will be exported from the pythonXY.dll on Windows. In
Windows DLLs, it's not sufficient to make a symbol global (non-static)
to use it in an application, you also have to declare it as
__declspec(dllexport), or list it in the linker definition file (which
is not used today anymore).

Likewise, to use a symbol from a DLL, you also need to declare it
as __declspec(dllimport) in the using application. This will, in
particular, arrange for a slot in the indirect-jump assembler section
of the using DLL, so that the resulting executable will be position-
independent (except for this procedure linkage section).

As we have the same header files both for the implemenation and the
usage, this macro tricky is necessary to sometimes say dllexport,
sometimes dllimport.

Even though it's strictly needed on Windows, and strictly only for
API that we do want to expose, we apply it to all API that is
public on Unix (i.e. all Py* API), in order to avoid API being available
on Unix but not on Windows.


More information about the Python-Dev mailing list