File tree Expand file tree Collapse file tree 3 files changed +75
-0
lines changed
Expand file tree Collapse file tree 3 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -1044,6 +1044,20 @@ if test "$PHP_DMALLOC" = "yes"; then
10441044 ] )
10451045fi
10461046
1047+ PHP_ARG_ENABLE([ jemalloc] ,
1048+ [ whether to enable jemalloc] ,
1049+ [ AS_HELP_STRING ( [ --enable-jemalloc] ,
1050+ [ Enable jemalloc] ) ] ,
1051+ [ no] ,
1052+ [ no] )
1053+
1054+ if test "$PHP_JEMALLOC" = "yes"; then
1055+ PKG_CHECK_MODULES([ JEMALLOC] , [ jemalloc] ,, [ AC_MSG_ERROR ( [ jemalloc not found] ) ] )
1056+ AC_DEFINE ( HAVE_JEMALLOC , 1 , [ Whether you have jemalloc] )
1057+ PHP_EVAL_LIBLINE($JEMALLOC_LIBS)
1058+ PHP_EVAL_INCLINE($JEMALLOC_CFLAGS)
1059+ fi
1060+
10471061PHP_ARG_ENABLE([ ipv6] ,
10481062 [ whether to enable IPv6 support] ,
10491063 [ AS_HELP_STRING ( [ --disable-ipv6] ,
Original file line number Diff line number Diff line change 4242#include <libxml/xmlschemas.h>
4343#endif
4444
45+ #ifdef HAVE_JEMALLOC
46+ #include <jemalloc/jemalloc.h>
47+ #endif // HAVE_JEMALLOC
48+
4549#include "php_libxml.h"
4650
4751#define PHP_LIBXML_LOADED_VERSION ((char *)xmlParserVersion)
@@ -900,9 +904,27 @@ static void php_libxml_exports_dtor(zval *zv)
900904 free (Z_PTR_P (zv ));
901905}
902906
907+ #ifdef HAVE_JEMALLOC
908+
909+ static char *
910+ je_xmlMemStrdup (const char * src )
911+ {
912+ const size_t size = strlen (src ) + 1 ;
913+ char * dest = je_malloc (size );
914+ if (dest != NULL )
915+ memcpy (dest , src , size );
916+ return dest ;
917+ }
918+
919+ #endif // HAVE_JEMALLOC
920+
903921PHP_LIBXML_API void php_libxml_initialize (void )
904922{
905923 if (!_php_libxml_initialized ) {
924+ #ifdef HAVE_JEMALLOC
925+ xmlMemSetup (je_free , je_malloc , je_realloc , je_xmlMemStrdup );
926+ #endif
927+
906928 /* we should be the only one's to ever init!! */
907929 ZEND_IGNORE_LEAKS_BEGIN ();
908930 xmlInitParser ();
Original file line number Diff line number Diff line change 6868/* Common */
6969#include <time.h>
7070
71+ #ifdef HAVE_JEMALLOC
72+ #include <jemalloc/jemalloc.h>
73+ #endif // HAVE_JEMALLOC
74+
7175#if (defined(PHP_WIN32 ) && defined(_MSC_VER ) && _MSC_VER >= 1900 )
7276#define timezone _timezone /* timezone is called _timezone in LibC */
7377#endif
@@ -1231,6 +1235,37 @@ PHP_INI_BEGIN()
12311235PHP_INI_END ()
12321236/* }}} */
12331237
1238+ #ifdef HAVE_JEMALLOC
1239+
1240+ static void *
1241+ je_CRYPTO_malloc (size_t num , const char * file , int line )
1242+ {
1243+ (void )file ;
1244+ (void )line ;
1245+
1246+ return je_malloc (num );
1247+ }
1248+
1249+ static void *
1250+ je_CRYPTO_realloc (void * addr , size_t num , const char * file , int line )
1251+ {
1252+ (void )file ;
1253+ (void )line ;
1254+
1255+ return je_realloc (addr , num );
1256+ }
1257+
1258+ static void
1259+ je_CRYPTO_free (void * addr , const char * file , int line )
1260+ {
1261+ (void )file ;
1262+ (void )line ;
1263+
1264+ je_free (addr );
1265+ }
1266+
1267+ #endif // HAVE_JEMALLOC
1268+
12341269/* {{{ PHP_MINIT_FUNCTION */
12351270PHP_MINIT_FUNCTION (openssl )
12361271{
@@ -1269,6 +1304,10 @@ PHP_MINIT_FUNCTION(openssl)
12691304 php_openssl_pkey_object_handlers .clone_obj = NULL ;
12701305 php_openssl_pkey_object_handlers .compare = zend_objects_not_comparable ;
12711306
1307+ #ifdef HAVE_JEMALLOC
1308+ CRYPTO_set_mem_functions (je_CRYPTO_malloc , je_CRYPTO_realloc , je_CRYPTO_free );
1309+ #endif // HAVE_JEMALLOC
1310+
12721311#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined (LIBRESSL_VERSION_NUMBER )
12731312 OPENSSL_config (NULL );
12741313 SSL_library_init ();
You can’t perform that action at this time.
0 commit comments