#Zend引擎分析 ##基础变量类型(zend_value)
- zend_long
typedef int64_t zend_long;
64位有符号整型
- zend_uchar
typedef unsigned char zend_uchar;
无符号字符型
- zend_bool
typedef unsigned char zend_bool;
bool其实是无符号字符型
- double
- zend_refcounted
typedef struct _zend_refcounted zend_refcounted;
struct _zend_refcounted {
uint32_t refcount; /* 32位整型的引用计数 */
union {
struct {
ZEND_ENDIAN_LOHI_3(
zend_uchar type,
zend_uchar flags, /* used for strings & objects */
uint16_t gc_info) /* keeps GC root number (or 0) and color */
} v;
uint32_t type_info;
} u;
};
- zend_string
typedef struct _zend_string zend_string;
struct _zend_string {
zend_refcounted gc;
zend_ulong h; /* hash value */
size_t len; /* 长度 */
char val[1];
};
- zend_array
typedef struct _zend_array zend_array;
struct _zend_array {
zend_refcounted gc;
HashTable ht;
};
- HashTable
typedef struct _HashTable {
uint32_t nTableSize; /* 大小 */
uint32_t nTableMask;
uint32_t nNumUsed;
uint32_t nNumOfElements;
zend_long nNextFreeElement;
Bucket *arData;
uint32_t *arHash;
dtor_func_t pDestructor;
uint32_t nInternalPointer;
union {
struct {
ZEND_ENDIAN_LOHI_3(
zend_uchar flags,
zend_uchar nApplyCount,
uint16_t reserve)
} v;
uint32_t flags;
} u;
} HashTable;
- Bucket
typedef struct _Bucket {
zval val;
zend_ulong h; /* hash value (or numeric index) */
zend_string *key; /* string key or NULL for numerics */
} Bucket;
- zend_object
typedef struct _zend_object zend_object;
struct _zend_object {
zend_refcounted gc;
uint32_t handle; // TODO: may be removed ???
zend_class_entry *ce;
const zend_object_handlers *handlers;
HashTable *properties;
HashTable *guards; /* protects from __get/__set ... recursion */
zval properties_table[1];
};
- zend_class_entry
typedef struct _zend_class_entry zend_class_entry;
struct _zend_class_entry {
char type;
zend_string *name;
struct _zend_class_entry *parent;
int refcount;
uint32_t ce_flags;
int default_properties_count;
int default_static_members_count;
zval *default_properties_table;
zval *default_static_members_table;
zval *static_members_table;
HashTable function_table;
HashTable properties_info;
HashTable constants_table;
union _zend_function *constructor;
union _zend_function *destructor;
union _zend_function *clone;
union _zend_function *__get;
union _zend_function *__set;
union _zend_function *__unset;
union _zend_function *__isset;
union _zend_function *__call;
union _zend_function *__callstatic;
union _zend_function *__tostring;
union _zend_function *__debugInfo;
union _zend_function *serialize_func;
union _zend_function *unserialize_func;
zend_class_iterator_funcs iterator_funcs;
/* handlers */
zend_object* (*create_object)(zend_class_entry *class_type TSRMLS_DC);
zend_object_iterator *(*get_iterator)(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC);
int (*interface_gets_implemented)(zend_class_entry *iface, zend_class_entry *class_type TSRMLS_DC); /* a class implements this interface */
union _zend_function *(*get_static_method)(zend_class_entry *ce, zend_string* method TSRMLS_DC);
/* serializer callbacks */
int (*serialize)(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data TSRMLS_DC);
int (*unserialize)(zval *object, zend_class_entry *ce, const unsigned char *buf, size_t buf_len, zend_unserialize_data *data TSRMLS_DC);
uint32_t num_interfaces;
uint32_t num_traits;
zend_class_entry **interfaces;
zend_class_entry **traits;
zend_trait_alias **trait_aliases;
zend_trait_precedence **trait_precedences;
union {
struct {
zend_string *filename;
uint32_t line_start;
uint32_t line_end;
zend_string *doc_comment;
} user;
struct {
const struct _zend_function_entry *builtin_functions;
struct _zend_module_entry *module;
} internal;
} info;
};
- zend_resource
typedef struct _zend_resource zend_resource;
struct _zend_resource {
zend_refcounted gc;
zend_long handle; // TODO: may be removed ???
int type;
void *ptr;
};
- zend_reference
typedef struct _zend_reference zend_reference;
struct _zend_reference {
zend_refcounted gc;
zval val;
};
- zend_ast_ref
typedef struct _zend_ast_ref zend_ast_ref;
struct _zend_ast_ref {
zend_refcounted gc;
zend_ast *ast;
};
-
zval
-
zend_function
-
zend_ast
typedef struct _zend_ast zend_ast;
struct _zend_ast {
zend_ast_kind kind; /* Type of the node (ZEND_AST_* enum constant) */
zend_ast_attr attr; /* Additional attribute, use depending on node type */
uint32_t lineno; /* Line number */
zend_ast *child[1]; /* Array of children (using struct hack) */
};