summaryrefslogtreecommitdiff
path: root/ext/gmp/php_gmp_int.h
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2017-10-02 17:26:05 -0400
committerSara Golemon <pollita@php.net>2017-10-09 13:23:10 -0400
commite05cba0806fed049854d3569401935a524861750 (patch)
treec4cbb003eabaa24da9d8faf20f5d087a600ee646 /ext/gmp/php_gmp_int.h
parent39ded1d5f85ca3358cc8a52bb37e72a5eb5ce0db (diff)
downloadphp-git-e05cba0806fed049854d3569401935a524861750.tar.gz
Make GMP more usable by third-party extensions.
Export a PHPAPI function to return gmp_ce (and make the actual storage static). Provide gmp_object struct in header w/ inline accessor. Install php_gmp_int.h header. Remove unnecessary `#ifdef HAVE_GMP` checks.
Diffstat (limited to 'ext/gmp/php_gmp_int.h')
-rw-r--r--ext/gmp/php_gmp_int.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/ext/gmp/php_gmp_int.h b/ext/gmp/php_gmp_int.h
new file mode 100644
index 0000000000..9dd4c4d7f0
--- /dev/null
+++ b/ext/gmp/php_gmp_int.h
@@ -0,0 +1,31 @@
+#ifndef incl_PHP_GMP_INT_H
+#define incl_PHP_GMP_INT_H
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "php.h"
+#include <gmp.h>
+
+typedef struct _gmp_object {
+ mpz_t num;
+ zend_object std;
+} gmp_object;
+
+static inline gmp_object *php_gmp_object_from_zend_object(zend_object *zobj) {
+ return (gmp_object *)( ((char *)zobj) - XtOffsetOf(gmp_object, std) );
+}
+
+PHPAPI zend_class_entry *php_gmp_class_entry();
+
+/* GMP and MPIR use different datatypes on different platforms */
+#ifdef PHP_WIN32
+typedef zend_long gmp_long;
+typedef zend_ulong gmp_ulong;
+#else
+typedef long gmp_long;
+typedef unsigned long gmp_ulong;
+#endif
+
+#endif