| 1 |
PYTHON setup.py build_ext --inplace |
| 2 |
PYTHON -c "import callingconvention" |
| 3 |
|
| 4 |
######## setup.py ######## |
| 5 |
|
| 6 |
from distutils.core import setup |
| 7 |
from Cython.Distutils import build_ext |
| 8 |
from Cython.Distutils.extension import Extension |
| 9 |
|
| 10 |
setup( |
| 11 |
ext_modules = [ |
| 12 |
Extension("callingconvention", ["callingconvention.pyx", "external_callingconvention.c"]), |
| 13 |
], |
| 14 |
cmdclass={'build_ext': build_ext}, |
| 15 |
) |
| 16 |
|
| 17 |
######## callingconvention.pyx ######## |
| 18 |
# mode: compile |
| 19 |
|
| 20 |
cdef extern from "callingconvention.h": |
| 21 |
pass |
| 22 |
|
| 23 |
cdef extern int f1() |
| 24 |
cdef extern int __cdecl f2() |
| 25 |
cdef extern int __stdcall f3() |
| 26 |
cdef extern int __fastcall f4() |
| 27 |
|
| 28 |
cdef extern int (*p1)() |
| 29 |
cdef extern int (__cdecl *p2)() |
| 30 |
cdef extern int (__stdcall *p3)() |
| 31 |
cdef extern int (__fastcall *p4)() |
| 32 |
|
| 33 |
p1 = f1 |
| 34 |
p2 = f2 |
| 35 |
p3 = f3 |
| 36 |
p4 = f4 |
| 37 |
|
| 38 |
|
| 39 |
######## callingconvention.h ######## |
| 40 |
|
| 41 |
#define DLL_EXPORT |
| 42 |
#include "external_callingconvention.h" |
| 43 |
|
| 44 |
|
| 45 |
######## external_callingconvention.h ######## |
| 46 |
|
| 47 |
#ifndef DL_IMPORT |
| 48 |
#define DL_IMPORT(t) t |
| 49 |
#elif defined(DLL_EXPORT) |
| 50 |
#define DL_IMPORT(t) DL_EXPORT(t) |
| 51 |
#endif |
| 52 |
|
| 53 |
#ifdef __cplusplus |
| 54 |
extern "C" { |
| 55 |
#endif |
| 56 |
extern DL_IMPORT(int) f1(void); |
| 57 |
extern DL_IMPORT(int) __cdecl f2(void); |
| 58 |
extern DL_IMPORT(int) __stdcall f3(void); |
| 59 |
extern DL_IMPORT(int) __fastcall f4(void); |
| 60 |
extern DL_IMPORT(int) (*p1)(void); |
| 61 |
extern DL_IMPORT(int) (__cdecl *p2)(void); |
| 62 |
extern DL_IMPORT(int) (__stdcall *p3)(void); |
| 63 |
extern DL_IMPORT(int) (__fastcall *p4)(void); |
| 64 |
#ifdef __cplusplus |
| 65 |
} |
| 66 |
#endif |
| 67 |
|
| 68 |
######## external_callingconvention.c ######## |
| 69 |
#include <Python.h> |
| 70 |
|
| 71 |
#ifndef DL_EXPORT |
| 72 |
#define DL_EXPORT(t) t |
| 73 |
#endif |
| 74 |
|
| 75 |
|
| 76 |
#if !defined(WIN32) && !defined(MS_WINDOWS) |
| 77 |
#ifndef __stdcall |
| 78 |
#define __stdcall |
| 79 |
#endif |
| 80 |
#ifndef __cdecl |
| 81 |
#define __cdecl |
| 82 |
#endif |
| 83 |
#ifndef __fastcall |
| 84 |
#define __fastcall |
| 85 |
#endif |
| 86 |
#endif |
| 87 |
|
| 88 |
DL_EXPORT(int) f1(void) {return 0;} |
| 89 |
DL_EXPORT(int) __cdecl f2(void) {return 0;} |
| 90 |
DL_EXPORT(int) __stdcall f3(void) {return 0;} |
| 91 |
DL_EXPORT(int) __fastcall f4(void) {return 0;} |
| 92 |
DL_EXPORT(int) (*p1)(void); |
| 93 |
DL_EXPORT(int) (__cdecl *p2)(void); |
| 94 |
DL_EXPORT(int) (__stdcall *p3)(void); |
| 95 |
DL_EXPORT(int) (__fastcall *p4)(void); |