From 738f7f860c08f1322d09c72a3db44308f4a16404 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 12 Feb 2016 22:57:38 +0200 Subject: Added Cython sample project. --- test cases/python3/3 cython/libdir/cstorer.pxd | 9 +++++++++ test cases/python3/3 cython/libdir/meson.build | 18 ++++++++++++++++++ test cases/python3/3 cython/libdir/storer.c | 24 ++++++++++++++++++++++++ test cases/python3/3 cython/libdir/storer.h | 8 ++++++++ test cases/python3/3 cython/libdir/storer.pyx | 16 ++++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 test cases/python3/3 cython/libdir/cstorer.pxd create mode 100644 test cases/python3/3 cython/libdir/meson.build create mode 100644 test cases/python3/3 cython/libdir/storer.c create mode 100644 test cases/python3/3 cython/libdir/storer.h create mode 100644 test cases/python3/3 cython/libdir/storer.pyx (limited to 'test cases/python3/3 cython/libdir') diff --git a/test cases/python3/3 cython/libdir/cstorer.pxd b/test cases/python3/3 cython/libdir/cstorer.pxd new file mode 100644 index 000000000..7b730fc75 --- /dev/null +++ b/test cases/python3/3 cython/libdir/cstorer.pxd @@ -0,0 +1,9 @@ + +cdef extern from "storer.h": + ctypedef struct Storer: + pass + + Storer* storer_new(); + void storer_destroy(Storer *s); + int storer_get_value(Storer *s); + void storer_set_value(Storer *s, int v); diff --git a/test cases/python3/3 cython/libdir/meson.build b/test cases/python3/3 cython/libdir/meson.build new file mode 100644 index 000000000..e5cfc8604 --- /dev/null +++ b/test cases/python3/3 cython/libdir/meson.build @@ -0,0 +1,18 @@ +pxd_c = custom_target('cstorer_pxd', + output : 'cstorer_pxd.c', + input : 'cstorer.pxd', + command : [cython, '@INPUT@', '-o', '@OUTPUT@'], +) + +pyx_c = custom_target('storer_pyx', + output : 'storer_pyx.c', + input : 'storer.pyx', + command : [cython, '@INPUT@', '-o', '@OUTPUT@'], +) + +slib = shared_library('storer', + 'storer.c', pxd_c, pyx_c, + name_prefix : '', + dependencies : py3_dep) + +pydir = meson.current_build_dir() diff --git a/test cases/python3/3 cython/libdir/storer.c b/test cases/python3/3 cython/libdir/storer.c new file mode 100644 index 000000000..0199bb850 --- /dev/null +++ b/test cases/python3/3 cython/libdir/storer.c @@ -0,0 +1,24 @@ +#include"storer.h" +#include + +struct _Storer { + int value; +}; + +Storer* storer_new() { + Storer *s = malloc(sizeof(struct _Storer)); + s->value = 0; + return s; +} + +void storer_destroy(Storer *s) { + free(s); +} + +int storer_get_value(Storer *s) { + return s->value; +} + +void storer_set_value(Storer *s, int v) { + s->value = v; +} diff --git a/test cases/python3/3 cython/libdir/storer.h b/test cases/python3/3 cython/libdir/storer.h new file mode 100644 index 000000000..4f7191711 --- /dev/null +++ b/test cases/python3/3 cython/libdir/storer.h @@ -0,0 +1,8 @@ +#pragma once + +typedef struct _Storer Storer; + +Storer* storer_new(); +void storer_destroy(Storer *s); +int storer_get_value(Storer *s); +void storer_set_value(Storer *s, int v); diff --git a/test cases/python3/3 cython/libdir/storer.pyx b/test cases/python3/3 cython/libdir/storer.pyx new file mode 100644 index 000000000..6ad6830e3 --- /dev/null +++ b/test cases/python3/3 cython/libdir/storer.pyx @@ -0,0 +1,16 @@ +cimport cstorer + +cdef class Storer: + cdef cstorer.Storer* _c_storer + + def __cinit__(self): + self._c_storer = cstorer.storer_new() + + def __dealloc__(self): + cstorer.storer_destroy(self._c_storer) + + cpdef int get_value(self): + return cstorer.storer_get_value(self._c_storer) + + cpdef void set_value(self, int value): + cstorer.storer_set_value(self._c_storer, value) -- cgit v1.2.3 From 16b9a522352560f44d418053af9e795c61efd691 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 14 Feb 2016 18:32:58 +0200 Subject: Fix cython to work on platforms other than latest Ubuntu. --- test cases/python3/3 cython/libdir/meson.build | 8 +------- test cases/python3/3 cython/libdir/storer.pyx | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'test cases/python3/3 cython/libdir') diff --git a/test cases/python3/3 cython/libdir/meson.build b/test cases/python3/3 cython/libdir/meson.build index e5cfc8604..baa4c1dbf 100644 --- a/test cases/python3/3 cython/libdir/meson.build +++ b/test cases/python3/3 cython/libdir/meson.build @@ -1,9 +1,3 @@ -pxd_c = custom_target('cstorer_pxd', - output : 'cstorer_pxd.c', - input : 'cstorer.pxd', - command : [cython, '@INPUT@', '-o', '@OUTPUT@'], -) - pyx_c = custom_target('storer_pyx', output : 'storer_pyx.c', input : 'storer.pyx', @@ -11,7 +5,7 @@ pyx_c = custom_target('storer_pyx', ) slib = shared_library('storer', - 'storer.c', pxd_c, pyx_c, + 'storer.c', pyx_c, name_prefix : '', dependencies : py3_dep) diff --git a/test cases/python3/3 cython/libdir/storer.pyx b/test cases/python3/3 cython/libdir/storer.pyx index 6ad6830e3..ed551dc5f 100644 --- a/test cases/python3/3 cython/libdir/storer.pyx +++ b/test cases/python3/3 cython/libdir/storer.pyx @@ -12,5 +12,5 @@ cdef class Storer: cpdef int get_value(self): return cstorer.storer_get_value(self._c_storer) - cpdef void set_value(self, int value): + cpdef set_value(self, int value): cstorer.storer_set_value(self._c_storer, value) -- cgit v1.2.3 From efceac497fa2702124398b2712761015d9a1c78a Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 26 Feb 2016 21:04:11 +0200 Subject: Python extension module finally works on Windows. --- test cases/python3/2 extmodule/ext/meson.build | 3 +++ test cases/python3/2 extmodule/meson.build | 5 ++++- test cases/python3/3 cython/libdir/meson.build | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) (limited to 'test cases/python3/3 cython/libdir') diff --git a/test cases/python3/2 extmodule/ext/meson.build b/test cases/python3/2 extmodule/ext/meson.build index 04c0592c2..7d67953cb 100644 --- a/test cases/python3/2 extmodule/ext/meson.build +++ b/test cases/python3/2 extmodule/ext/meson.build @@ -1,6 +1,9 @@ if host_machine.system() == 'darwin' # Default suffix is 'dylib' but Python does not use for extensions. suffix = 'so' +elif host_machine.system() == 'windows' + # On Windows the extension is pyd for some unexplainable reason. + suffix = 'pyd' else suffix = [] endif diff --git a/test cases/python3/2 extmodule/meson.build b/test cases/python3/2 extmodule/meson.build index a86a1222c..858bbea9f 100644 --- a/test cases/python3/2 extmodule/meson.build +++ b/test cases/python3/2 extmodule/meson.build @@ -1,4 +1,7 @@ -project('Python extension module', 'c') +project('Python extension module', 'c', + default_options : ['buildtype=release']) +# Because Windows Python ships only with optimized libs, +# we must build this project the same way. py3_dep = dependency('python3') diff --git a/test cases/python3/3 cython/libdir/meson.build b/test cases/python3/3 cython/libdir/meson.build index baa4c1dbf..5c0352e88 100644 --- a/test cases/python3/3 cython/libdir/meson.build +++ b/test cases/python3/3 cython/libdir/meson.build @@ -1,3 +1,13 @@ +if host_machine.system() == 'darwin' + # Default suffix is 'dylib' but Python does not use for extensions. + suffix = 'so' +elif host_machine.system() == 'windows' + # On Windows the extension is pyd for some unexplainable reason. + suffix = 'pyd' +else + suffix = [] +endif + pyx_c = custom_target('storer_pyx', output : 'storer_pyx.c', input : 'storer.pyx', @@ -7,6 +17,7 @@ pyx_c = custom_target('storer_pyx', slib = shared_library('storer', 'storer.c', pyx_c, name_prefix : '', + name_suffix : suffix, dependencies : py3_dep) pydir = meson.current_build_dir() -- cgit v1.2.3