summaryrefslogtreecommitdiff
path: root/zend/extensionimpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zend/extensionimpl.cpp')
-rw-r--r--zend/extensionimpl.cpp88
1 files changed, 41 insertions, 47 deletions
diff --git a/zend/extensionimpl.cpp b/zend/extensionimpl.cpp
index bacf80f..5261b0d 100644
--- a/zend/extensionimpl.cpp
+++ b/zend/extensionimpl.cpp
@@ -41,14 +41,14 @@ static void init_globals(zend_phpcpp_globals *globals) {}
* variable. However, there does not seem to be a decent API call in Zend to
* get back the original module_entry linked to this number. So we have to
* look up entries in a hash table to find the right module entry. To make things
- * even worse, the records in this hash table are copies of the original
+ * even worse, the records in this hash table are copies of the original
* zend_module_entry structure, so we can also not hide the C++ extension
* object pointer in the entry that we created ourselves.
- *
+ *
* We have an ugly solution, we keep track of a map of all C++ extension names
* and their associated extension object, and a map of all module number and
* the linked extension object.
- *
+ *
* @var map
*/
static std::map<std::string,ExtensionImpl*> name2extension;
@@ -56,11 +56,11 @@ static std::map<int,ExtensionImpl*> number2extension;
/**
* Handler function that is used in combination with zend_hash_apply()
- *
+ *
* This function is called when we need to find an extension object based on
- * an extension number. We loop through the list of all registered modules, and
+ * an extension number. We loop through the list of all registered modules, and
* for each module we check if we know the extension based on the name
- *
+ *
* @param zend_module_entry
*/
static int match_module(zend_module_entry *entry)
@@ -68,10 +68,10 @@ static int match_module(zend_module_entry *entry)
// check if there is an extension with this name
auto iter = name2extension.find(entry->name);
if (iter == name2extension.end()) return ZEND_HASH_APPLY_KEEP;
-
+
// we have the extension, store in combination with the number
number2extension[entry->module_number] = iter->second;
-
+
// done
return ZEND_HASH_APPLY_KEEP;
}
@@ -87,14 +87,14 @@ static ExtensionImpl *find(int number TSRMLS_DC)
// do we already have an extension with this number?
auto iter = number2extension.find(number);
if (iter != number2extension.end()) return iter->second;
-
+
// no, not yet, loop through all modules
zend_hash_apply(&module_registry, (apply_func_t)match_module TSRMLS_CC);
-
+
// find again
iter = number2extension.find(number);
if (iter == number2extension.end()) return nullptr;
-
+
// found!
return iter->second;
}
@@ -109,7 +109,7 @@ static ExtensionImpl *find(int number TSRMLS_DC)
int ExtensionImpl::processStartup(int type, int module_number TSRMLS_DC)
{
// initialize and allocate the "global" variables
- ZEND_INIT_MODULE_GLOBALS(phpcpp, init_globals, NULL);
+ ZEND_INIT_MODULE_GLOBALS(phpcpp, init_globals, NULL);
// get the extension
auto *extension = find(module_number TSRMLS_CC);
@@ -148,10 +148,10 @@ int ExtensionImpl::processRequest(int type, int module_number TSRMLS_DC)
{
// get the extension
auto *extension = find(module_number TSRMLS_CC);
-
+
// is the callback registered?
if (extension->_onRequest) extension->_onRequest();
-
+
// done
return BOOL2SUCCESS(true);
}
@@ -167,10 +167,10 @@ int ExtensionImpl::processIdle(int type, int module_number TSRMLS_DC)
{
// get the extension
auto *extension = find(module_number TSRMLS_CC);
-
+
// is the callback registered?
if (extension->_onIdle) extension->_onIdle();
-
+
// done
return BOOL2SUCCESS(true);
}
@@ -187,10 +187,10 @@ int ExtensionImpl::processMismatch(int type, int module_number TSRMLS_DC)
{
// get the extension
auto *extension = find(module_number TSRMLS_CC);
-
+
// report a warning
warning << "Version mismatch between PHP-CPP and extension " << extension->name() << " " << extension->version() << " (recompile needed?)" << std::endl;
-
+
// done
return BOOL2SUCCESS(true);
}
@@ -202,12 +202,12 @@ int ExtensionImpl::processMismatch(int type, int module_number TSRMLS_DC)
* @param version Version number
* @param apiversion API version number
*/
-ExtensionImpl::ExtensionImpl(Extension *data, const char *name, const char *version, int apiversion) :
+ExtensionImpl::ExtensionImpl(Extension *data, const char *name, const char *version, int apiversion) :
ExtensionBase(data)
{
// keep extension pointer based on the name
name2extension[name] = this;
-
+
// assign all members (apart from the globals)
_entry.size = sizeof(zend_module_entry); // size of the data
_entry.zend_api = ZEND_MODULE_API_NO; // api number
@@ -242,8 +242,8 @@ ExtensionImpl::ExtensionImpl(Extension *data, const char *name, const char *vers
// everything is ok if the api versions match
if (apiversion == PHPCPP_API_VERSION) return;
-
- // mismatch between api versions, the extension is invalid, we use a
+
+ // mismatch between api versions, the extension is invalid, we use a
// different startup function to report to the user
_entry.module_startup_func = &ExtensionImpl::processMismatch;
@@ -260,12 +260,9 @@ ExtensionImpl::~ExtensionImpl()
{
// remove from the array
name2extension.erase(_entry.name);
-
- // deallocate the php.ini entries
- if (_ini) delete[] _ini;
-
+
// deallocate functions
- if (_entry.functions) delete[] _entry.functions;
+ delete[] _entry.functions;
}
/**
@@ -303,7 +300,7 @@ zend_module_entry *ExtensionImpl::module()
// the number of functions
int count = _data->functions();
-
+
// skip if there are no functions
if (count == 0) return &_entry;
@@ -315,10 +312,10 @@ zend_module_entry *ExtensionImpl::module()
// apply a function to each function
_data->functions([&i, entries](const std::string &prefix, NativeFunction &function) {
-
+
// initialize the function
function.initialize(prefix, &entries[i]);
-
+
// move on to the next iteration
i++;
});
@@ -345,40 +342,40 @@ zend_module_entry *ExtensionImpl::module()
bool ExtensionImpl::initialize(int module_number TSRMLS_DC)
{
// array contains ini settings
- _ini = new zend_ini_entry[_data->iniVariables()+1];
+ _ini.reset(new zend_ini_entry_def[_data->iniVariables()+1]);
// the entry that we're filling
int i = 0;
// Fill the php.ini entries
_data->iniVariables([this, &i, module_number](Ini &ini) {
-
+
// initialize the function
- zend_ini_entry *entry = &_ini[i];
-
+ zend_ini_entry_def *entry = &_ini[i];
+
// fill the property
ini.fill(entry, module_number);
-
+
// move on to the next iteration
- i++;
+ ++i;
});
// last entry should be set to all zero's
memset(&_ini[i], 0, sizeof(zend_ini_entry));
// register ini entries in Zend core
- zend_register_ini_entries(_ini, module_number TSRMLS_CC);
+ zend_register_ini_entries(_ini.get(), module_number TSRMLS_CC);
// the constants are registered after the module is ready
_data->constants([module_number TSRMLS_CC](const std::string &prefix, Constant &c) {
-
+
// forward to implementation class
c.implementation()->initialize(prefix, module_number TSRMLS_CC);
});
-
+
// we also need to register each class, find out all classes
_data->classes([TSRMLS_C](const std::string &prefix, ClassBase &c) {
-
+
// forward to implementation class
c.implementation()->initialize(&c, prefix TSRMLS_CC);
});
@@ -386,10 +383,10 @@ bool ExtensionImpl::initialize(int module_number TSRMLS_DC)
// initialize the PhpCpp::Functor class
Functor::initialize(TSRMLS_C);
- // remember that we're initialized (when you use "apache reload" it is
+ // remember that we're initialized (when you use "apache reload" it is
// possible that the processStartup() method is called more than once)
_locked = true;
-
+
// is the callback registered?
if (_onStartup) _onStartup();
@@ -409,17 +406,14 @@ bool ExtensionImpl::shutdown(int module_number TSRMLS_DC)
zend_unregister_ini_entries(module_number TSRMLS_CC);
// destruct the ini entries
- if (_ini) delete[] _ini;
-
- // forget the ini entries
- _ini = nullptr;
+ _ini.reset();
// shutdown the functor class
Functor::shutdown(TSRMLS_C);
// is the callback registered?
if (_onShutdown) _onShutdown();
-
+
// done
return true;
}