Skip to content

Commit c2cbe30

Browse files
authored
Merge pull request #9 from koolkode/AttributeOpcache
Implement Opcache File Backend
2 parents e870452 + 2468119 commit c2cbe30

File tree

3 files changed

+79
-14
lines changed

3 files changed

+79
-14
lines changed

Zend/tests/attributes/001_placement.phpt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,68 +43,83 @@ $sources = [
4343
];
4444

4545
foreach ($sources as $r) {
46-
foreach ($r->getAttributes() as $attr) {
47-
var_dump($attr->getName(), $attr->getArguments());
46+
$attr = $r->getAttributes();
47+
var_dump(count($attr));
48+
49+
foreach ($attr as $a) {
50+
var_dump($a->getName(), $a->getArguments());
4851
}
4952
}
5053

5154
?>
5255
--EXPECT--
56+
int(1)
5357
string(2) "A1"
5458
array(1) {
5559
[0]=>
5660
int(1)
5761
}
62+
int(1)
5863
string(2) "A1"
5964
array(1) {
6065
[0]=>
6166
int(2)
6267
}
68+
int(1)
6369
string(2) "A1"
6470
array(1) {
6571
[0]=>
6672
int(2)
6773
}
74+
int(1)
6875
string(2) "A1"
6976
array(1) {
7077
[0]=>
7178
int(3)
7279
}
80+
int(1)
7381
string(2) "A1"
7482
array(1) {
7583
[0]=>
7684
int(3)
7785
}
86+
int(1)
7887
string(2) "A1"
7988
array(1) {
8089
[0]=>
8190
int(4)
8291
}
92+
int(1)
8393
string(2) "A1"
8494
array(1) {
8595
[0]=>
8696
int(5)
8797
}
98+
int(1)
8899
string(2) "A1"
89100
array(1) {
90101
[0]=>
91102
int(6)
92103
}
104+
int(1)
93105
string(2) "A1"
94106
array(1) {
95107
[0]=>
96108
int(7)
97109
}
110+
int(1)
98111
string(2) "A1"
99112
array(1) {
100113
[0]=>
101114
int(8)
102115
}
116+
int(1)
103117
string(2) "A1"
104118
array(1) {
105119
[0]=>
106120
int(9)
107121
}
122+
int(1)
108123
string(2) "A1"
109124
array(1) {
110125
[0]=>

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5769,7 +5769,7 @@ static void zend_compile_attributes(HashTable *attributes, zend_ast *ast, uint32
57695769
ZEND_ASSERT(ast->kind == ZEND_AST_ATTRIBUTE_LIST);
57705770

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

57745774
// Validate internal attribute
57755775
zend_attributes_internal_validator validator = zend_hash_find_ptr(&zend_attributes_internal_validators, attr->lcname);

ext/opcache/zend_file_cache.c

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "zend_compile.h"
2222
#include "zend_vm.h"
2323
#include "zend_interfaces.h"
24+
#include "zend_attributes.h"
2425

2526
#include "php.h"
2627
#ifdef ZEND_WIN32
@@ -158,22 +159,22 @@ static int zend_file_cache_flock(int fd, int type)
158159
} \
159160
} while (0)
160161

161-
#define SERIALIZE_ATTRIBUTES(attr) do { \
162-
if ((attr) && !IS_SERIALIZED(attr)) { \
162+
#define SERIALIZE_ATTRIBUTES(attributes) do { \
163+
if ((attributes) && !IS_SERIALIZED(attributes)) { \
163164
HashTable *ht; \
164-
SERIALIZE_PTR(attr); \
165-
ht = (attr); \
165+
SERIALIZE_PTR(attributes); \
166+
ht = (attributes); \
166167
UNSERIALIZE_PTR(ht); \
167-
zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_zval); \
168+
zend_file_cache_serialize_hash(ht, script, info, buf, zend_file_cache_serialize_attribute); \
168169
} \
169170
} while (0)
170171

171-
#define UNSERIALIZE_ATTRIBUTES(attr) do { \
172-
if ((attr) && !IS_UNSERIALIZED(attr)) { \
172+
#define UNSERIALIZE_ATTRIBUTES(attributes) do { \
173+
if ((attributes) && !IS_UNSERIALIZED(attributes)) { \
173174
HashTable *ht; \
174-
UNSERIALIZE_PTR(attr); \
175-
ht = (attr); \
176-
zend_file_cache_unserialize_hash(ht, script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR); \
175+
UNSERIALIZE_PTR(attributes); \
176+
ht = (attributes); \
177+
zend_file_cache_unserialize_hash(ht, script, buf, zend_file_cache_unserialize_attribute, NULL); \
177178
} \
178179
} while (0)
179180

@@ -390,6 +391,33 @@ static void zend_file_cache_serialize_zval(zval *zv,
390391
}
391392
}
392393

394+
static void zend_file_cache_serialize_attribute(zval *zv,
395+
zend_persistent_script *script,
396+
zend_file_cache_metainfo *info,
397+
void *buf)
398+
{
399+
if (!IS_SERIALIZED(Z_PTR_P(zv))) {
400+
zend_attribute *attr = Z_PTR_P(zv);
401+
uint32_t i;
402+
403+
SERIALIZE_PTR(Z_PTR_P(zv));
404+
attr = Z_PTR_P(zv);
405+
UNSERIALIZE_PTR(attr);
406+
407+
if (!IS_SERIALIZED(attr->name)) {
408+
SERIALIZE_STR(attr->name);
409+
}
410+
411+
if (!IS_SERIALIZED(attr->lcname)) {
412+
SERIALIZE_STR(attr->lcname);
413+
}
414+
415+
for (i = 0; i < attr->argc; i++) {
416+
zend_file_cache_serialize_zval(&attr->argv[i], script, info, buf);
417+
}
418+
}
419+
}
420+
393421
static void zend_file_cache_serialize_type(
394422
zend_type *type, zend_persistent_script *script, zend_file_cache_metainfo *info, void *buf)
395423
{
@@ -613,7 +641,6 @@ static void zend_file_cache_serialize_prop_info(zval *zv,
613641
SERIALIZE_STR(prop->doc_comment);
614642
}
615643
SERIALIZE_ATTRIBUTES(prop->attributes);
616-
617644
zend_file_cache_serialize_type(&prop->type, script, info, buf);
618645
}
619646
}
@@ -1118,6 +1145,29 @@ static void zend_file_cache_unserialize_zval(zval *zv,
11181145
}
11191146
}
11201147

1148+
static void zend_file_cache_unserialize_attribute(zval *zv, zend_persistent_script *script, void *buf)
1149+
{
1150+
if (!IS_UNSERIALIZED(Z_PTR_P(zv))) {
1151+
zend_attribute *attr;
1152+
uint32_t i;
1153+
1154+
UNSERIALIZE_PTR(Z_PTR_P(zv));
1155+
attr = Z_PTR_P(zv);
1156+
1157+
if (!IS_UNSERIALIZED(attr->name)) {
1158+
UNSERIALIZE_STR(attr->name);
1159+
}
1160+
1161+
if (!IS_UNSERIALIZED(attr->lcname)) {
1162+
UNSERIALIZE_STR(attr->lcname);
1163+
}
1164+
1165+
for (i = 0; i < attr->argc; i++) {
1166+
zend_file_cache_unserialize_zval(&attr->argv[i], script, buf);
1167+
}
1168+
}
1169+
}
1170+
11211171
static void zend_file_cache_unserialize_type(
11221172
zend_type *type, zend_persistent_script *script, void *buf)
11231173
{

0 commit comments

Comments
 (0)