com php-src: Make GMP more usable by third-party extensions.: NEWS ext/gmp/config.m4 ext/gmp/config.w32 ext/gmp/gmp.c ext/gmp/php _gmp.h
ext/gmp/php_gmp_int.h
| From: | Sara Golemon | Date: | Mon, 09 Oct 2017 17:23:10 +0000 |
| Subject: | com php-src: Make GMP more usable by third-party extensions.: NEWS ext/gmp/config.m4 ext/gmp/config.w32 ext/gmp/gmp.c ext/gmp/php _gmp.h ext/gmp/php_gmp_int.h |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-99669@lists.php.net to get a copy of this message | ||
Commit: e05cba0806fed049854d3569401935a524861750
Author: Sara Golemon <pollita@php.net> Mon, 2 Oct 2017 17:26:05 -0400
Parents: 39ded1d5f85ca3358cc8a52bb37e72a5eb5ce0db
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e05cba0806fed049854d3569401935a524861750
Log:
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.
Changed paths:
M NEWS
M ext/gmp/config.m4
M ext/gmp/config.w32
M ext/gmp/gmp.c
M ext/gmp/php_gmp.h
A ext/gmp/php_gmp_int.h
Diff:
diff --git a/NEWS b/NEWS
index 201f120..d5247a9 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 22cca7e..a1c565b 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 7ea3615..ca85a2e 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 9fcf9c1..61fb37a 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 903c68e..971d659 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 0000000..9dd4c4d
--- /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