[pypy-commit] pypy reflex-support: support for bool arrays (arg passing and returns)
wlav
noreply at buildbot.pypy.org
Thu Jun 28 01:13:56 CEST 2012
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r55866:8d7c4822975f
Date: 2012-06-27 11:58 -0700
http://bitbucket.org/pypy/pypy/changeset/8d7c4822975f/
Log: support for bool arrays (arg passing and returns)
diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -829,6 +829,7 @@
def _build_array_converters():
"NOT_RPYTHON"
array_info = (
+ ('b', rffi.sizeof(rffi.UCHAR), ("bool",)), # is debatable, but works ...
('h', rffi.sizeof(rffi.SHORT), ("short int", "short")),
('H', rffi.sizeof(rffi.USHORT), ("unsigned short int", "unsigned short")),
('i', rffi.sizeof(rffi.INT), ("int",)),
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -235,6 +235,9 @@
result = rffi.charp2str(ccpresult) # TODO: make it a choice to free
return space.wrap(result)
+class BoolPtrExecutor(PtrTypeExecutor):
+ _immutable_ = True
+ typecode = 'b' # really unsigned char, but this works ...
class ShortPtrExecutor(PtrTypeExecutor):
_immutable_ = True
@@ -422,6 +425,7 @@
_executors["void"] = VoidExecutor
_executors["void*"] = PtrTypeExecutor
_executors["bool"] = BoolExecutor
+_executors["bool*"] = BoolPtrExecutor
_executors["char"] = CharExecutor
_executors["char*"] = CStringExecutor
_executors["unsigned char"] = CharExecutor
diff --git a/pypy/module/cppyy/test/datatypes.cxx b/pypy/module/cppyy/test/datatypes.cxx
--- a/pypy/module/cppyy/test/datatypes.cxx
+++ b/pypy/module/cppyy/test/datatypes.cxx
@@ -19,6 +19,7 @@
m_double = -77.;
m_enum = kNothing;
+ m_bool_array2 = new bool[N];
m_short_array2 = new short[N];
m_ushort_array2 = new unsigned short[N];
m_int_array2 = new int[N];
@@ -30,6 +31,8 @@
m_double_array2 = new double[N];
for (int i = 0; i < N; ++i) {
+ m_bool_array[i] = bool(i%2);
+ m_bool_array2[i] = bool((i+1)%2);
m_short_array[i] = -1*i;
m_short_array2[i] = -2*i;
m_ushort_array[i] = 3u*i;
@@ -64,6 +67,7 @@
void cppyy_test_data::destroy_arrays() {
if (m_owns_arrays == true) {
+ delete[] m_bool_array2;
delete[] m_short_array2;
delete[] m_ushort_array2;
delete[] m_int_array2;
@@ -94,6 +98,8 @@
double cppyy_test_data::get_double() { return m_double; }
cppyy_test_data::what cppyy_test_data::get_enum() { return m_enum; }
+bool* cppyy_test_data::get_bool_array() { return m_bool_array; }
+bool* cppyy_test_data::get_bool_array2() { return m_bool_array2; }
short* cppyy_test_data::get_short_array() { return m_short_array; }
short* cppyy_test_data::get_short_array2() { return m_short_array2; }
unsigned short* cppyy_test_data::get_ushort_array() { return m_ushort_array; }
diff --git a/pypy/module/cppyy/test/datatypes.h b/pypy/module/cppyy/test/datatypes.h
--- a/pypy/module/cppyy/test/datatypes.h
+++ b/pypy/module/cppyy/test/datatypes.h
@@ -36,6 +36,8 @@
double get_double();
what get_enum();
+ bool* get_bool_array();
+ bool* get_bool_array2();
short* get_short_array();
short* get_short_array2();
unsigned short* get_ushort_array();
@@ -131,6 +133,8 @@
what m_enum;
// array types
+ bool m_bool_array[N];
+ bool* m_bool_array2;
short m_short_array[N];
short* m_short_array2;
unsigned short m_ushort_array[N];
diff --git a/pypy/module/cppyy/test/test_datatypes.py b/pypy/module/cppyy/test/test_datatypes.py
--- a/pypy/module/cppyy/test/test_datatypes.py
+++ b/pypy/module/cppyy/test/test_datatypes.py
@@ -63,6 +63,10 @@
# reding of array types
for i in range(self.N):
# reading of integer array types
+ assert c.m_bool_array[i] == bool(i%2)
+ assert c.get_bool_array()[i] == bool(i%2)
+ assert c.m_bool_array2[i] == bool((i+1)%2)
+ assert c.get_bool_array2()[i] == bool((i+1)%2)
assert c.m_short_array[i] == -1*i
assert c.get_short_array()[i] == -1*i
assert c.m_short_array2[i] == -2*i
More information about the pypy-commit
mailing list