Skip to content

Commit cec7fd6

Browse files
author
drswinghead
committed
fix compile warning. fix macro compat.
1 parent 6ba9ef8 commit cec7fd6

File tree

7 files changed

+82
-7
lines changed

7 files changed

+82
-7
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ all:
2828
# $(PHPEXE) -d extension=./hello.so examples/hello.php
2929

3030
clean:
31-
rm -f ../../pkg/linux_amd64/zend.a
32-
rm -f ../../pkg/linux_amd64/phpgo.a
31+
rm -f $(GOPATH)/pkg/linux_amd64/zend.a
32+
rm -f $(GOPATH)/pkg/linux_amd64/phpgo.a
3333
rm -f hello.so

phpgo/extension.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,16 @@ static void* phpgo_function_conv_arg(int cbid, int idx, char ch, int zty, zval *
199199
goapi_new_value(GT_Int64, (uint64_t)arg, &rv);
200200
} else if (ch == 'b') {
201201
convert_to_boolean_ex(conv_zarg);
202+
#ifdef ZEND_ENGINE_3
203+
if (Z_TYPE_P(conv_zarg) == IS_TRUE) {
204+
goapi_new_value(GT_Bool, (uint64_t)1, &rv);
205+
} else {
206+
goapi_new_value(GT_Bool, (uint64_t)0, &rv);
207+
}
208+
#else
202209
zend_bool arg = (zend_bool)Z_BVAL_P(macro_zarg);
203210
goapi_new_value(GT_Bool, (uint64_t)arg, &rv);
211+
#endif
204212
} else if (ch == 'd') {
205213
convert_to_double_ex(conv_zarg);
206214
double arg = (double)Z_DVAL_P(macro_zarg);
@@ -215,12 +223,15 @@ static void* phpgo_function_conv_arg(int cbid, int idx, char ch, int zty, zval *
215223
char *arg = Z_STRVAL_P(macro_zarg);
216224
goapi_new_value(GT_String, (uint64_t)arg, &rv);
217225
#ifdef ZEND_ENGINE_3
218-
} else if (Z_TYPE_P(macro_zarg) == _IS_BOOL) {
226+
} else if (Z_TYPE_P(macro_zarg) == IS_TRUE) {
227+
goapi_new_value(GT_Bool, (uint64_t)1, &rv);
228+
} else if (Z_TYPE_P(macro_zarg) == IS_FALSE) {
229+
goapi_new_value(GT_Bool, (uint64_t)0, &rv);
219230
#else
220231
} else if (Z_TYPE_P(macro_zarg) == IS_BOOL) {
221-
#endif
222232
zend_bool arg = (zend_bool)Z_BVAL_P(macro_zarg);
223233
goapi_new_value(GT_Bool, (uint64_t)arg, &rv);
234+
#endif
224235
} else if (Z_TYPE_P(macro_zarg) == IS_DOUBLE) {
225236
double* parg = calloc(1, sizeof(double));
226237
*parg = (double)Z_DVAL_P(macro_zarg);
@@ -409,7 +420,7 @@ static void phpgo_method_conv_args(int cbid, phpgo_callback_info* cbi, int suppl
409420
static void phpgo_function_reutrn_php_array(void *p0, zval *return_value) {
410421
array_init(return_value);
411422

412-
goapi_set_php_array(p0, &return_value);
423+
goapi_set_php_array(p0, (void**)&return_value);
413424
}
414425

415426
// go类型的返回值转换为PHP类型的变量值
@@ -436,6 +447,12 @@ static int phpgo_function_conv_ret(int cbid, phpgo_callback_info* cbi, void *p0,
436447
free((double*)rv);
437448
break;
438449
#ifdef ZEND_ENGINE_3
450+
case IS_TRUE:
451+
RETVAL_TRUE;
452+
break;
453+
case IS_FALSE:
454+
RETVAL_FALSE;
455+
break;
439456
case _IS_BOOL:
440457
#else
441458
case IS_BOOL:

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ manual:
7373
- [ ] namespace support
7474
- [ ] multiple extension support
7575
- [ ] class member access support
76-
- [ ] unlimited function/method/class count support
76+
- [x] unlimited function/method/class count support
7777

7878

7979
Contributing

zend/clog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void dlog_set_level(int id, enum clog_level level)
1818
}
1919
#warning "defined log level"
2020
#else
21-
#warning "not defined log level"
21+
// #warning "not defined log level"
2222
clog_set_level(id, CLOG_DEBUG);
2323
#endif
2424
}

zend/compat.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@ ZEND_API void zend_register_double_constant_compat(const char *name, size_t name
1717

1818
ZEND_API void zend_register_bool_constant_compat(const char *name, size_t name_len, zend_bool bval, int flags, int module_number)
1919
{
20+
#ifdef ZEND_ENGINE_3
2021
zend_register_bool_constant(name, name_len, bval, flags, module_number);
22+
#else
23+
zend_register_long_constant(name, name_len, bval, flags, module_number);
24+
#endif
2125
}
2226

2327
ZEND_API void zend_register_null_constant_compat(const char *name, size_t name_len, int flags, int module_number)
2428
{
29+
#ifdef ZEND_ENGINE_3
2530
zend_register_null_constant(name, name_len, flags, module_number);
31+
#else
32+
zend_register_stringl_constant(name, name_len, NULL, 0, flags, module_number);
33+
#endif
2634
}
2735

zend/compat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <zend_modules.h>
77

88
#ifdef ZEND_ENGINE_3
9+
// #define Z_BVAL_P(zv) Z_LVAL_P(zv)
910
/*
1011
#define Z_BVAL_PP(zv) Z_LVAL_P(*(zv))
1112
#define Z_LVAL_PP(zv) Z_LVAL_P(*(zv))

zend/goapi.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,54 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
7070

7171
/* End of boilerplate cgo prologue. */
7272

73+
///////////
74+
#ifdef __cplusplus
75+
extern "C" {
76+
#endif
77+
78+
//// put goapi.go's export function here
79+
80+
extern void goapi_array_new(GoInt p0, void** p1);
81+
82+
extern void goapi_array_push(void* p0, void* p1, void** p2);
83+
84+
extern void goapi_map_new(void** p0);
85+
86+
extern void goapi_map_add(void* p0, void* p1, void* p2);
87+
88+
extern void goapi_map_get(void* p0, void* p1, void** p2);
89+
90+
extern void goapi_map_del(void* p0, void* p1);
91+
92+
extern GoUint8 goapi_map_has(void* p0, void* p1);
93+
94+
extern void goapi_chan_new(GoInt p0, GoInt p1, void** p2);
95+
96+
extern void goapi_chan_read(void* p0, void** p1);
97+
98+
extern void goapi_chan_write(void* p0, void* p1);
99+
100+
extern void goapi_chan_close(void* p0);
101+
102+
extern void goapi_type(GoInt p0, void** p1);
103+
104+
extern void goapi_typeof(void* p0, void** p1);
105+
106+
extern GoInt goapi_typeid(void* p0);
107+
108+
extern void goapi_new(GoInt p0, void** p1);
109+
110+
extern void goapi_new_value(GoInt p0, GoUintptr p1, void** p2);
111+
112+
extern void goapi_set_value(void* p0, GoUintptr p1, void** p2);
113+
114+
extern void goapi_set_php_array(void* p0, void** p1);
115+
116+
extern GoUintptr goapi_get_value(void* p0);
117+
118+
#ifdef __cplusplus
119+
}
120+
#endif
121+
73122
#endif
74123

0 commit comments

Comments
 (0)