summaryrefslogtreecommitdiff
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
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.
-rw-r--r--NEWS3
-rw-r--r--ext/gmp/config.m41
-rw-r--r--ext/gmp/config.w321
-rw-r--r--ext/gmp/gmp.c16
-rw-r--r--ext/gmp/php_gmp.h17
-rw-r--r--ext/gmp/php_gmp_int.h31
6 files changed, 42 insertions, 27 deletions
diff --git a/NEWS b/NEWS
index 201f1209ac..d5247a9369 100644
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,9 @@ PHP NEWS
- GD:
. Added support for WebP in imagecreatefromstring() (Andreas Treichel, cmb).
+- GMP:
+ . Export internal structures and accessor helpers for GMP object. (Sara)
+
- LDAP:
. Added ldap_exop_refresh helper for EXOP REFRESH operation with dds overlay.
(Come)
diff --git a/ext/gmp/config.m4 b/ext/gmp/config.m4
index 22cca7eaf2..a1c565bf4e 100644
--- a/ext/gmp/config.m4
+++ b/ext/gmp/config.m4
@@ -23,6 +23,7 @@ if test "$PHP_GMP" != "no"; then
PHP_ADD_LIBRARY_WITH_PATH(gmp, $GMP_DIR/$PHP_LIBDIR, GMP_SHARED_LIBADD)
PHP_ADD_INCLUDE($GMP_DIR/include)
+ PHP_INSTALL_HEADERS([ext/gmp/php_gmp_int.h])
PHP_NEW_EXTENSION(gmp, gmp.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
PHP_SUBST(GMP_SHARED_LIBADD)
diff --git a/ext/gmp/config.w32 b/ext/gmp/config.w32
index 7ea36150b2..ca85a2e44b 100644
--- a/ext/gmp/config.w32
+++ b/ext/gmp/config.w32
@@ -7,6 +7,7 @@ if (PHP_GMP != "no") {
if (CHECK_LIB("mpir_a.lib", "gmp", PHP_GMP) &&
CHECK_HEADER_ADD_INCLUDE("gmp.h", "CFLAGS_GMP", PHP_GMP + ";" + PHP_PHP_BUILD + "\\include\\mpir")) {
EXTENSION("gmp", "gmp.c", null, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
+ PHP_INSTALL_HEADERS("ext/gmp", "php_gmp_int.h");
AC_DEFINE('HAVE_GMP', 1, 'GMP support');
AC_DEFINE('HAVE_MPIR', 1, 'MPIR support');
} else {
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c
index 9fcf9c14d7..61fb37a1e2 100644
--- a/ext/gmp/gmp.c
+++ b/ext/gmp/gmp.c
@@ -23,13 +23,12 @@
#include "php.h"
#include "php_ini.h"
#include "php_gmp.h"
+#include "php_gmp_int.h"
#include "ext/standard/info.h"
#include "ext/standard/php_var.h"
#include "zend_smart_str_public.h"
#include "zend_exceptions.h"
-#if HAVE_GMP
-
#include <gmp.h>
/* Needed for gmp_random() */
@@ -220,13 +219,12 @@ ZEND_TSRMLS_CACHE_DEFINE()
ZEND_GET_MODULE(gmp)
#endif
-zend_class_entry *gmp_ce;
+static zend_class_entry *gmp_ce;
static zend_object_handlers gmp_object_handlers;
-typedef struct _gmp_object {
- mpz_t num;
- zend_object std;
-} gmp_object;
+zend_class_entry *php_gmp_class_entry() {
+ return gmp_ce;
+}
typedef struct _gmp_temp {
mpz_t num;
@@ -252,7 +250,7 @@ typedef struct _gmp_temp {
(Z_TYPE_P(zval) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zval), gmp_ce))
#define GET_GMP_OBJECT_FROM_OBJ(obj) \
- ((gmp_object *) ((char *) (obj) - XtOffsetOf(gmp_object, std)))
+ php_gmp_object_from_zend_object(obj)
#define GET_GMP_OBJECT_FROM_ZVAL(zv) \
GET_GMP_OBJECT_FROM_OBJ(Z_OBJ_P(zv))
@@ -2088,8 +2086,6 @@ ZEND_FUNCTION(gmp_scan1)
}
/* }}} */
-#endif /* HAVE_GMP */
-
/*
* Local variables:
* tab-width: 4
diff --git a/ext/gmp/php_gmp.h b/ext/gmp/php_gmp.h
index 903c68ee5e..971d6593ec 100644
--- a/ext/gmp/php_gmp.h
+++ b/ext/gmp/php_gmp.h
@@ -19,8 +19,6 @@
#ifndef PHP_GMP_H
#define PHP_GMP_H
-#if HAVE_GMP
-
#include <gmp.h>
extern zend_module_entry gmp_module_entry;
@@ -81,15 +79,6 @@ ZEND_FUNCTION(gmp_popcount);
ZEND_FUNCTION(gmp_hamdist);
ZEND_FUNCTION(gmp_nextprime);
-/* 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
-
ZEND_BEGIN_MODULE_GLOBALS(gmp)
zend_bool rand_initialized;
gmp_randstate_t rand_state;
@@ -101,12 +90,6 @@ ZEND_END_MODULE_GLOBALS(gmp)
ZEND_TSRMLS_CACHE_EXTERN()
#endif
-#else
-
-#define phpext_gmp_ptr NULL
-
-#endif
-
#endif /* PHP_GMP_H */
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