protobuf/php/ext/google/protobuf/protobuf.h
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef PHP_PROTOBUF_H_
32 #define PHP_PROTOBUF_H_
33 
34 #include <php.h>
35 #include <stdbool.h>
36 
37 #include "php-upb.h"
38 
39 const zval *get_generated_pool();
40 
41 #if PHP_VERSION_ID < 70300
42 #define GC_ADDREF(h) ++GC_REFCOUNT(h)
43 #define GC_DELREF(h) --GC_REFCOUNT(h)
44 #endif
45 
46 // Since php 7.4, the write_property() object handler now returns the assigned
47 // value (after possible type coercions) rather than void.
48 // https://github.com/php/php-src/blob/PHP-7.4.0/UPGRADING.INTERNALS#L171-L173
49 #if PHP_VERSION_ID < 70400
50 #define PROTO_RETURN_VAL void
51 #else
52 #define PROTO_RETURN_VAL zval*
53 #endif
54 
55 // Since php 8.0, the Object Handlers API was changed to receive zend_object*
56 // instead of zval* and zend_string* instead of zval* for property names.
57 // https://github.com/php/php-src/blob/php-8.0.0beta1/UPGRADING.INTERNALS#L37-L39
58 #if PHP_VERSION_ID < 80000
59 #define PROTO_VAL zval
60 #define PROTO_STR zval
61 #define PROTO_VAL_P(obj) (void*)Z_OBJ_P(obj)
62 #define PROTO_STRVAL_P(obj) Z_STRVAL_P(obj)
63 #define PROTO_STRLEN_P(obj) Z_STRLEN_P(obj)
64 #define ZVAL_OBJ_COPY(z, o) do { ZVAL_OBJ(z, o); GC_ADDREF(o); } while (0)
65 #define RETVAL_OBJ_COPY(r) ZVAL_OBJ_COPY(return_value, r)
66 #define RETURN_OBJ_COPY(r) do { RETVAL_OBJ_COPY(r); return; } while (0)
67 #define RETURN_COPY(zv) do { ZVAL_COPY(return_value, zv); return; } while (0)
68 #define RETURN_COPY_VALUE(zv) do { ZVAL_COPY_VALUE(return_value, zv); return; } while (0)
69 #else
70 #define PROTO_VAL zend_object
71 #define PROTO_STR zend_string
72 #define PROTO_VAL_P(obj) (void*)(obj)
73 #define PROTO_STRVAL_P(obj) ZSTR_VAL(obj)
74 #define PROTO_STRLEN_P(obj) ZSTR_LEN(obj)
75 #endif
76 
77 // In PHP 8.1, several old interfaces are removed:
78 // https://github.com/php/php-src/blob/14f599ea7def7c7a59c40aff763ce8b105573e7a/UPGRADING.INTERNALS#L27-L31
79 //
80 // We now use the new interfaces (zend_ce_arrayaccess and zend_ce_countable).
81 // However we have to polyfill zend_ce_countable, which was only introduced in
82 // PHP 7.2.0.
83 #if PHP_VERSION_ID < 70200
84 #define zend_ce_countable spl_ce_Countable
85 #endif
86 
87 ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
88 ZEND_END_ARG_INFO()
89 
90 ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1)
91  ZEND_ARG_INFO(0, value)
92 ZEND_END_ARG_INFO()
93 
94 #define PHP_PROTOBUF_VERSION "3.19.5"
95 
96 // ptr -> PHP object cache. This is a weak map that caches lazily-created
97 // wrapper objects around upb types:
98 // * upb_msg* -> Message
99 // * upb_array* -> RepeatedField
100 // * upb_map*, -> MapField
101 // * upb_msgdef* -> Descriptor
102 // * upb_enumdef* -> EnumDescriptor
103 // * upb_msgdef* -> Descriptor
104 //
105 // Each wrapped object should add itself to the map when it is constructed, and
106 // remove itself from the map when it is destroyed. This is how we ensure that
107 // the map only contains live objects. The map is weak so it does not actually
108 // take references to the cached objects.
109 void ObjCache_Add(const void *key, zend_object *php_obj);
110 void ObjCache_Delete(const void *key);
111 bool ObjCache_Get(const void *key, zval *val);
112 
113 // PHP class name map. This is necessary because the pb_name->php_class_name
114 // transformation is non-reversible, so when we need to look up a msgdef or
115 // enumdef by PHP class, we can't turn the class name into a pb_name.
116 // * php_class_name -> upb_msgdef*
117 // * php_class_name -> upb_enumdef*
118 void NameMap_AddMessage(const upb_msgdef *m);
119 void NameMap_AddEnum(const upb_enumdef *m);
120 const upb_msgdef *NameMap_GetMessage(zend_class_entry *ce);
121 const upb_enumdef *NameMap_GetEnum(zend_class_entry *ce);
122 
123 // Add this descriptor object to the global list of descriptors that will be
124 // kept alive for the duration of the request but destroyed when the request
125 // is ending.
126 void Descriptors_Add(zend_object *desc);
127 
128 // We need our own assert() because PHP takes control of NDEBUG in its headers.
129 #ifdef PBPHP_ENABLE_ASSERTS
130 #define PBPHP_ASSERT(x) \
131  do { \
132  if (!(x)) { \
133  fprintf(stderr, "Assertion failure at %s:%d %s", __FILE__, __LINE__, \
134  #x); \
135  abort(); \
136  } \
137  } while (false)
138 #else
139 #define PBPHP_ASSERT(x) \
140  do { \
141  } while (false && (x))
142 #endif
143 
144 #endif // PHP_PROTOBUF_H_
ObjCache_Get
bool ObjCache_Get(const void *key, zval *val)
Definition: protobuf/php/ext/google/protobuf/protobuf.c:232
NameMap_AddMessage
void NameMap_AddMessage(const upb_msgdef *m)
Definition: protobuf/php/ext/google/protobuf/protobuf.c:249
NameMap_GetEnum
const upb_enumdef * NameMap_GetEnum(zend_class_entry *ce)
Definition: protobuf/php/ext/google/protobuf/protobuf.c:285
Descriptors_Add
void Descriptors_Add(zend_object *desc)
Definition: protobuf/php/ext/google/protobuf/protobuf.c:210
value
const char * value
Definition: hpack_parser_table.cc:165
NameMap_GetMessage
const upb_msgdef * NameMap_GetMessage(zend_class_entry *ce)
Definition: protobuf/php/ext/google/protobuf/protobuf.c:261
key
const char * key
Definition: hpack_parser_table.cc:164
upb_enumdef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2984
ObjCache_Add
void ObjCache_Add(const void *key, zend_object *php_obj)
Definition: protobuf/php/ext/google/protobuf/protobuf.c:219
ObjCache_Delete
void ObjCache_Delete(const void *key)
Definition: protobuf/php/ext/google/protobuf/protobuf.c:224
desc
#define desc
Definition: bloaty/third_party/protobuf/src/google/protobuf/extension_set.h:338
php-upb.h
NameMap_AddEnum
void NameMap_AddEnum(const upb_enumdef *m)
Definition: protobuf/php/ext/google/protobuf/protobuf.c:255
regress.m
m
Definition: regress/regress.py:25
upb_msgdef
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:2962
get_generated_pool
const zval * get_generated_pool()
Definition: protobuf/php/ext/google/protobuf/protobuf.c:94


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:47