Skip to content

Zend: support relative paths for extensions #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion Zend/zend_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/* $Id$ */

#include "zend_extensions.h"
#include "php.h"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a good idea make Zend engine rely on php

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

php.h is used for DEFAULT_SLASH, IS_SLASH and INI_STR("extension_dir").

Do we have equivalents in the Zend world?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is one reason of why zend extension does not support relative path.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Could we consider an optional approach based on dlsym?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, including php.h in Zend Engine files is definitely a no go. Same for using any symbols not originating in Zend Engine.

ZEND_API zend_llist zend_extensions;
static int last_resource_number;
Expand All @@ -30,8 +31,28 @@ int zend_load_extension(const char *path)
DL_HANDLE handle;
zend_extension *new_extension;
zend_extension_version_info *extension_version_info;
char *normalized_path;
char *extension_dir = INI_STR("extension_dir");
int extension_dir_len = strlen(extension_dir);

if (strchr(path, '/') == NULL || strchr(path, DEFAULT_SLASH) == NULL) {
if (extension_dir && extension_dir[0]) {
if (IS_SLASH(extension_dir[extension_dir_len-1])) {
spprintf(&normalized_path, 0, "%s%s", extension_dir, path);
} else {
spprintf(&normalized_path, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, path);
}
} else {
return FAILURE;
}
} else {
normalized_path = estrdup(path);
}

handle = DL_LOAD(normalized_path);

efree(normalized_path);

handle = DL_LOAD(path);
if (!handle) {
#ifndef ZEND_WIN32
fprintf(stderr, "Failed loading %s: %s\n", path, DL_ERROR());
Expand Down