Go to the documentation of this file.
33 #include <Zend/zend.h>
41 #define DEREF(memory, type) *(type*)(memory)
62 #define CASE_TYPE(upb_type, c_type) \
63 case UPB_TYPE_##upb_type: { \
64 return DEREF(memory, c_type) == 0; \
83 default:
return false;
97 zend_error(E_USER_ERROR,
"Given string is not UTF8 encoded.");
102 if (EXPECTED(cached_zval !=
NULL)) {
103 #if PHP_MAJOR_VERSION < 7
104 REPLACE_ZVAL_VALUE((zval**)memory,
value, 1);
106 zend_assign_to_variable(cached_zval,
value, IS_CV);
112 if (Z_TYPE_P(
value) != IS_OBJECT && Z_TYPE_P(
value) != IS_NULL) {
113 zend_error(E_USER_ERROR,
"Given value is not message.");
117 zend_error(E_USER_ERROR,
"Given message does not have correct class.");
122 if (EXPECTED(property_ptr !=
value)) {
126 #if PHP_MAJOR_VERSION < 7
130 ZVAL_ZVAL(property_ptr,
value, 1, 0);
135 #define CASE_TYPE(upb_type, type, c_type, php_type) \
136 case UPB_TYPE_##upb_type: { \
137 c_type type##_value; \
138 if (protobuf_convert_to_##type(value, &type##_value)) { \
139 DEREF(memory, c_type) = type##_value; \
149 CASE_TYPE(DOUBLE,
double,
double, DOUBLE)
162 const zend_class_entry*
klass,
void* memory,
163 zval*
value TSRMLS_DC) {
164 #if PHP_MAJOR_VERSION >= 7
165 if (Z_ISREF_P(
value)) {
177 zend_error(E_USER_ERROR,
"Given string is not UTF8 encoded.");
183 #if PHP_MAJOR_VERSION < 7
184 MAKE_STD_ZVAL(
DEREF(memory, zval*));
186 Z_STRLEN_P(
value), 1);
188 *(zend_string**)memory =
189 zend_string_init(Z_STRVAL_P(
value), Z_STRLEN_P(
value), 0);
194 if (Z_TYPE_P(
value) != IS_OBJECT) {
195 zend_error(E_USER_ERROR,
"Given value is not message.");
199 zend_error(E_USER_ERROR,
"Given message does not have correct class.");
202 #if PHP_MAJOR_VERSION < 7
203 if (EXPECTED(
DEREF(memory, zval*) !=
value)) {
220 void* memory, zval*
value TSRMLS_DC) {
221 #if PHP_MAJOR_VERSION >= 7
222 if (Z_ISREF_P(
value)) {
234 zend_error(E_USER_ERROR,
"Given string is not UTF8 encoded.");
240 #if PHP_MAJOR_VERSION < 7
241 MAKE_STD_ZVAL(
DEREF(memory, zval*));
243 Z_STRLEN_P(
value), 1);
245 *(zend_string**)memory =
246 zend_string_init(Z_STRVAL_P(
value), Z_STRLEN_P(
value), 0);
251 if (Z_TYPE_P(
value) != IS_OBJECT) {
252 zend_error(E_USER_ERROR,
"Given value is not message.");
256 zend_error(E_USER_ERROR,
"Given message does not have correct class.");
259 #if PHP_MAJOR_VERSION < 7
260 if (EXPECTED(
DEREF(memory, zval*) !=
value)) {
280 DEREF(memory,
float) = 0.0;
283 DEREF(memory,
double) = 0.0;
286 DEREF(memory, int8_t) = 0;
295 DEREF(memory, int32_t) = 0;
298 DEREF(memory, int64_t) = 0;
301 DEREF(memory, uint32_t) = 0;
304 DEREF(memory, uint64_t) = 0;
314 #define CASE(upb_type, php_type, c_type) \
315 case UPB_TYPE_##upb_type: \
316 PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); \
317 ZVAL_##php_type(CACHED_PTR_TO_ZVAL_PTR(cache), DEREF(memory, c_type)); \
320 CASE(FLOAT, DOUBLE,
float)
321 CASE(DOUBLE, DOUBLE,
double)
322 CASE(BOOL, BOOL, int8_t)
323 CASE(INT32, LONG, int32_t)
324 CASE(ENUM, LONG, uint32_t)
329 #define CASE(upb_type, c_type) \
330 case UPB_TYPE_##upb_type: { \
331 PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); \
332 char buffer[MAX_LENGTH_OF_INT64]; \
333 sprintf(buffer, "%lld", DEREF(memory, c_type)); \
334 PHP_PROTO_ZVAL_STRING(CACHED_PTR_TO_ZVAL_PTR(cache), buffer, 1); \
338 #define CASE(upb_type, c_type) \
339 case UPB_TYPE_##upb_type: { \
340 PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); \
341 ZVAL_LONG(CACHED_PTR_TO_ZVAL_PTR(cache), DEREF(memory, c_type)); \
345 CASE(UINT64, uint64_t)
354 if (
sizeof(
int) == 8) {
355 value |= (-((
value >> 31) & 0x1) & 0xFFFFFFFF00000000);
371 Z_STRLEN_P(
value), 1);
393 #if PHP_MAJOR_VERSION < 7
400 ZVAL_NEW_STR(cache, zend_string_dup(*(zend_string**)memory, 0));
405 #if PHP_MAJOR_VERSION < 7
437 #if PHP_MAJOR_VERSION < 7
444 ZVAL_OBJ(cache, *(zend_object**)memory);
456 #define CASE(upb_type, php_type) \
457 case UPB_TYPE_##upb_type: \
458 PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); \
459 ZVAL_##php_type(CACHED_PTR_TO_ZVAL_PTR(cache), 0); \
472 #define CASE(upb_type) \
473 case UPB_TYPE_##upb_type: { \
474 PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); \
475 PHP_PROTO_ZVAL_STRING(CACHED_PTR_TO_ZVAL_PTR(cache), "0", 1); \
479 #define CASE(upb_type) \
480 case UPB_TYPE_##upb_type: { \
481 PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); \
482 ZVAL_LONG(CACHED_PTR_TO_ZVAL_PTR(cache), 0); \
542 assert(key_field !=
NULL);
548 assert(value_field !=
NULL);
572 return (
offset + granularity - 1) & ~(granularity - 1);
577 return (uint32_t*)(((uint8_t*)storage) +
600 off +=
sizeof(
void*);
619 field_size =
sizeof(zval*);
632 #if PHP_MAJOR_VERSION < 7 || (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 0)
633 zend_class_entry* old_scope = EG(scope);
634 EG(scope) =
desc->klass;
636 zend_class_entry* old_scope = EG(fake_scope);
637 EG(fake_scope) =
desc->klass;
640 #if PHP_MAJOR_VERSION < 7
642 ZVAL_STRINGL(&member, fieldname, strlen(fieldname), 0);
643 zend_property_info* property_info =
644 zend_get_property_info(
desc->klass, &member,
true TSRMLS_CC);
646 zend_string* member = zend_string_init(fieldname, strlen(fieldname), 1);
647 zend_property_info* property_info =
648 zend_get_property_info(
desc->klass, member,
true);
649 zend_string_release(member);
652 #if PHP_MAJOR_VERSION < 7 || (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 0)
653 EG(scope) = old_scope;
655 EG(fake_scope) = old_scope;
659 property_info->offset;
693 #if PHP_MAJOR_VERSION < 7 || (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 0)
694 zend_class_entry* old_scope = EG(scope);
695 EG(scope) =
desc->klass;
697 zend_class_entry* old_scope = EG(fake_scope);
698 EG(fake_scope) =
desc->klass;
701 #if PHP_MAJOR_VERSION < 7
703 ZVAL_STRINGL(&member, oneofname, strlen(oneofname), 0);
704 zend_property_info* property_info =
705 zend_get_property_info(
desc->klass, &member,
true TSRMLS_CC);
707 zend_string* member = zend_string_init(oneofname, strlen(oneofname), 1);
708 zend_property_info* property_info =
709 zend_get_property_info(
desc->klass, member,
true);
710 zend_string_release(member);
713 #if PHP_MAJOR_VERSION < 7 || (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 0)
714 EG(scope) = old_scope;
716 EG(fake_scope) = old_scope;
720 property_info->offset;
732 size_t field_size =
sizeof(uint32_t);
734 off = (off + field_size - 1) & ~(field_size - 1);
761 memset(storage, 0,
sizeof(
void*));
775 zval_ptr_dtor(property_ptr);
776 #if PHP_MAJOR_VERSION < 7
777 MAKE_STD_ZVAL(*property_ptr);
783 zval_ptr_dtor(property_ptr);
784 #if PHP_MAJOR_VERSION < 7
785 MAKE_STD_ZVAL(*property_ptr);
842 zend_class_entry *ce =
NULL;
855 int property_cache_index =
871 memory =
DEREF(memory,
void**);
874 if (EXPECTED(property_ptr !=
val)) {
875 zend_class_entry *subce =
NULL;
876 zval converted_value;
887 subce = subdesc->
klass;
897 subce = subdesc->
klass;
903 #if PHP_MAJOR_VERSION < 7
904 REPLACE_ZVAL_VALUE((zval**)memory, &converted_value, 1);
907 ZVAL_ZVAL(property_ptr, &converted_value, 1, 0);
909 zval_dtor(&converted_value);
913 zend_class_entry *ce =
NULL;
926 zend_class_entry* ce =
NULL;
929 #define CASE_TYPE(upb_type, c_type) \
930 case UPB_TYPE_##upb_type: { \
931 DEREF(to_memory, c_type) = DEREF(from_memory, c_type); \
955 #if PHP_MAJOR_VERSION < 7
986 #if PHP_MAJOR_VERSION < 7
987 MAKE_STD_ZVAL(
DEREF(to_memory, zval*));
989 Z_STRVAL_P(*(zval**)from_memory),
990 Z_STRLEN_P(*(zval**)from_memory), 1);
992 DEREF(to_memory, zend_string*) =
993 zend_string_dup(*(zend_string**)from_memory, 0);
1000 zend_class_entry* ce =
desc->klass;
1001 #if PHP_MAJOR_VERSION < 7
1002 MAKE_STD_ZVAL(
DEREF(to_memory, zval*));
1005 DEREF(to_memory, zend_object*) = ce->create_object(ce TSRMLS_CC);
1035 uint32_t oneof_case_offset =
1052 int property_cache_index =
1055 OBJ_PROP(&to->std, property_cache_index);
1062 *to_oneof_case = *from_oneof_case;
1069 int size, key_length, value_length;
1074 zval* from_map_php =
1080 if (
size == 0)
continue;
1108 for (j = 0; j <
size; j++) {
1109 void* from_memory =
NULL;
1117 #if PHP_MAJOR_VERSION >= 7
1118 from_memory = &
Z_OBJ_P((zval*)from_memory);
1149 if (*oneof_case == 0) {
void * slot_memory(MessageLayout *layout, const void *storage, const upb_fielddef *field)
const upb_msgdef * msgdef
const upb_fielddef * map_entry_key(const upb_msgdef *msgdef)
void * upb_value_memory(upb_value *v)
#define UNBOX_HASHTABLE_VALUE(class_name, val)
const upb_oneofdef * upb_msg_iter_oneof(const upb_msg_oneof_iter *iter)
const zend_class_entry * field_type_class(const upb_fielddef *field PHP_PROTO_TSRMLS_DC)
#define PHP_PROTO_TSRMLS_DC
#define PHP_PROTO_TSRMLS_CC
static void native_slot_merge(const upb_fielddef *field, const void *from_memory, void *to_memory PHP_PROTO_TSRMLS_DC)
void custom_data_init(const zend_class_entry *ce, MessageHeader *intern PHP_PROTO_TSRMLS_DC)
#define CACHED_PTR_TO_ZVAL_PTR(VALUE)
bool upb_msgdef_mapentry(const upb_msgdef *m)
const char * map_iter_key(MapIter *iter, int *len)
GLenum GLuint GLenum GLsizei length
upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f)
const upb_fielddef * upb_oneofdef_itof(const upb_oneofdef *o, uint32_t num)
void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m)
void * message_data(MessageHeader *msg)
const upb_fielddef * map_field_value(const upb_fielddef *field)
void map_field_create_with_field(const zend_class_entry *ce, const upb_fielddef *field, CACHED_VALUE *map_field PHP_PROTO_TSRMLS_DC)
void check_map_field(const zend_class_entry *klass, PHP_PROTO_LONG key_type, PHP_PROTO_LONG value_type, zval *val, zval *return_value)
bool map_index_set(Map *intern, const char *keyval, int length, upb_value v)
zval * layout_get(MessageLayout *layout, const void *storage, const upb_fielddef *field, CACHED_VALUE *cache TSRMLS_DC)
#define DEREF(memory, type)
void repeated_field_create_with_field(zend_class_entry *ce, const upb_fielddef *field, CACHED_VALUE *repeated_field PHP_PROTO_TSRMLS_DC)
size_t native_slot_size(upb_fieldtype_t type)
static void native_slot_merge_by_array(const upb_fielddef *field, const void *from_memory, void *to_memory PHP_PROTO_TSRMLS_DC)
void layout_merge(MessageLayout *layout, MessageHeader *from, MessageHeader *to PHP_PROTO_TSRMLS_DC)
#define PHP_PROTO_HASHTABLE_VALUE
const upb_enumdef * upb_fielddef_enumsubdef(const upb_fielddef *f)
upb_value map_iter_value(MapIter *iter, int *len)
#define CASE(upb_type, php_type, c_type)
bool map_done(MapIter *iter)
MessageLayout * create_layout(const upb_msgdef *msgdef)
bool native_slot_set_by_array(upb_fieldtype_t type, const zend_class_entry *klass, void *memory, zval *value TSRMLS_DC)
void layout_set(MessageLayout *layout, MessageHeader *header, const upb_fielddef *field, zval *val TSRMLS_DC)
uint32_t * slot_oneof_case(MessageLayout *layout, const void *storage, const upb_fielddef *field)
void free_layout(MessageLayout *layout)
#define php_proto_zend_hash_index_find_mem(ht, h, pDest)
static void * value_memory(const upb_fielddef *field, void *memory)
#define CASE_TYPE(upb_type, c_type)
#define ALLOC(class_name)
#define UNBOX(class_name, val)
#define ALLOC_N(class_name, n)
void native_slot_init(upb_fieldtype_t type, void *memory, CACHED_VALUE *cache)
const upb_oneofdef * upb_fielddef_containingoneof(const upb_fielddef *f)
bool upb_fielddef_ismap(const upb_fielddef *f)
void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m)
bool is_map_field(const upb_fielddef *field)
#define PHP_PROTO_HASH_OF(array)
#define PHP_PROTO_ZVAL_STRINGL(zval_ptr, s, len, copy)
const char * upb_oneofdef_name(const upb_oneofdef *o)
const char * upb_fielddef_name(const upb_fielddef *f)
php_proto_zval_ptr_dtor(intern->array)
#define OBJ_PROP(OBJECT, OFFSET)
bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter)
const FieldDescriptor * field
const SETUP_TEARDOWN_TESTCONTEXT char * key
const upb_msgdef * tryget_map_entry_msgdef(const upb_fielddef *field)
void native_slot_get_default(upb_fieldtype_t type, CACHED_VALUE *cache TSRMLS_DC)
void check_repeated_field(const zend_class_entry *klass, PHP_PROTO_LONG type, zval *val, zval *return_value)
zend_class_entry * repeated_field_type
const char * layout_get_oneof_case(MessageLayout *layout, const void *storage, const upb_oneofdef *oneof TSRMLS_DC)
void upb_oneof_next(upb_oneof_iter *iter)
const upb_fielddef * map_field_key(const upb_fielddef *field)
upb_fielddef * upb_msg_iter_field(const upb_msg_field_iter *iter)
upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f)
void map_next(MapIter *iter)
@ UPB_DESCRIPTOR_TYPE_MESSAGE
bool is_structurally_valid_utf8(const char *buf, int len)
upb_fielddef * upb_oneof_iter_field(const upb_oneof_iter *iter)
void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o)
#define ZVAL_OBJ(zval_ptr, call_create)
static bool native_slot_is_default(upb_fieldtype_t type, const void *memory)
const upb_msgdef * upb_fielddef_msgsubdef(const upb_fielddef *f)
void upb_msg_field_next(upb_msg_field_iter *iter)
void native_slot_get_by_map_value(upb_fieldtype_t type, const void *memory, CACHED_VALUE *cache TSRMLS_DC)
const upb_msgdef * msgdef
void repeated_field_push_native(RepeatedField *intern, void *value)
PHP_PROTO_HASHTABLE_VALUE get_def_obj(const void *def)
int upb_msgdef_numfields(const upb_msgdef *m)
bool native_slot_set_by_map(upb_fieldtype_t type, const zend_class_entry *klass, void *memory, zval *value TSRMLS_DC)
static size_t align_up_to(size_t offset, size_t granularity)
void map_begin(zval *map_php, MapIter *iter TSRMLS_DC)
#define NATIVE_SLOT_MAX_SIZE
void native_slot_get_by_array(upb_fieldtype_t type, const void *memory, CACHED_VALUE *cache TSRMLS_DC)
bool upb_msg_field_done(const upb_msg_field_iter *iter)
const upb_fielddef * upb_msgdef_itof(const upb_msgdef *m, uint32_t i)
#define MESSAGE_FIELD_NO_CASE
#define CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(zval_ptr, class_type)
void native_slot_get(upb_fieldtype_t type, const void *memory, CACHED_VALUE *cache TSRMLS_DC)
uint32_t upb_fielddef_number(const upb_fielddef *f)
upb_label_t upb_fielddef_label(const upb_fielddef *f)
bool upb_oneof_done(upb_oneof_iter *iter)
const upb_fielddef * map_entry_value(const upb_msgdef *msgdef)
static int slot_property_cache(MessageLayout *layout, const void *storage, const upb_fielddef *field)
GLsizei const GLfloat * value
bool native_slot_set(upb_fieldtype_t type, const zend_class_entry *klass, void *memory, zval *value PHP_PROTO_TSRMLS_DC)
#define php_proto_zend_hash_index_find_zval(ht, h, pDest)
void native_slot_get_by_map_key(upb_fieldtype_t type, const void *memory, int length, CACHED_VALUE *cache TSRMLS_DC)
void upb_msg_oneof_next(upb_msg_oneof_iter *iter)
upb_fieldtype_t value_type
UPB_INLINE size_t upb_strtable_count(const upb_strtable *t)
bool protobuf_convert_to_string(zval *from)
void layout_init(MessageLayout *layout, void *storage, zend_object *object PHP_PROTO_TSRMLS_DC)
const upb_msgdef * map_entry_msgdef(const upb_fielddef *field)
zend_class_entry * map_field_type
uint32_t upb_fielddef_index(const upb_fielddef *f)
#define PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(value)
const upb_fielddef * upb_msgdef_ntof(const upb_msgdef *m, const char *name, size_t len)
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59