del php5 ifdefs from ext

pull/24353/head
root 5 years ago
parent 68a6d1bfb2
commit 3896e9ffce
  1. 26
      src/php/ext/grpc/byte_buffer.c
  2. 5
      src/php/ext/grpc/byte_buffer.h
  3. 37
      src/php/ext/grpc/call.c
  4. 15
      src/php/ext/grpc/call_credentials.c
  5. 4
      src/php/ext/grpc/channel.c
  6. 136
      src/php/ext/grpc/php7_wrapper.h

@ -31,30 +31,6 @@ grpc_byte_buffer *string_to_byte_buffer(char *string, size_t length) {
return buffer;
}
#if PHP_MAJOR_VERSION < 7
void byte_buffer_to_string(grpc_byte_buffer *buffer, char **out_string,
size_t *out_length) {
grpc_byte_buffer_reader reader;
if (buffer == NULL || !grpc_byte_buffer_reader_init(&reader, buffer)) {
/* TODO(dgq): distinguish between the error cases. */
*out_string = NULL;
*out_length = 0;
return;
}
grpc_slice slice = grpc_byte_buffer_reader_readall(&reader);
size_t length = GRPC_SLICE_LENGTH(slice);
char *string = ecalloc(length + 1, sizeof(char));
memcpy(string, GRPC_SLICE_START_PTR(slice), length);
grpc_slice_unref(slice);
*out_string = string;
*out_length = length;
}
#else
zend_string* byte_buffer_to_zend_string(grpc_byte_buffer *buffer) {
grpc_byte_buffer_reader reader;
if (buffer == NULL || !grpc_byte_buffer_reader_init(&reader, buffer)) {
@ -78,5 +54,3 @@ zend_string* byte_buffer_to_zend_string(grpc_byte_buffer *buffer) {
return zstr;
}
#endif // PHP_MAJOR_VERSION < 7

@ -23,11 +23,6 @@
grpc_byte_buffer *string_to_byte_buffer(char *string, size_t length);
#if PHP_MAJOR_VERSION < 7
void byte_buffer_to_string(grpc_byte_buffer *buffer, char **out_string,
size_t *out_length);
#else
zend_string* byte_buffer_to_zend_string(grpc_byte_buffer *buffer);
#endif // PHP_MAJOR_VERSION < 7
#endif /* NET_GRPC_PHP_GRPC_BYTE_BUFFER_H_ */

@ -104,9 +104,7 @@ zval *grpc_parse_metadata_array(grpc_metadata_array
PHP_GRPC_FREE_STD_ZVAL(inner_array);
}
efree(str_key);
#if PHP_MAJOR_VERSION >= 7
efree(str_val);
#endif
}
return array;
}
@ -300,12 +298,7 @@ PHP_METHOD(Call, startBatch) {
int cancelled;
grpc_call_error error;
#if PHP_MAJOR_VERSION < 7
char *message_str;
size_t message_len;
#else
zend_string* zmessage = NULL;
#endif // PHP_MAJOR_VERSION < 7
grpc_metadata_array_init(&metadata);
grpc_metadata_array_init(&trailing_metadata);
@ -463,9 +456,7 @@ PHP_METHOD(Call, startBatch) {
}
grpc_completion_queue_pluck(completion_queue, call->wrapped,
gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
#if PHP_MAJOR_VERSION >= 7
zval *recv_md;
#endif
for (int i = 0; i < op_num; i++) {
switch(ops[i].op) {
case GRPC_OP_SEND_INITIAL_METADATA:
@ -481,54 +472,31 @@ PHP_METHOD(Call, startBatch) {
add_property_bool(result, "send_status", true);
break;
case GRPC_OP_RECV_INITIAL_METADATA:
#if PHP_MAJOR_VERSION < 7
array = grpc_parse_metadata_array(&recv_metadata TSRMLS_CC);
add_property_zval(result, "metadata", array);
#else
recv_md = grpc_parse_metadata_array(&recv_metadata);
add_property_zval(result, "metadata", recv_md);
zval_ptr_dtor(recv_md);
PHP_GRPC_FREE_STD_ZVAL(recv_md);
#endif
PHP_GRPC_DELREF(array);
break;
case GRPC_OP_RECV_MESSAGE:
#if PHP_MAJOR_VERSION < 7
byte_buffer_to_string(message, &message_str, &message_len);
#else
zmessage = byte_buffer_to_zend_string(message);
#endif // PHP_MAJOR_VERSION < 7
#if PHP_MAJOR_VERSION < 7
if (message_str == NULL) {
#else
if (zmessage == NULL) {
#endif // PHP_MAJOR_VERSION < 7
add_property_null(result, "message");
} else {
#if PHP_MAJOR_VERSION < 7
php_grpc_add_property_stringl(result, "message", message_str,
message_len, false);
#else
zval zmessage_val;
ZVAL_NEW_STR(&zmessage_val, zmessage);
add_property_zval(result, "message", &zmessage_val);
zval_ptr_dtor(&zmessage_val);
#endif // PHP_MAJOR_VERSION < 7
}
break;
case GRPC_OP_RECV_STATUS_ON_CLIENT:
PHP_GRPC_MAKE_STD_ZVAL(recv_status);
object_init(recv_status);
#if PHP_MAJOR_VERSION < 7
array = grpc_parse_metadata_array(&recv_trailing_metadata TSRMLS_CC);
add_property_zval(recv_status, "metadata", array);
#else
recv_md = grpc_parse_metadata_array(&recv_trailing_metadata);
add_property_zval(recv_status, "metadata", recv_md);
zval_ptr_dtor(recv_md);
PHP_GRPC_FREE_STD_ZVAL(recv_md);
#endif
PHP_GRPC_DELREF(array);
add_property_long(recv_status, "code", status);
char *status_details_text = grpc_slice_to_c_string(recv_status_details);
@ -536,9 +504,7 @@ PHP_METHOD(Call, startBatch) {
true);
gpr_free(status_details_text);
add_property_zval(result, "status", recv_status);
#if PHP_MAJOR_VERSION >= 7
zval_ptr_dtor(recv_status);
#endif
PHP_GRPC_DELREF(recv_status);
PHP_GRPC_FREE_STD_ZVAL(recv_status);
break;
@ -563,9 +529,6 @@ cleanup:
}
if (ops[i].op == GRPC_OP_RECV_MESSAGE) {
grpc_byte_buffer_destroy(message);
#if PHP_MAJOR_VERSION < 7
PHP_GRPC_FREE_STD_ZVAL(message_str);
#endif // PHP_MAJOR_VERSION < 7
}
}
RETURN_DESTROY_ZVAL(result);

@ -158,16 +158,9 @@ int plugin_get_metadata(
php_grpc_add_property_string(arg, "service_url", context.service_url, true);
php_grpc_add_property_string(arg, "method_name", context.method_name, true);
zval *retval = NULL;
#if PHP_MAJOR_VERSION < 7
zval **params[1];
params[0] = &arg;
state->fci->params = params;
state->fci->retval_ptr_ptr = &retval;
#else
PHP_GRPC_MAKE_STD_ZVAL(retval);
state->fci->params = arg;
state->fci->retval = retval;
#endif
state->fci->param_count = 1;
PHP_GRPC_DELREF(arg);
@ -195,14 +188,10 @@ int plugin_get_metadata(
}
if (retval != NULL) {
#if PHP_MAJOR_VERSION < 7
zval_ptr_dtor(&retval);
#else
zval_ptr_dtor(arg);
zval_ptr_dtor(retval);
PHP_GRPC_FREE_STD_ZVAL(arg);
PHP_GRPC_FREE_STD_ZVAL(retval);
#endif
}
if (should_return) {
return true;
@ -233,10 +222,6 @@ void plugin_destroy_state(void *ptr) {
plugin_state *state = (plugin_state *)ptr;
free(state->fci);
free(state->fci_cache);
#if PHP_MAJOR_VERSION < 7
PHP_GRPC_FREE_STD_ZVAL(state->fci->params);
PHP_GRPC_FREE_STD_ZVAL(state->fci->retval);
#endif
free(state);
}

@ -25,11 +25,7 @@
#include <ext/standard/php_var.h>
#include <ext/standard/sha1.h>
#if PHP_MAJOR_VERSION < 7
#include <ext/standard/php_smart_str.h>
#else
#include <zend_smart_str.h>
#endif
#include <ext/spl/spl_exceptions.h>
#include <zend_exceptions.h>

@ -20,140 +20,6 @@
#ifndef PHP7_WRAPPER_GRPC_H
#define PHP7_WRAPPER_GRPC_H
#if PHP_MAJOR_VERSION < 7
#define php_grpc_int int
#define php_grpc_long long
#define php_grpc_ulong ulong
#define php_grpc_zend_object zend_object_value
#define php_grpc_add_property_string(arg, name, context, b) \
add_property_string(arg, name, context, b)
#define php_grpc_add_property_stringl(res, name, str, len, b) \
add_property_stringl(res, name, str, len, b)
#define php_grpc_add_property_zval(res, name, val) \
add_property_zval(res, name, val)
#define php_grpc_add_next_index_stringl(data, str, len, b) \
add_next_index_stringl(data, str, len, b)
#define PHP_GRPC_RETVAL_STRING(val, dup) RETVAL_STRING(val, dup)
#define PHP_GRPC_RETURN_STRING(val, dup) RETURN_STRING(val, dup)
#define PHP_GRPC_MAKE_STD_ZVAL(pzv) MAKE_STD_ZVAL(pzv)
#define PHP_GRPC_FREE_STD_ZVAL(pzv)
#define PHP_GRPC_DELREF(zv) Z_DELREF_P(zv)
#define PHP_GRPC_ADD_STRING_TO_ARRAY(val, key, key_len, str, dup) \
add_assoc_string_ex(val, key, key_len , str, dup);
#define PHP_GRPC_ADD_LONG_TO_ARRAY(val, key, key_len, str) \
add_assoc_long_ex(val, key, key_len, str);
#define PHP_GRPC_ADD_BOOL_TO_ARRAY(val, key, key_len, str) \
add_assoc_bool_ex(val, key, key_len, str);
#define PHP_GRPC_ADD_LONG_TO_RETVAL(val, key, key_len, str) \
add_assoc_long_ex(val, key, key_len+1, str);
#define RETURN_DESTROY_ZVAL(val) \
RETURN_ZVAL(val, false /* Don't execute copy constructor */, \
true /* Dealloc original before returning */)
#define PHP_GRPC_WRAP_OBJECT_START(name) \
typedef struct name { \
zend_object std;
#define PHP_GRPC_WRAP_OBJECT_END(name) \
} name;
#define PHP_GRPC_FREE_WRAPPED_FUNC_START(class_object) \
void free_##class_object(void *object TSRMLS_DC) { \
class_object *p = (class_object *)object;
#define PHP_GRPC_FREE_WRAPPED_FUNC_END() \
zend_object_std_dtor(&p->std TSRMLS_CC); \
efree(p); \
}
#define PHP_GRPC_ALLOC_CLASS_OBJECT(class_object) \
class_object *intern; \
zend_object_value retval; \
intern = (class_object *)emalloc(sizeof(class_object)); \
memset(intern, 0, sizeof(class_object));
#define PHP_GRPC_FREE_CLASS_OBJECT(class_object, handler) \
retval.handle = zend_objects_store_put( \
intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, \
free_##class_object, NULL TSRMLS_CC); \
retval.handlers = zend_get_std_object_handlers(); \
return retval;
#define PHP_GRPC_HASH_FOREACH_VAL_START(ht, data) \
zval **tmp_data = NULL; \
for (zend_hash_internal_pointer_reset(ht); \
zend_hash_get_current_data(ht, (void**)&tmp_data) == SUCCESS; \
zend_hash_move_forward(ht)) { \
data = *tmp_data;
#define PHP_GRPC_HASH_FOREACH_STR_KEY_VAL_START(ht, key, key_type, data) \
zval **tmp##key = NULL; \
ulong index##key; \
uint len##key; \
for (zend_hash_internal_pointer_reset(ht); \
zend_hash_get_current_data(ht, (void**)&tmp##key) == SUCCESS; \
zend_hash_move_forward(ht)) { \
key_type = zend_hash_get_current_key_ex(ht, &key, &len##key, &index##key,\
0, NULL); \
data = *tmp##key;
#define PHP_GRPC_HASH_VALPTR_TO_VAL(data) \
&data;
#define PHP_GRPC_HASH_FOREACH_LONG_KEY_VAL_START(ht, key, key_type, index,\
data) \
zval **tmp##key = NULL; \
uint len##key; \
for (zend_hash_internal_pointer_reset(ht); \
zend_hash_get_current_data(ht, (void**)&tmp##key) == SUCCESS; \
zend_hash_move_forward(ht)) { \
key_type = zend_hash_get_current_key_ex(ht, &key, &len##key, &index,\
0, NULL); \
data = *tmp##key;
#define PHP_GRPC_HASH_FOREACH_END() }
static inline int php_grpc_zend_hash_find(HashTable *ht, char *key, int len,
void **value) {
zval **data = NULL;
if (zend_hash_find(ht, key, len, (void **)&data) == SUCCESS) {
*value = *data;
return SUCCESS;
} else {
*value = NULL;
return FAILURE;
}
}
#define php_grpc_zend_hash_del zend_hash_del
#define php_grpc_zend_resource zend_rsrc_list_entry
#define PHP_GRPC_BVAL_IS_TRUE(zv) Z_LVAL_P(zv)
#define PHP_GRPC_VAR_SERIALIZE(buf, zv, hash) \
php_var_serialize(buf, &zv, hash TSRMLS_CC)
#define PHP_GRPC_SERIALIZED_BUF_STR(buf) buf.c
#define PHP_GRPC_SERIALIZED_BUF_LEN(buf) buf.len
#define PHP_GRPC_SHA1Update(cxt, str, len) \
PHP_SHA1Update(cxt, (const unsigned char *)str, len)
#define PHP_GRPC_PERSISTENT_LIST_FIND(plist, key, len, rsrc) \
zend_hash_find(plist, key, len+1, (void **)&rsrc) != FAILURE
#define PHP_GRPC_PERSISTENT_LIST_UPDATE(plist, key, len, rsrc) \
zend_hash_update(plist, key, len+1, rsrc, sizeof(php_grpc_zend_resource), \
NULL)
#define PHP_GRPC_PERSISTENT_LIST_SIZE(plist) \
*plist.nNumOfElements
#define PHP_GRPC_GET_CLASS_ENTRY(object) zend_get_class_entry(object TSRMLS_CC)
#define PHP_GRPC_INIT_HANDLER(class_object, handler_name)
#define PHP_GRPC_DECLARE_OBJECT_HANDLER(handler_name)
#define PHP_GRPC_GET_WRAPPED_OBJECT(class_object, zv) \
(class_object *)zend_object_store_get_object(zv TSRMLS_CC)
#else
#define php_grpc_int size_t
#define php_grpc_long zend_long
@ -283,6 +149,4 @@ static inline int php_grpc_zend_hash_del(HashTable *ht, char *key, int len) {
#define PHP_GRPC_GET_WRAPPED_OBJECT(class_object, zv) \
class_object##_from_obj(Z_OBJ_P((zv)))
#endif /* PHP_MAJOR_VERSION */
#endif /* PHP7_WRAPPER_GRPC_H */

Loading…
Cancel
Save