Skip to content

Commit 4e8bba9

Browse files
committed
Implemented attribute storage in file-based Opcache.
1 parent e870452 commit 4e8bba9

File tree

1 file changed

+61
-11
lines changed

1 file changed

+61
-11
lines changed

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)