summaryrefslogtreecommitdiffstats
path: root/5b075fd0afe0e3df78ba12edb4074ccd5c131984.patch
blob: 04b10d7fde50c851ec8e8524fe4839f09cf9847d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
From 5b075fd0afe0e3df78ba12edb4074ccd5c131984 Mon Sep 17 00:00:00 2001
From: Bo Yang <teboring@google.com>
Date: Tue, 3 Dec 2019 02:17:50 +0000
Subject: [PATCH] Fix comments

---
 php/ext/google/protobuf/message.c    | 21 ++++++++++++++++++++-
 php/ext/google/protobuf/type_check.c | 24 ++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c
index 9adf3b0179..7f6947c2ca 100644
--- a/php/ext/google/protobuf/message.c
+++ b/php/ext/google/protobuf/message.c
@@ -75,8 +75,13 @@ static zval** message_get_property_ptr_ptr(zval* object, zval* member, int type,
                                            php_proto_zend_literal key TSRMLS_DC);
 static HashTable* message_get_gc(zval* object, zval*** table, int* n TSRMLS_DC);
 #else
+#if PHP_VERSION_ID < 70400
 static void message_set_property(zval* object, zval* member, zval* value,
                                  void** cache_slot);
+#else
+static zval* message_set_property(zval* object, zval* member, zval* value,
+                                  void** cache_slot);
+#endif
 static zval* message_get_property(zval* object, zval* member, int type,
                                   void** cache_slot, zval* rv);
 static zval* message_get_property_ptr_ptr(zval* object, zval* member, int type,
@@ -140,13 +145,20 @@ static void message_set_property_internal(zval* object, zval* member,
 #if PHP_MAJOR_VERSION < 7
 static void message_set_property(zval* object, zval* member, zval* value,
                                  php_proto_zend_literal key TSRMLS_DC) {
-#else
+#elif PHP_VERSION_ID < 70400
 static void message_set_property(zval* object, zval* member, zval* value,
                                  void** cache_slot) {
+#else
+static zval* message_set_property(zval* object, zval* member, zval* value,
+                                  void** cache_slot) {
 #endif
   if (Z_TYPE_P(member) != IS_STRING) {
     zend_error(E_USER_ERROR, "Unexpected type for field name");
+#if PHP_VERSION_ID < 70400
     return;
+#else
+    return value;
+#endif
   }
 
 #if PHP_MAJOR_VERSION < 7 || (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 0)
@@ -156,10 +168,17 @@ static void message_set_property(zval* object, zval* member, zval* value,
 #endif
     // User cannot set property directly (e.g., $m->a = 1)
     zend_error(E_USER_ERROR, "Cannot access private property.");
+#if PHP_VERSION_ID < 70400
     return;
+#else
+    return value;
+#endif
   }
 
   message_set_property_internal(object, member, value TSRMLS_CC);
+#if PHP_VERSION_ID >= 70400
+  return value;
+#endif
 }
 
 static zval* message_get_property_internal(zval* object,
diff --git a/php/ext/google/protobuf/type_check.c b/php/ext/google/protobuf/type_check.c
index af35b90318..84d06be7ef 100644
--- a/php/ext/google/protobuf/type_check.c
+++ b/php/ext/google/protobuf/type_check.c
@@ -407,8 +407,6 @@ bool protobuf_convert_to_bool(zval* from, int8_t* to) {
       *to = (int8_t)(Z_LVAL_P(from) != 0);
       break;
     case IS_STRING: {
-      char* strval = Z_STRVAL_P(from);
-
       if (Z_STRLEN_P(from) == 0 ||
           (Z_STRLEN_P(from) == 1 && Z_STRVAL_P(from)[0] == '0')) {
         *to = 0;
@@ -496,7 +494,11 @@ PHP_METHOD(Util, checkMessage) {
   if (!instanceof_function(Z_OBJCE_P(val), klass TSRMLS_CC)) {
     zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
                             "Given value is not an instance of %s.",
+#if PHP_MAJOR_VERSION < 7
                             klass->name);
+#else
+                            ZSTR_VAL(klass->name));
+#endif
     return;
   }
   RETURN_ZVAL(val, 1, 0);
@@ -541,7 +543,11 @@ void check_repeated_field(const zend_class_entry* klass, PHP_PROTO_LONG type,
     if (!instanceof_function(Z_OBJCE_P(val), repeated_field_type TSRMLS_CC)) {
       zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
                               "Given value is not an instance of %s.",
+#if PHP_MAJOR_VERSION < 7
                               repeated_field_type->name);
+#else
+                              ZSTR_VAL(repeated_field_type->name));
+#endif
       return;
     }
     RepeatedField* intern = UNBOX(RepeatedField, val);
@@ -553,7 +559,12 @@ void check_repeated_field(const zend_class_entry* klass, PHP_PROTO_LONG type,
     if (klass != NULL && intern->msg_ce != klass) {
       zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
                               "Expect a repeated field of %s, but %s is given.",
+#if PHP_MAJOR_VERSION < 7
                               klass->name, intern->msg_ce->name);
+#else
+                              ZSTR_VAL(klass->name),
+                              ZSTR_VAL(intern->msg_ce->name));
+#endif
       return;
     }
     RETURN_ZVAL(val, 1, 0);
@@ -617,7 +628,11 @@ void check_map_field(const zend_class_entry* klass, PHP_PROTO_LONG key_type,
     if (!instanceof_function(Z_OBJCE_P(val), map_field_type TSRMLS_CC)) {
       zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
                               "Given value is not an instance of %s.",
+#if PHP_MAJOR_VERSION < 7
                               map_field_type->name);
+#else
+                              ZSTR_VAL(map_field_type->name));
+#endif
       return;
     }
     Map* intern = UNBOX(Map, val);
@@ -636,7 +651,12 @@ void check_map_field(const zend_class_entry* klass, PHP_PROTO_LONG key_type,
     if (klass != NULL && intern->msg_ce != klass) {
       zend_throw_exception_ex(NULL, 0 TSRMLS_CC,
                               "Expect a map field of %s, but %s is given.",
+#if PHP_MAJOR_VERSION < 7
                               klass->name, intern->msg_ce->name);
+#else
+                              ZSTR_VAL(klass->name),
+                              ZSTR_VAL(intern->msg_ce->name));
+#endif
       return;
     }
     RETURN_ZVAL(val, 1, 0);