com php-src: Minor refactor of load extension by name impl: ext/standard/dl.c main/php_ini.c
| From: | Sara Golemon | Date: | Thu, 22 Jun 2017 17:13:45 +0000 |
| Subject: | com php-src: Minor refactor of load extension by name impl: ext/standard/dl.c main/php_ini.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-98169@lists.php.net to get a copy of this message | ||
Commit: d09edf7b34ffc2b6b90eb25e75e18070c38aab1d
Author: Sara Golemon <pollita@php.net> Thu, 22 Jun 2017 13:13:42 -0400
Parents: fe5c8f2b80e57c6470a56a8d775947fe0ded182e
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d09edf7b34ffc2b6b90eb25e75e18070c38aab1d
Log:
Minor refactor of load extension by name impl
Minimize the #ifdef surface area
Localize orig_libpath to retry scope
Send errors to php_error() rathern than stderr
Changed paths:
M ext/standard/dl.c
M main/php_ini.c
Diff:
diff --git a/ext/standard/dl.c b/ext/standard/dl.c
index 35a71ab..0505166 100644
--- a/ext/standard/dl.c
+++ b/ext/standard/dl.c
@@ -81,7 +81,7 @@ PHPAPI PHP_FUNCTION(dl)
PHPAPI int php_load_extension(char *filename, int type, int start_now)
{
void *handle;
- char *libpath, *orig_libpath;
+ char *libpath;
zend_module_entry *module_entry;
zend_module_entry *(*get_module)(void);
int error_type, slash_suffix;
@@ -118,22 +118,20 @@ PHPAPI int php_load_extension(char *filename, int type, int start_now)
}
if (VCWD_ACCESS(libpath, F_OK)) {
/* If file does not exist, consider as extension name and build file name */
- orig_libpath = libpath;
+ const char *libpath_prefix = "";
+ char *orig_libpath = libpath;
#if PHP_WIN32
+ libpath_prefix = "php_";
+#endif
if (slash_suffix) {
- spprintf(&libpath, 0, "%sphp_%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /*
SAFE */
- } else {
- spprintf(&libpath, 0, "%s%cphp_%s." PHP_SHLIB_SUFFIX, extension_dir,
DEFAULT_SLASH, filename); /* SAFE */
- }
-#else
- if (slash_suffix) {
- spprintf(&libpath, 0, "%s%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE
*/
+ spprintf(&libpath, 0, "%s%s%s." PHP_SHLIB_SUFFIX, extension_dir, libpath_prefix,
filename); /* SAFE */
} else {
- spprintf(&libpath, 0, "%s%c%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH,
filename); /* SAFE */
+ spprintf(&libpath, 0, "%s%c%s%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH,
libpath_prefix, filename); /* SAFE */
}
-#endif
+
if (VCWD_ACCESS(libpath, F_OK)) {
- php_error_docref(NULL TSRMLS_CC, error_type, "Cannot access dynamic library '%s'
(tried : %s, %s)", filename, orig_libpath, libpath);
+ php_error(error_type, "Cannot access dynamic library '%s' (tried : %s,
%s)",
+ filename, orig_libpath, libpath);
efree(orig_libpath);
efree(libpath);
return FAILURE;
diff --git a/main/php_ini.c b/main/php_ini.c
index a378ce1..8b53f30 100644
--- a/main/php_ini.c
+++ b/main/php_ini.c
@@ -362,7 +362,7 @@ static void php_load_zend_extension_cb(void *arg)
if (IS_ABSOLUTE_PATH(filename, length)) {
zend_load_extension(filename);
} else {
- char *libpath, *orig_libpath;
+ char *libpath;
char *extension_dir = INI_STR("extension_dir");
int extension_dir_len = (int)strlen(extension_dir);
int slash_suffix = IS_SLASH(extension_dir[extension_dir_len-1]);
@@ -372,30 +372,29 @@ static void php_load_zend_extension_cb(void *arg)
} else {
spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); /* SAFE
*/
}
+
if (VCWD_ACCESS(libpath, F_OK)) {
/* If file does not exist, consider as extension name and build file name */
- orig_libpath = libpath;
+ const char *libpath_prefix = "";
+ char *orig_libpath = libpath;
#if PHP_WIN32
+ libpath_prefix = "php_";
+#endif
+
if (slash_suffix) {
- spprintf(&libpath, 0, "%sphp_%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /*
SAFE */
- } else {
- spprintf(&libpath, 0, "%s%cphp_%s." PHP_SHLIB_SUFFIX, extension_dir,
DEFAULT_SLASH, filename); /* SAFE */
- }
-#else
- if (slash_suffix) {
- spprintf(&libpath, 0, "%s%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE
*/
+ spprintf(&libpath, 0, "%s%s%s." PHP_SHLIB_SUFFIX, extension_dir, libpath_prefix,
filename); /* SAFE */
} else {
- spprintf(&libpath, 0, "%s%c%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH,
filename); /* SAFE */
+ spprintf(&libpath, 0, "%s%c%s%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH,
libpath_prefix, filename); /* SAFE */
}
-#endif
+
if (VCWD_ACCESS(libpath, F_OK)) {
- fprintf(stderr, "Cannot access Zend extension %s (Tried: %s, %s)\n", filename,
orig_libpath, libpath);
- /* See http://support.microsoft.com/kb/190351 */
- fflush(stderr);
+ php_error(E_CORE_WARNING, "Cannot access Zend extension %s (Tried: %s, %s)\n",
+ filename, orig_libpath, libpath);
efree(orig_libpath);
efree(libpath);
return;
}
+
efree(orig_libpath);
}