aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/python_builtin.i
diff options
context:
space:
mode:
Diffstat (limited to 'Examples/test-suite/python_builtin.i')
-rw-r--r--Examples/test-suite/python_builtin.i32
1 files changed, 27 insertions, 5 deletions
diff --git a/Examples/test-suite/python_builtin.i b/Examples/test-suite/python_builtin.i
index d4e245dc4..994c625e8 100644
--- a/Examples/test-suite/python_builtin.i
+++ b/Examples/test-suite/python_builtin.i
@@ -2,10 +2,12 @@
%module python_builtin
+// throw is invalid in C++17 and later, only SWIG to use it
+#define TESTCASE_THROW1(T1) throw(T1)
+#define TESTCASE_THROW2(T1, T2) throw(T1, T2)
%{
-#if defined(_MSC_VER)
- #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
-#endif
+#define TESTCASE_THROW1(T1)
+#define TESTCASE_THROW2(T1, T2)
%}
%inline %{
@@ -192,13 +194,13 @@ void Dealloc2Destroyer(PyObject *v) {
return size;
}
- int __getitem__(Py_ssize_t n) throw (std::out_of_range) {
+ int __getitem__(Py_ssize_t n) TESTCASE_THROW1(std::out_of_range) {
if (n >= (int)size)
throw std::out_of_range("Index too large");
return numbers[n];
}
- SimpleArray __getitem__(PySliceObject *slice) throw (std::out_of_range, std::invalid_argument) {
+ SimpleArray __getitem__(PySliceObject *slice) TESTCASE_THROW2(std::out_of_range, std::invalid_argument) {
if (!PySlice_Check(slice))
throw std::invalid_argument("Slice object expected");
Py_ssize_t i, j, step;
@@ -223,3 +225,23 @@ void Dealloc2Destroyer(PyObject *v) {
}
};
%}
+
+// Test 7 mapping to Python's pow
+%pybinoperator(__pow__, ANumber::power, ternaryfunc, nb_power);
+
+%inline %{
+class ANumber {
+ int num;
+public:
+ ANumber(int d = 0) : num(d) {}
+ ANumber __pow__(const ANumber &other, const ANumber *x = 0) const {
+ int val = (int)pow(num, other.num);
+ val = x ? val % x->num : val;
+ return ANumber(val);
+ }
+ int Value() const {
+ return num;
+ }
+};
+%}
+