Fixed compile warnings for PHP extension. (#5589)
* Fixed compile warnings for PHP extension. * Fixed some compile errors on PHP <7 and with TSR enabled. * One more fix for TSRM builds.
This commit is contained in:
parent
6bbd2fc5aa
commit
dd7127d23d
@ -28,6 +28,9 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <php.h>
|
||||
#include <Zend/zend_exceptions.h>
|
||||
|
||||
#include "protobuf.h"
|
||||
|
||||
// Forward declare.
|
||||
|
@ -27,6 +27,9 @@
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
#include <php.h>
|
||||
#include <Zend/zend_exceptions.h>
|
||||
|
||||
#include "protobuf.h"
|
||||
#include "utf8.h"
|
||||
@ -84,6 +87,8 @@ void stringsink_init(stringsink *sink) {
|
||||
|
||||
void stringsink_uninit(stringsink *sink) { free(sink->ptr); }
|
||||
|
||||
void stringsink_uninit_opaque(void *sink) { stringsink_uninit(sink); }
|
||||
|
||||
/* stackenv *****************************************************************/
|
||||
|
||||
// Stack-allocated context during an encode/decode operation. Contains the upb
|
||||
@ -1748,7 +1753,7 @@ PHP_METHOD(Message, serializeToString) {
|
||||
serialize_to_string(getThis(), return_value TSRMLS_CC);
|
||||
}
|
||||
|
||||
void merge_from_string(const char* data, int data_len, const Descriptor* desc,
|
||||
void merge_from_string(const char* data, int data_len, Descriptor* desc,
|
||||
MessageHeader* msg) {
|
||||
const upb_pbdecodermethod* method = msgdef_decodermethod(desc);
|
||||
const upb_handlers* h = upb_pbdecodermethod_desthandlers(method);
|
||||
@ -1900,7 +1905,7 @@ static void discard_unknown_fields(MessageHeader* msg) {
|
||||
for (map_begin(map_php, &map_it TSRMLS_CC);
|
||||
!map_done(&map_it); map_next(&map_it)) {
|
||||
upb_value value = map_iter_value(&map_it, &len);
|
||||
void* memory = raw_value(upb_value_memory(&value), value_field);
|
||||
const void* memory = raw_value(upb_value_memory(&value), value_field);
|
||||
#if PHP_MAJOR_VERSION < 7
|
||||
MessageHeader *submsg = UNBOX(MessageHeader, *(zval**)memory);
|
||||
#else
|
||||
|
@ -167,7 +167,8 @@ static void map_begin_internal(Map *map, MapIter *iter) {
|
||||
upb_strtable_begin(&iter->it, &map->table);
|
||||
}
|
||||
|
||||
static HashTable *map_field_get_gc(zval *object, CACHED_VALUE **table, int *n) {
|
||||
static HashTable *map_field_get_gc(zval *object, CACHED_VALUE **table,
|
||||
int *n TSRMLS_DC) {
|
||||
// TODO(teboring): Unfortunately, zend engine does not support garbage
|
||||
// collection for custom array. We have to use zend engine's native array
|
||||
// instead.
|
||||
@ -294,7 +295,7 @@ static bool map_field_read_dimension(zval *object, zval *key, int type,
|
||||
}
|
||||
}
|
||||
|
||||
static bool map_index_unset(Map *intern, const char* keyval, int length) {
|
||||
static void map_index_unset(Map *intern, const char* keyval, int length) {
|
||||
upb_value old_value;
|
||||
if (upb_strtable_remove2(&intern->table, keyval, length, &old_value)) {
|
||||
switch (intern->value_type) {
|
||||
|
@ -29,9 +29,16 @@
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <php.h>
|
||||
#include <Zend/zend_exceptions.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if PHP_MAJOR_VERSION < 7
|
||||
#include <Zend/zend_compile.h>
|
||||
#else
|
||||
#include <Zend/zend_inheritance.h>
|
||||
#endif
|
||||
|
||||
#include "protobuf.h"
|
||||
#include "utf8.h"
|
||||
|
||||
@ -83,7 +90,7 @@ static HashTable* message_get_properties(zval* object TSRMLS_DC);
|
||||
// Define object free method.
|
||||
PHP_PROTO_OBJECT_FREE_START(MessageHeader, message)
|
||||
if (*(void**)intern->data != NULL) {
|
||||
stringsink_uninit(*(void**)intern->data);
|
||||
stringsink_uninit_opaque(*(void**)intern->data);
|
||||
FREE(*(void**)intern->data);
|
||||
}
|
||||
FREE(intern->data);
|
||||
@ -904,12 +911,11 @@ PHP_METHOD(Field_Cardinality, name) {
|
||||
case 3:
|
||||
PHP_PROTO_RETURN_STRING("CARDINALITY_REPEATED", 1);
|
||||
default:
|
||||
zend_throw_exception(
|
||||
NULL,
|
||||
zend_throw_exception_ex(
|
||||
NULL, 0 TSRMLS_CC,
|
||||
"Enum Google\\Protobuf\\Field_Cardinality has no name "
|
||||
"defined for value %d.",
|
||||
value,
|
||||
0 TSRMLS_CC);
|
||||
value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -927,12 +933,11 @@ PHP_METHOD(Field_Cardinality, value) {
|
||||
if (strncmp(name, "CARDINALITY_REQUIRED", name_len) == 0) RETURN_LONG(2);
|
||||
if (strncmp(name, "CARDINALITY_REPEATED", name_len) == 0) RETURN_LONG(3);
|
||||
|
||||
zend_throw_exception(
|
||||
NULL,
|
||||
zend_throw_exception_ex(
|
||||
NULL, 0 TSRMLS_CC,
|
||||
"Enum Google\\Protobuf\\Field_Cardinality has no value "
|
||||
"defined for name %s.",
|
||||
name,
|
||||
0 TSRMLS_CC);
|
||||
name);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -1042,12 +1047,10 @@ PHP_METHOD(Field_Kind, name) {
|
||||
case 18:
|
||||
PHP_PROTO_RETURN_STRING("TYPE_SINT64", 1);
|
||||
default:
|
||||
zend_throw_exception(
|
||||
NULL,
|
||||
"Enum Google\\Protobuf\\Field_Kind has no name "
|
||||
"defined for value %d.",
|
||||
value,
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Enum Google\\Protobuf\\Field_Kind has no name "
|
||||
"defined for value %d.",
|
||||
value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1080,12 +1083,10 @@ PHP_METHOD(Field_Kind, value) {
|
||||
if (strncmp(name, "TYPE_SINT32", name_len) == 0) RETURN_LONG(17);
|
||||
if (strncmp(name, "TYPE_SINT64", name_len) == 0) RETURN_LONG(18);
|
||||
|
||||
zend_throw_exception(
|
||||
NULL,
|
||||
"Enum Google\\Protobuf\\Field_Kind has no value "
|
||||
"defined for name %s.",
|
||||
name,
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Enum Google\\Protobuf\\Field_Kind has no value "
|
||||
"defined for name %s.",
|
||||
name);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -1117,12 +1118,10 @@ PHP_METHOD(NullValue, name) {
|
||||
case 0:
|
||||
PHP_PROTO_RETURN_STRING("NULL_VALUE", 1);
|
||||
default:
|
||||
zend_throw_exception(
|
||||
NULL,
|
||||
"Enum Google\\Protobuf\\NullValue has no name "
|
||||
"defined for value %d.",
|
||||
value,
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Enum Google\\Protobuf\\NullValue has no name "
|
||||
"defined for value %d.",
|
||||
value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1137,12 +1136,10 @@ PHP_METHOD(NullValue, value) {
|
||||
|
||||
if (strncmp(name, "NULL_VALUE", name_len) == 0) RETURN_LONG(0);
|
||||
|
||||
zend_throw_exception(
|
||||
NULL,
|
||||
"Enum Google\\Protobuf\\NullValue has no value "
|
||||
"defined for name %s.",
|
||||
name,
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Enum Google\\Protobuf\\NullValue has no value "
|
||||
"defined for name %s.",
|
||||
name);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -1178,12 +1175,10 @@ PHP_METHOD(Syntax, name) {
|
||||
case 1:
|
||||
PHP_PROTO_RETURN_STRING("SYNTAX_PROTO3", 1);
|
||||
default:
|
||||
zend_throw_exception(
|
||||
NULL,
|
||||
"Enum Google\\Protobuf\\Syntax has no name "
|
||||
"defined for value %d.",
|
||||
value,
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Enum Google\\Protobuf\\Syntax has no name "
|
||||
"defined for value %d.",
|
||||
value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1199,12 +1194,10 @@ PHP_METHOD(Syntax, value) {
|
||||
if (strncmp(name, "SYNTAX_PROTO2", name_len) == 0) RETURN_LONG(0);
|
||||
if (strncmp(name, "SYNTAX_PROTO3", name_len) == 0) RETURN_LONG(1);
|
||||
|
||||
zend_throw_exception(
|
||||
NULL,
|
||||
"Enum Google\\Protobuf\\Syntax has no value "
|
||||
"defined for name %s.",
|
||||
name,
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Enum Google\\Protobuf\\Syntax has no value "
|
||||
"defined for name %s.",
|
||||
name);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -310,8 +310,10 @@ static inline int php_proto_zend_hash_index_update_mem(HashTable* ht, ulong h,
|
||||
static inline int php_proto_zend_hash_update_zval(HashTable* ht,
|
||||
const char* key, uint key_len,
|
||||
zval* pData) {
|
||||
void* result = NULL;
|
||||
zend_string* internal_key = zend_string_init(key, key_len, 0);
|
||||
zend_hash_update(ht, internal_key, pData);
|
||||
result = zend_hash_update(ht, internal_key, pData);
|
||||
return result != NULL ? SUCCESS : FAILURE;
|
||||
}
|
||||
|
||||
static inline int php_proto_zend_hash_update_mem(HashTable* ht, const char* key,
|
||||
@ -682,6 +684,7 @@ void double_value_init(TSRMLS_D);
|
||||
void duration_init(TSRMLS_D);
|
||||
void empty_init(TSRMLS_D);
|
||||
void enum_descriptor_init(TSRMLS_D);
|
||||
void enum_value_descriptor_init(TSRMLS_D);
|
||||
void enum_init(TSRMLS_D);
|
||||
void enum_value_init(TSRMLS_D);
|
||||
void field_cardinality_init(TSRMLS_D);
|
||||
@ -711,8 +714,8 @@ void struct_init(TSRMLS_D);
|
||||
void syntax_init(TSRMLS_D);
|
||||
void timestamp_init(TSRMLS_D);
|
||||
void type_init(TSRMLS_D);
|
||||
void uint32_value_init(TSRMLS_D);
|
||||
void uint64_value_init(TSRMLS_D);
|
||||
void u_int32_value_init(TSRMLS_D);
|
||||
void u_int64_value_init(TSRMLS_D);
|
||||
void util_init(TSRMLS_D);
|
||||
void value_init(TSRMLS_D);
|
||||
|
||||
@ -966,7 +969,7 @@ PHP_METHOD(Message, __construct);
|
||||
const upb_pbdecodermethod *new_fillmsg_decodermethod(Descriptor *desc,
|
||||
const void *owner);
|
||||
void serialize_to_string(zval* val, zval* return_value TSRMLS_DC);
|
||||
void merge_from_string(const char* data, int data_len, const Descriptor* desc,
|
||||
void merge_from_string(const char* data, int data_len, Descriptor* desc,
|
||||
MessageHeader* msg);
|
||||
|
||||
PHP_METHOD(Message, serializeToString);
|
||||
@ -1448,6 +1451,7 @@ extern zend_class_entry* value_type;
|
||||
upb_fieldtype_t to_fieldtype(upb_descriptortype_t type);
|
||||
const zend_class_entry* field_type_class(
|
||||
const upb_fielddef* field PHP_PROTO_TSRMLS_DC);
|
||||
void stringsink_uninit_opaque(void *sink);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
@ -29,6 +29,7 @@
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <Zend/zend_operators.h>
|
||||
#include <Zend/zend_exceptions.h>
|
||||
|
||||
#include "protobuf.h"
|
||||
#include "utf8.h"
|
||||
@ -434,9 +435,9 @@ PHP_METHOD(Util, checkMessage) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
if (!instanceof_function(Z_OBJCE_P(val), klass TSRMLS_CC)) {
|
||||
zend_throw_exception(
|
||||
NULL, "Given value is not an instance of %s.", klass->name,
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Given value is not an instance of %s.",
|
||||
klass->name);
|
||||
return;
|
||||
}
|
||||
RETURN_ZVAL(val, 1, 0);
|
||||
@ -479,32 +480,27 @@ void check_repeated_field(const zend_class_entry* klass, PHP_PROTO_LONG type,
|
||||
|
||||
} else if (Z_TYPE_P(val) == IS_OBJECT) {
|
||||
if (!instanceof_function(Z_OBJCE_P(val), repeated_field_type TSRMLS_CC)) {
|
||||
zend_throw_exception(
|
||||
NULL, "Given value is not an instance of %s.",
|
||||
repeated_field_type->name,
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Given value is not an instance of %s.",
|
||||
repeated_field_type->name);
|
||||
return;
|
||||
}
|
||||
RepeatedField* intern = UNBOX(RepeatedField, val);
|
||||
if (to_fieldtype(type) != intern->type) {
|
||||
zend_throw_exception(
|
||||
NULL, "Incorrect repeated field type.",
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Incorrect repeated field type.");
|
||||
return;
|
||||
}
|
||||
if (klass != NULL && intern->msg_ce != klass) {
|
||||
zend_throw_exception(
|
||||
NULL, "Expect a repeated field of %s, but %s is given.",
|
||||
klass->name,
|
||||
intern->msg_ce->name,
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Expect a repeated field of %s, but %s is given.",
|
||||
klass->name, intern->msg_ce->name);
|
||||
return;
|
||||
}
|
||||
RETURN_ZVAL(val, 1, 0);
|
||||
} else {
|
||||
zend_throw_exception(
|
||||
NULL, "Incorrect repeated field type.",
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Incorrect repeated field type.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -560,10 +556,9 @@ void check_map_field(const zend_class_entry* klass, PHP_PROTO_LONG key_type,
|
||||
RETURN_ZVAL(CACHED_TO_ZVAL_PTR(map_field), 1, 1);
|
||||
} else if (Z_TYPE_P(val) == IS_OBJECT) {
|
||||
if (!instanceof_function(Z_OBJCE_P(val), map_field_type TSRMLS_CC)) {
|
||||
zend_throw_exception(
|
||||
NULL, "Given value is not an instance of %s.",
|
||||
map_field_type->name,
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Given value is not an instance of %s.",
|
||||
map_field_type->name);
|
||||
return;
|
||||
}
|
||||
Map* intern = UNBOX(Map, val);
|
||||
@ -580,10 +575,9 @@ void check_map_field(const zend_class_entry* klass, PHP_PROTO_LONG key_type,
|
||||
return;
|
||||
}
|
||||
if (klass != NULL && intern->msg_ce != klass) {
|
||||
zend_throw_exception(
|
||||
NULL, "Expect a map field of %s, but %s is given.",
|
||||
klass->name, intern->msg_ce->name,
|
||||
0 TSRMLS_CC);
|
||||
zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
|
||||
"Expect a map field of %s, but %s is given.",
|
||||
klass->name, intern->msg_ce->name);
|
||||
return;
|
||||
}
|
||||
RETURN_ZVAL(val, 1, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user