Skip to content

Implement Opcache File Backend #9

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

Merged
merged 2 commits into from
May 1, 2020
Merged
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
19 changes: 17 additions & 2 deletions Zend/tests/attributes/001_placement.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,68 +43,83 @@ $sources = [
];

foreach ($sources as $r) {
foreach ($r->getAttributes() as $attr) {
var_dump($attr->getName(), $attr->getArguments());
$attr = $r->getAttributes();
var_dump(count($attr));

foreach ($attr as $a) {
var_dump($a->getName(), $a->getArguments());
}
}

?>
--EXPECT--
int(1)
string(2) "A1"
array(1) {
[0]=>
int(1)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
int(2)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
int(2)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
int(3)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
int(3)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
int(4)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
int(5)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
int(6)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
int(7)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
int(8)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
int(9)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5769,7 +5769,7 @@ static void zend_compile_attributes(HashTable *attributes, zend_ast *ast, uint32
ZEND_ASSERT(ast->kind == ZEND_AST_ATTRIBUTE_LIST);

for (i = 0; i < list->children; i++) {
zend_attribute *attr = zend_compile_attribute(list->child[i], 0);
zend_attribute *attr = zend_compile_attribute(list->child[i], offset);

// Validate internal attribute
zend_attributes_internal_validator validator = zend_hash_find_ptr(&zend_attributes_internal_validators, attr->lcname);
Expand Down
72 changes: 61 additions & 11 deletions ext/opcache/zend_file_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "zend_compile.h"
#include "zend_vm.h"
#include "zend_interfaces.h"
#include "zend_attributes.h"

#include "php.h"
#ifdef ZEND_WIN32
Expand Down Expand Up @@ -158,22 +159,22 @@ static int zend_file_cache_flock(int fd, int type)
} \
} while (0)

#define SERIALIZE_ATTRIBUTES(attr) do { \
if ((attr) && !IS_SERIALIZED(attr)) { \
#define SERIALIZE_ATTRIBUTES(attributes) do { \
if ((attributes) && !IS_SERIALIZED(attributes)) { \
HashTable *ht; \
SERIALIZE_PTR(attr); \
ht = (attr); \
SERIALIZE_PTR(attributes); \
ht = (attributes); \
UNSERIALIZE_PTR(ht); \
zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval); \
zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_attribute); \
} \
} while (0)

#define UNSERIALIZE_ATTRIBUTES(attr) do { \
if ((attr) && !IS_UNSERIALIZED(attr)) { \
#define UNSERIALIZE_ATTRIBUTES(attributes) do { \
if ((attributes) && !IS_UNSERIALIZED(attributes)) { \
HashTable *ht; \
UNSERIALIZE_PTR(attr); \
ht = (attr); \
zend_file_cache_unserialize_hash(ht, script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR); \
UNSERIALIZE_PTR(attributes); \
ht = (attributes); \
zend_file_cache_unserialize_hash(ht, script, buf, zend_file_cache_unserialize_attribute, NULL); \
} \
} while (0)

Expand Down Expand Up @@ -390,6 +391,33 @@ static void zend_file_cache_serialize_zval(zval *zv,
}
}

static void zend_file_cache_serialize_attribute(zval *zv,
zend_persistent_script *script,
zend_file_cache_metainfo *info,
void *buf)
{
if (!IS_SERIALIZED(Z_PTR_P(zv))) {
zend_attribute *attr = Z_PTR_P(zv);
uint32_t i;

SERIALIZE_PTR(Z_PTR_P(zv));
attr = Z_PTR_P(zv);
UNSERIALIZE_PTR(attr);

if (!IS_SERIALIZED(attr->name)) {
SERIALIZE_STR(attr->name);
}

if (!IS_SERIALIZED(attr->lcname)) {
SERIALIZE_STR(attr->lcname);
}

for (i = 0; i < attr->argc; i++) {
zend_file_cache_serialize_zval(&attr->argv[i], script, info, buf);
}
}
}

static void zend_file_cache_serialize_type(
zend_type *type, zend_persistent_script *script, zend_file_cache_metainfo *info, void *buf)
{
Expand Down Expand Up @@ -613,7 +641,6 @@ static void zend_file_cache_serialize_prop_info(zval *zv,
SERIALIZE_STR(prop->doc_comment);
}
SERIALIZE_ATTRIBUTES(prop->attributes);

zend_file_cache_serialize_type(&prop->type, script, info, buf);
}
}
Expand Down Expand Up @@ -1118,6 +1145,29 @@ static void zend_file_cache_unserialize_zval(zval *zv,
}
}

static void zend_file_cache_unserialize_attribute(zval *zv, zend_persistent_script *script, void *buf)
{
if (!IS_UNSERIALIZED(Z_PTR_P(zv))) {
zend_attribute *attr;
uint32_t i;

UNSERIALIZE_PTR(Z_PTR_P(zv));
attr = Z_PTR_P(zv);

if (!IS_UNSERIALIZED(attr->name)) {
UNSERIALIZE_STR(attr->name);
}

if (!IS_UNSERIALIZED(attr->lcname)) {
UNSERIALIZE_STR(attr->lcname);
}

for (i = 0; i < attr->argc; i++) {
zend_file_cache_unserialize_zval(&attr->argv[i], script, buf);
}
}
}

static void zend_file_cache_unserialize_type(
zend_type *type, zend_persistent_script *script, void *buf)
{
Expand Down