summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2021-03-17 09:43:15 +1300
committerOlly Betts <olly@survex.com>2021-03-17 09:43:15 +1300
commit4e0997cd5a2360ccb639436783dc76b855d1ef59 (patch)
treee78ad6ffe01191004969822fdaa2c566f56dd749
parent6afc3e350462792baf7581d4ddafe80f66590c35 (diff)
downloadswig-4e0997cd5a2360ccb639436783dc76b855d1ef59.tar.gz
Conditionalise math.i for PHP
PHP already provides all the wrapped constants and all the wrapped functions except fabs() (PHP provides abs() instead). Rewrapping the constants causes warnings or errors (depending on PHP version) and the rewrapped functions seem to be hidden by the built-in versions, so only wrap fabs() for PHP. (Even a wrapper for fabs() seems of little use since abs() is already provided, but really math.i seems of little use more generally since any general purpose programming language will provide its own maths functions and constants - the key motivation here is to eliminate warnings and errors from running the testsuite.)
-rw-r--r--Examples/test-suite/li_math.i5
-rw-r--r--Lib/math.i13
2 files changed, 10 insertions, 8 deletions
diff --git a/Examples/test-suite/li_math.i b/Examples/test-suite/li_math.i
index 3aa3db303..db39cd3de 100644
--- a/Examples/test-suite/li_math.i
+++ b/Examples/test-suite/li_math.i
@@ -1,7 +1,2 @@
%module li_math
-#ifdef SWIGPHP
-// PHP already provides these functions with the same names, so just kill that
-// warning.
-%warnfilter(SWIGWARN_PARSE_KEYWORD);
-#endif
%include math.i
diff --git a/Lib/math.i b/Lib/math.i
index a37c92d19..ac8d9a6eb 100644
--- a/Lib/math.i
+++ b/Lib/math.i
@@ -9,6 +9,8 @@
#include <math.h>
%}
+#ifndef SWIGPHP /* PHP already provides all these functions except fabs() */
+
extern double cos(double x);
/* Cosine of x */
@@ -54,9 +56,6 @@ extern double pow(double x, double y);
extern double sqrt(double x);
/* Square root. x >= 0 */
-extern double fabs(double x);
-/* Absolute value of x */
-
extern double ceil(double x);
/* Smallest integer not less than x, as a double */
@@ -66,6 +65,13 @@ extern double floor(double x);
extern double fmod(double x, double y);
/* Floating-point remainder of x/y, with the same sign as x. */
+#endif
+
+extern double fabs(double x);
+/* Absolute value of x */
+
+#ifndef SWIGPHP /* PHP already provides these constants and it's an error to redefine them */
+
#define M_E 2.7182818284590452354
#define M_LOG2E 1.4426950408889634074
#define M_LOG10E 0.43429448190325182765
@@ -80,3 +86,4 @@ extern double fmod(double x, double y);
#define M_SQRT2 1.41421356237309504880
#define M_SQRT1_2 0.70710678118654752440
+#endif