]> granicus.if.org Git - php/commitdiff
Minor refactor of load extension by name impl
authorSara Golemon <pollita@php.net>
Thu, 22 Jun 2017 17:13:42 +0000 (13:13 -0400)
committerSara Golemon <pollita@php.net>
Thu, 22 Jun 2017 17:13:45 +0000 (13:13 -0400)
Minimize the #ifdef surface area
Localize orig_libpath to retry scope
Send errors to php_error() rathern than stderr

ext/standard/dl.c
main/php_ini.c

index 35a71ab2a57aaeac27c24af818b94608990bdf11..050516639e11e73e44f72d5dfef1c4957016b412 100644 (file)
@@ -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;
index a378ce1926d414f4159cadbfb80255d62855fea4..8b53f304413c0569033caebb2838ebb688d89843 100644 (file)
@@ -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);
                }