Commit 96e2d764 authored by Bo Yang's avatar Bo Yang

Fix compile error for php on Mac.

parent 75b69887
...@@ -30,7 +30,7 @@ env: ...@@ -30,7 +30,7 @@ env:
- CONFIG=ruby21 - CONFIG=ruby21
- CONFIG=ruby22 - CONFIG=ruby22
- CONFIG=jruby - CONFIG=jruby
- CONFIG=php5.5_mac - CONFIG=php5.6_mac
matrix: matrix:
exclude: exclude:
# It's nontrivial to programmatically install a new JDK from the command # It's nontrivial to programmatically install a new JDK from the command
......
...@@ -169,7 +169,7 @@ static void repeated_field_write_dimension(zval *object, zval *offset, ...@@ -169,7 +169,7 @@ static void repeated_field_write_dimension(zval *object, zval *offset,
} else { } else {
if (protobuf_convert_to_uint64(offset, &index)) { if (protobuf_convert_to_uint64(offset, &index)) {
if (!zend_hash_index_exists(ht, index)) { if (!zend_hash_index_exists(ht, index)) {
zend_error(E_USER_ERROR, "Element at %d doesn't exist.\n", index); zend_error(E_USER_ERROR, "Element at %llu doesn't exist.\n", index);
return; return;
} }
} else { } else {
...@@ -222,7 +222,7 @@ void repeated_field_create_with_type(zend_class_entry *ce, ...@@ -222,7 +222,7 @@ void repeated_field_create_with_type(zend_class_entry *ce,
zend_object_store_get_object(*repeated_field TSRMLS_CC); zend_object_store_get_object(*repeated_field TSRMLS_CC);
intern->type = upb_fielddef_type(field); intern->type = upb_fielddef_type(field);
if (intern->type == UPB_TYPE_MESSAGE) { if (intern->type == UPB_TYPE_MESSAGE) {
upb_msgdef *msg = upb_fielddef_msgsubdef(field); const upb_msgdef *msg = upb_fielddef_msgsubdef(field);
zval *desc_php = get_def_obj(msg); zval *desc_php = get_def_obj(msg);
Descriptor *desc = zend_object_store_get_object(desc_php TSRMLS_CC); Descriptor *desc = zend_object_store_get_object(desc_php TSRMLS_CC);
intern->msg_ce = desc->klass; intern->msg_ce = desc->klass;
...@@ -321,7 +321,7 @@ PHP_METHOD(RepeatedField, offsetGet) { ...@@ -321,7 +321,7 @@ PHP_METHOD(RepeatedField, offsetGet) {
HashTable *table = HASH_OF(intern->array); HashTable *table = HASH_OF(intern->array);
if (zend_hash_index_find(table, index, (void **)&memory) == FAILURE) { if (zend_hash_index_find(table, index, (void **)&memory) == FAILURE) {
zend_error(E_USER_ERROR, "Element at %d doesn't exist.\n", index); zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
return; return;
} }
...@@ -365,7 +365,7 @@ PHP_METHOD(RepeatedField, offsetUnset) { ...@@ -365,7 +365,7 @@ PHP_METHOD(RepeatedField, offsetUnset) {
// Only the element at the end of the array can be removed. // Only the element at the end of the array can be removed.
if (index == -1 || if (index == -1 ||
index != (zend_hash_num_elements(HASH_OF(intern->array)) - 1)) { index != (zend_hash_num_elements(HASH_OF(intern->array)) - 1)) {
zend_error(E_USER_ERROR, "Cannot remove element at %d.\n", index); zend_error(E_USER_ERROR, "Cannot remove element at %ld.\n", index);
return; return;
} }
......
...@@ -318,7 +318,8 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) { ...@@ -318,7 +318,8 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) {
add_def_obj(desc->def_type_lower, desc_php); \ add_def_obj(desc->def_type_lower, desc_php); \
/* Unlike other messages, MapEntry is shared by all map fields and doesn't \ /* Unlike other messages, MapEntry is shared by all map fields and doesn't \
* have generated PHP class.*/ \ * have generated PHP class.*/ \
if (upb_def_type(def) == UPB_DEF_MSG && upb_msgdef_mapentry(def)) { \ if (upb_def_type(def) == UPB_DEF_MSG && \
upb_msgdef_mapentry(upb_downcast_msgdef(def))) { \
break; \ break; \
} \ } \
/* Prepend '.' to package name to make it absolute. */ \ /* Prepend '.' to package name to make it absolute. */ \
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "protobuf.h" #include "protobuf.h"
#include "utf8.h"
/* stringsink *****************************************************************/ /* stringsink *****************************************************************/
...@@ -416,7 +417,8 @@ static void map_slot_uninit(void* memory, upb_fieldtype_t type) { ...@@ -416,7 +417,8 @@ static void map_slot_uninit(void* memory, upb_fieldtype_t type) {
} }
} }
static void map_slot_key(upb_fieldtype_t type, const void* from, char** keyval, static void map_slot_key(upb_fieldtype_t type, const void* from,
const char** keyval,
size_t* length) { size_t* length) {
if (type == UPB_TYPE_STRING) { if (type == UPB_TYPE_STRING) {
zval* key_php = **(zval***)from; zval* key_php = **(zval***)from;
...@@ -891,7 +893,7 @@ static upb_selector_t getsel(const upb_fielddef* f, upb_handlertype_t type) { ...@@ -891,7 +893,7 @@ static upb_selector_t getsel(const upb_fielddef* f, upb_handlertype_t type) {
return ret; return ret;
} }
static void put_optional_value(void* memory, int len, const upb_fielddef* f, static void put_optional_value(const void* memory, int len, const upb_fielddef* f,
int depth, upb_sink* sink TSRMLS_DC) { int depth, upb_sink* sink TSRMLS_DC) {
assert(upb_fielddef_label(f) == UPB_LABEL_OPTIONAL); assert(upb_fielddef_label(f) == UPB_LABEL_OPTIONAL);
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <Zend/zend_interfaces.h> #include <Zend/zend_interfaces.h>
#include "protobuf.h" #include "protobuf.h"
#include "utf8.h"
ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, index)
...@@ -152,7 +153,7 @@ static zend_function_entry map_field_methods[] = { ...@@ -152,7 +153,7 @@ static zend_function_entry map_field_methods[] = {
zend_class_entry* map_field_type; zend_class_entry* map_field_type;
zend_object_handlers* map_field_handlers; zend_object_handlers* map_field_handlers;
static map_begin_internal(Map *map, MapIter *iter) { static void map_begin_internal(Map *map, MapIter *iter) {
iter->self = map; iter->self = map;
upb_strtable_begin(&iter->it, &map->table); upb_strtable_begin(&iter->it, &map->table);
} }
...@@ -258,8 +259,8 @@ static void map_field_free_element(void *object) { ...@@ -258,8 +259,8 @@ static void map_field_free_element(void *object) {
// MapField Handlers // MapField Handlers
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static bool *map_field_read_dimension(zval *object, zval *key, int type, static bool map_field_read_dimension(zval *object, zval *key, int type,
zval **retval TSRMLS_DC) { zval **retval TSRMLS_DC) {
Map *intern = Map *intern =
(Map *)zend_object_store_get_object(object TSRMLS_CC); (Map *)zend_object_store_get_object(object TSRMLS_CC);
...@@ -398,7 +399,7 @@ PHP_METHOD(MapField, offsetExists) { ...@@ -398,7 +399,7 @@ PHP_METHOD(MapField, offsetExists) {
v.ctype = UPB_CTYPE_UINT64; v.ctype = UPB_CTYPE_UINT64;
#endif #endif
if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) { if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) {
return false; RETURN_BOOL(false);
} }
RETURN_BOOL(upb_strtable_lookup2(&intern->table, keyval, length, &v)); RETURN_BOOL(upb_strtable_lookup2(&intern->table, keyval, length, &v));
...@@ -434,7 +435,7 @@ PHP_METHOD(MapField, offsetUnset) { ...@@ -434,7 +435,7 @@ PHP_METHOD(MapField, offsetUnset) {
PHP_METHOD(MapField, count) { PHP_METHOD(MapField, count) {
Map *intern = Map *intern =
(MapField *)zend_object_store_get_object(getThis() TSRMLS_CC); (Map *)zend_object_store_get_object(getThis() TSRMLS_CC);
if (zend_parse_parameters_none() == FAILURE) { if (zend_parse_parameters_none() == FAILURE) {
return; return;
......
...@@ -55,7 +55,7 @@ static void add_to_table(HashTable* t, const void* def, void* value) { ...@@ -55,7 +55,7 @@ static void add_to_table(HashTable* t, const void* def, void* value) {
uint nIndex = (ulong)def & t->nTableMask; uint nIndex = (ulong)def & t->nTableMask;
zval* pDest = NULL; zval* pDest = NULL;
zend_hash_index_update(t, (zend_ulong)def, &value, sizeof(zval*), &pDest); zend_hash_index_update(t, (zend_ulong)def, &value, sizeof(zval*), (void**)&pDest);
} }
static void* get_from_table(const HashTable* t, const void* def) { static void* get_from_table(const HashTable* t, const void* def) {
...@@ -69,7 +69,7 @@ static void* get_from_table(const HashTable* t, const void* def) { ...@@ -69,7 +69,7 @@ static void* get_from_table(const HashTable* t, const void* def) {
static void add_to_list(HashTable* t, void* value) { static void add_to_list(HashTable* t, void* value) {
zval* pDest = NULL; zval* pDest = NULL;
zend_hash_next_index_insert(t, &value, sizeof(void*), &pDest); zend_hash_next_index_insert(t, &value, sizeof(void*), (void**)&pDest);
} }
void add_def_obj(const void* def, zval* value) { void add_def_obj(const void* def, zval* value) {
...@@ -134,6 +134,8 @@ static PHP_RINIT_FUNCTION(protobuf) { ...@@ -134,6 +134,8 @@ static PHP_RINIT_FUNCTION(protobuf) {
generated_pool = NULL; generated_pool = NULL;
generated_pool_php = NULL; generated_pool_php = NULL;
return 0;
} }
static PHP_RSHUTDOWN_FUNCTION(protobuf) { static PHP_RSHUTDOWN_FUNCTION(protobuf) {
...@@ -147,6 +149,8 @@ static PHP_RSHUTDOWN_FUNCTION(protobuf) { ...@@ -147,6 +149,8 @@ static PHP_RSHUTDOWN_FUNCTION(protobuf) {
zval_dtor(generated_pool_php); zval_dtor(generated_pool_php);
FREE_ZVAL(generated_pool_php); FREE_ZVAL(generated_pool_php);
} }
return 0;
} }
static PHP_MINIT_FUNCTION(protobuf) { static PHP_MINIT_FUNCTION(protobuf) {
...@@ -158,10 +162,14 @@ static PHP_MINIT_FUNCTION(protobuf) { ...@@ -158,10 +162,14 @@ static PHP_MINIT_FUNCTION(protobuf) {
descriptor_init(TSRMLS_C); descriptor_init(TSRMLS_C);
enum_descriptor_init(TSRMLS_C); enum_descriptor_init(TSRMLS_C);
util_init(TSRMLS_C); util_init(TSRMLS_C);
return 0;
} }
static PHP_MSHUTDOWN_FUNCTION(protobuf) { static PHP_MSHUTDOWN_FUNCTION(protobuf) {
PEFREE(message_handlers); PEFREE(message_handlers);
PEFREE(repeated_field_handlers); PEFREE(repeated_field_handlers);
PEFREE(map_field_handlers); PEFREE(map_field_handlers);
return 0;
} }
...@@ -70,14 +70,6 @@ typedef struct MapField MapField; ...@@ -70,14 +70,6 @@ typedef struct MapField MapField;
ZEND_BEGIN_MODULE_GLOBALS(protobuf) ZEND_BEGIN_MODULE_GLOBALS(protobuf)
ZEND_END_MODULE_GLOBALS(protobuf) ZEND_END_MODULE_GLOBALS(protobuf)
ZEND_DECLARE_MODULE_GLOBALS(protobuf)
#ifdef ZTS
#define PROTOBUF_G(v) TSRMG(protobuf_globals_id, zend_protobuf_globals*, v)
#else
#define PROTOBUF_G(v) (protobuf_globals.v)
#endif
// Init module and PHP classes. // Init module and PHP classes.
void descriptor_init(TSRMLS_D); void descriptor_init(TSRMLS_D);
void enum_descriptor_init(TSRMLS_D); void enum_descriptor_init(TSRMLS_D);
...@@ -347,6 +339,7 @@ void* upb_value_memory(upb_value* v); ...@@ -347,6 +339,7 @@ void* upb_value_memory(upb_value* v);
// These operate on a map field (i.e., a repeated field of submessages whose // These operate on a map field (i.e., a repeated field of submessages whose
// submessage type is a map-entry msgdef). // submessage type is a map-entry msgdef).
bool is_map_field(const upb_fielddef* field);
const upb_fielddef* map_field_key(const upb_fielddef* field); const upb_fielddef* map_field_key(const upb_fielddef* field);
const upb_fielddef* map_field_value(const upb_fielddef* field); const upb_fielddef* map_field_value(const upb_fielddef* field);
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include <protobuf.h> #include <protobuf.h>
#include <Zend/zend.h> #include <Zend/zend.h>
#include "utf8.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Native slot storage. // Native slot storage.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -210,7 +212,7 @@ CASE(ENUM, LONG, uint32_t) ...@@ -210,7 +212,7 @@ CASE(ENUM, LONG, uint32_t)
return; return;
} }
default: default:
return EG(uninitialized_zval_ptr); return;
} }
} }
...@@ -245,7 +247,7 @@ void native_slot_get_default(upb_fieldtype_t type, zval** cache TSRMLS_DC) { ...@@ -245,7 +247,7 @@ void native_slot_get_default(upb_fieldtype_t type, zval** cache TSRMLS_DC) {
return; return;
} }
default: default:
return EG(uninitialized_zval_ptr); return;
} }
} }
...@@ -305,6 +307,7 @@ const zend_class_entry* field_type_class(const upb_fielddef* field TSRMLS_DC) { ...@@ -305,6 +307,7 @@ const zend_class_entry* field_type_class(const upb_fielddef* field TSRMLS_DC) {
EnumDescriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); EnumDescriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC);
return desc->klass; return desc->klass;
} }
return NULL;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -517,7 +520,7 @@ void layout_set(MessageLayout* layout, MessageHeader* header, ...@@ -517,7 +520,7 @@ void layout_set(MessageLayout* layout, MessageHeader* header,
// zval in properties table first. // zval in properties table first.
switch (type) { switch (type) {
case UPB_TYPE_MESSAGE: { case UPB_TYPE_MESSAGE: {
upb_msgdef* msg = upb_fielddef_msgsubdef(field); const upb_msgdef* msg = upb_fielddef_msgsubdef(field);
zval* desc_php = get_def_obj(msg); zval* desc_php = get_def_obj(msg);
Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC);
ce = desc->klass; ce = desc->klass;
...@@ -551,7 +554,7 @@ void layout_set(MessageLayout* layout, MessageHeader* header, ...@@ -551,7 +554,7 @@ void layout_set(MessageLayout* layout, MessageHeader* header,
upb_fieldtype_t type = upb_fielddef_type(field); upb_fieldtype_t type = upb_fielddef_type(field);
zend_class_entry *ce = NULL; zend_class_entry *ce = NULL;
if (type == UPB_TYPE_MESSAGE) { if (type == UPB_TYPE_MESSAGE) {
upb_msgdef* msg = upb_fielddef_msgsubdef(field); const upb_msgdef* msg = upb_fielddef_msgsubdef(field);
zval* desc_php = get_def_obj(msg); zval* desc_php = get_def_obj(msg);
Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC);
ce = desc->klass; ce = desc->klass;
......
...@@ -58,7 +58,7 @@ bool is_structurally_valid_utf8(const char* buf, int len) { ...@@ -58,7 +58,7 @@ bool is_structurally_valid_utf8(const char* buf, int len) {
return false; return false;
} }
for (j = i + 1; j < i + offset; j++) { for (j = i + 1; j < i + offset; j++) {
if (buf[j] & 0xc0 != 0x80) { if ((buf[j] & 0xc0) != 0x80) {
return false; return false;
} }
} }
......
...@@ -24,9 +24,4 @@ done ...@@ -24,9 +24,4 @@ done
# Make sure to run the memory test in debug mode. # Make sure to run the memory test in debug mode.
php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
php --version
which php
pwd
ls
ls -l `which php`
USE_ZEND_ALLOC=0 valgrind --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php USE_ZEND_ALLOC=0 valgrind --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
...@@ -369,12 +369,6 @@ build_php5.5_c() { ...@@ -369,12 +369,6 @@ build_php5.5_c() {
cd php/tests && /bin/bash ./test.sh && cd ../.. cd php/tests && /bin/bash ./test.sh && cd ../..
} }
build_php5.5_mac() {
curl -s https://php-osx.liip.ch/install.sh | bash -s 5.5
export PATH="/usr/local/php5-5.5.38-20160831-100002/bin:$PATH"
cd php/tests && /bin/bash ./test.sh && cd ../..
}
build_php5.5_zts_c() { build_php5.5_zts_c() {
use_php_zts 5.5 use_php_zts 5.5
wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit
...@@ -393,6 +387,25 @@ build_php5.6_c() { ...@@ -393,6 +387,25 @@ build_php5.6_c() {
cd php/tests && /bin/bash ./test.sh && cd ../.. cd php/tests && /bin/bash ./test.sh && cd ../..
} }
build_php5.6_mac() {
# Install PHP
curl -s https://php-osx.liip.ch/install.sh | bash -s 5.6
export PATH="/usr/local/php5-5.6.25-20160831-101628/bin:$PATH"
# Install phpunit
curl https://phar.phpunit.de/phpunit.phar -L -o phpunit.phar
chmod +x phpunit.phar
sudo mv phpunit.phar /usr/local/bin/phpunit
# Install valgrind
echo "#! /bin/bash" > valgrind
chmod ug+x valgrind
sudo mv valgrind /usr/local/bin/valgrind
# Test
cd php/tests && /bin/bash ./test.sh && cd ../..
}
build_php7.0() { build_php7.0() {
use_php 7.0 use_php 7.0
rm -rf vendor rm -rf vendor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment