]> granicus.if.org Git - php/commitdiff
Make GMP more usable by third-party extensions.
authorSara Golemon <pollita@php.net>
Mon, 2 Oct 2017 21:26:05 +0000 (17:26 -0400)
committerSara Golemon <pollita@php.net>
Mon, 9 Oct 2017 17:23:10 +0000 (13:23 -0400)
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.

NEWS
ext/gmp/config.m4
ext/gmp/config.w32
ext/gmp/gmp.c
ext/gmp/php_gmp.h
ext/gmp/php_gmp_int.h [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 201f1209acc912096ebd577505d54f76989f2301..d5247a9369ef3e5c7c1c3f64bf98932d7718f4dc 100644 (file)
--- 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)
index 22cca7eaf208eeaf45db68012c6000fa432098c4..a1c565bf4ef13ce365e05aeec56686bb04ed439e 100644 (file)
@@ -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)
index 7ea36150b20d73dc4417fe56b681d8329d90e36b..ca85a2e44b22b1fec960435491ce08e375014879 100644 (file)
@@ -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 {
index 9fcf9c14d74614c0c46535b20f2afddf31460bf4..61fb37a1e2fe8fc0cbb1d57f5197061936777cf4 100644 (file)
 #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
index 903c68ee5eb5806f0540f82996c1d4e4824285ce..971d6593eca52b17fded96c3e811dc23aeefd08a 100644 (file)
@@ -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 (file)
index 0000000..9dd4c4d
--- /dev/null
@@ -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