Skip to content
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

PHP-CPP: PHP 8.4 support #535

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions zend/classimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,22 @@ static ClassImpl *self(zend_class_entry *entry)
* the string, in case PHP tries to read it) and after that the pointer
* and we leave the doc_comment_len at 0.
*/
#if PHP_VERSION_ID < 80400
while (entry->parent && (entry->info.user.doc_comment == nullptr || ZSTR_LEN(entry->info.user.doc_comment) > 0))
#else
while (entry->parent && (entry->doc_comment == nullptr || ZSTR_LEN(entry->doc_comment) > 0))
#endif
{
// we did not create this class entry, but luckily we have a parent
entry = entry->parent;
}

// retrieve the comment (it has a pointer hidden in it to the ClassBase object)
#if PHP_VERSION_ID < 80400
const char *comment = ZSTR_VAL(entry->info.user.doc_comment);
#else
const char *comment = ZSTR_VAL(entry->doc_comment);
#endif

// the first byte of the comment is an empty string (null character), but
// the next bytes contain a pointer to the ClassBase class
Expand Down Expand Up @@ -1604,7 +1612,11 @@ zend_class_entry *ClassImpl::initialize(ClassBase *base, const std::string &pref
std::memcpy(ZSTR_VAL(_self) + 1, &impl, sizeof(impl));

// install the doc_comment
#if PHP_VERSION_ID < 80400
_entry->info.user.doc_comment = _self;
#else
_entry->doc_comment = _self;
#endif

// declare all member variables
for (auto &member : _members) member->initialize(_entry);
Expand Down
4 changes: 4 additions & 0 deletions zend/iteratorimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ void IteratorImpl::destructor(zend_object_iterator *iter)
* @param iter
* @return int
*/
#if PHP_VERSION_ID < 80400
int IteratorImpl::valid(zend_object_iterator *iter)
#else
zend_result IteratorImpl::valid(zend_object_iterator *iter)
#endif
{
// check if valid
return self(iter)->valid() ? SUCCESS : FAILURE;
Expand Down
4 changes: 4 additions & 0 deletions zend/iteratorimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ class IteratorImpl
* @param iter
* @return int
*/
#if PHP_VERSION_ID < 80400
static int valid(zend_object_iterator *iter);
#else
static zend_result valid(zend_object_iterator *iter);
#endif

/**
* Fetch the current item
Expand Down
6 changes: 6 additions & 0 deletions zend/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,23 @@ class Module
// this is not possible if the module is invalid in the first place
if (!valid()) return false;

#if PHP_VERSION_ID < 80400
// the Zend engine sets a number of properties in the entry class, we do that here too
// note that it would be better to call zend_next_free_module() to find the next module
// number, but some users complain that this function is not always available
_entry->type = MODULE_TEMPORARY;
_entry->module_number = zend_hash_num_elements(&module_registry) + 1;
Copy link
Author

Choose a reason for hiding this comment

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

Explicitly uses zend_next_free_module inside zend_register_module_ex.

#endif
_entry->handle = _handle;

// @todo does loading an extension even work in a multi-threading setup?

// register the module, this apparently returns a copied entry pointer
#if PHP_VERSION_ID < 80400
auto *entry = zend_register_module_ex(_entry);
#else
auto *entry = zend_register_module_ex(_entry, MODULE_TEMPORARY);
#endif

// forget the entry, so that a new call to start() will fail too
_entry = nullptr;
Expand Down