Skip to content

Commit 61b9d7b

Browse files
committed
Add alias to smart_str to be compatible with PHP7
1 parent 6023f44 commit 61b9d7b

File tree

9 files changed

+109
-109
lines changed

9 files changed

+109
-109
lines changed

src/php_tarantool.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99
#include <zend_exceptions.h>
1010

1111
#include <ext/standard/info.h>
12-
#include <ext/standard/php_smart_str.h>
1312

13+
#if PHP_VERSION_ID >= 70000
14+
# include <ext/standard/php_smart_string.h>
15+
#else
16+
# include <ext/standard/php_smart_str.h>
17+
typedef smart_str smart_string;
18+
# define smart_string_alloc4(...) smart_str_alloc4(__VA_ARGS__)
19+
# define smart_string_free_ex(...) smart_str_free_ex(__VA_ARGS__)
20+
#endif
1421

1522
extern zend_module_entry tarantool_module_entry;
1623
#define phpext_tarantool_ptr &tarantool_module_entry
@@ -33,9 +40,6 @@ extern zend_module_entry tarantool_module_entry;
3340
#include "TSRM.h"
3441
#endif
3542

36-
#include <ext/standard/php_smart_str.h>
37-
#include <php_network.h>
38-
3943
struct pool_manager;
4044
struct tarantool_schema;
4145

@@ -79,17 +83,17 @@ ZEND_EXTERN_MODULE_GLOBALS(tarantool);
7983

8084
typedef struct tarantool_object {
8185
zend_object zo;
82-
char *host;
83-
int port;
84-
char *login;
85-
char *passwd;
86-
php_stream *stream;
87-
char *persistent_id;
88-
smart_str *value;
89-
struct tp *tps;
90-
char auth;
91-
char *greeting;
92-
char *salt;
86+
char *host;
87+
int port;
88+
char *login;
89+
char *passwd;
90+
php_stream *stream;
91+
char *persistent_id;
92+
smart_string *value;
93+
struct tp *tps;
94+
char auth;
95+
char *greeting;
96+
char *salt;
9397
struct tarantool_schema *schema;
9498
} tarantool_object;
9599

src/tarantool.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ now_gettimeofday(void)
2121
return t.tv_sec * 1e9 + t.tv_usec * 1e3;
2222
}
2323

24-
void smart_str_nullify(smart_str *str);
24+
void smart_string_nullify(smart_string *str);
2525

2626
ZEND_DECLARE_MODULE_GLOBALS(tarantool)
2727

@@ -111,7 +111,7 @@ tarantool_stream_send(tarantool_object *obj TSRMLS_DC) {
111111
SSTR_LEN(obj->value));
112112
if (rv) return FAILURE;
113113
SSTR_LEN(obj->value) = 0;
114-
smart_str_nullify(obj->value);
114+
smart_string_nullify(obj->value);
115115
return SUCCESS;
116116
}
117117

@@ -211,7 +211,7 @@ static void tarantool_free(tarantool_object *obj TSRMLS_DC) {
211211
if (obj->host) pefree(obj->host, 1);
212212
if (obj->login) pefree(obj->login, 1);
213213
if (obj->passwd) efree(obj->passwd);
214-
if (obj->value) smart_str_free_ex(obj->value, 1);
214+
if (obj->value) smart_string_free_ex(obj->value, 1);
215215
if (obj->tps) tarantool_tp_free(obj->tps);
216216
if (obj->value) pefree(obj->value, 1);
217217
pefree(obj, 1);
@@ -260,7 +260,7 @@ static int64_t tarantool_step_recv(
260260
goto error;
261261
}
262262
size_t body_size = php_mp_unpack_package_size(pack_len);
263-
smart_str_ensure(obj->value, body_size);
263+
smart_string_ensure(obj->value, body_size);
264264
if (tarantool_stream_read(obj, SSTR_POS(obj->value),
265265
body_size) != body_size) {
266266
THROW_EXC("Can't read query from server");
@@ -302,7 +302,7 @@ static int64_t tarantool_step_recv(
302302
if (zend_hash_index_find(hash, TNT_CODE, (void **)&val) == SUCCESS) {
303303
if (Z_LVAL_PP(val) == TNT_OK) {
304304
SSTR_LEN(obj->value) = 0;
305-
smart_str_nullify(obj->value);
305+
smart_string_nullify(obj->value);
306306
return SUCCESS;
307307
}
308308
HashTable *hash = HASH_OF(*body);
@@ -322,7 +322,7 @@ static int64_t tarantool_step_recv(
322322
if (*header) zval_ptr_dtor(header);
323323
if (*body) zval_ptr_dtor(body);
324324
SSTR_LEN(obj->value) = 0;
325-
smart_str_nullify(obj->value);
325+
smart_string_nullify(obj->value);
326326
return FAILURE;
327327
}
328328

@@ -530,7 +530,7 @@ int get_spaceno_by_name(tarantool_object *obj, zval *id, zval *name TSRMLS_DC) {
530530
return FAILURE;
531531
}
532532
size_t body_size = php_mp_unpack_package_size(pack_len);
533-
smart_str_ensure(obj->value, body_size);
533+
smart_string_ensure(obj->value, body_size);
534534
if (tarantool_stream_read(obj, obj->value->c,
535535
body_size) != body_size) {
536536
THROW_EXC("Can't read query from server");
@@ -590,7 +590,7 @@ int get_indexno_by_name(tarantool_object *obj, zval *id,
590590
return FAILURE;
591591
}
592592
size_t body_size = php_mp_unpack_package_size(pack_len);
593-
smart_str_ensure(obj->value, body_size);
593+
smart_string_ensure(obj->value, body_size);
594594
if (tarantool_stream_read(obj, obj->value->c,
595595
body_size) != body_size) {
596596
THROW_EXC("Can't read query from server");
@@ -704,7 +704,7 @@ PHP_METHOD(tarantool_class, __construct) {
704704
/* initialzie object structure */
705705
obj->host = pestrdup(host, 1);
706706
obj->port = port;
707-
obj->value = (smart_str *)pemalloc(sizeof(smart_str), 1);
707+
obj->value = (smart_string *)pemalloc(sizeof(smart_string), 1);
708708
obj->auth = 0;
709709
obj->greeting = (char *)pecalloc(sizeof(char), GREETING_SIZE, 1);
710710
obj->salt = NULL;
@@ -715,7 +715,7 @@ PHP_METHOD(tarantool_class, __construct) {
715715
obj->value->len = 0;
716716
obj->value->a = 0;
717717
obj->value->c = NULL;
718-
smart_str_ensure(obj->value, GREETING_SIZE);
718+
smart_string_ensure(obj->value, GREETING_SIZE);
719719
obj->tps = tarantool_tp_new(obj->value);
720720
return;
721721
}
@@ -763,7 +763,7 @@ int __tarantool_authenticate(tarantool_object *obj) {
763763
return FAILURE;
764764
}
765765
size_t body_size = php_mp_unpack_package_size(pack_len);
766-
smart_str_ensure(obj->value, body_size);
766+
smart_string_ensure(obj->value, body_size);
767767
if (tarantool_stream_read(obj, obj->value->c,
768768
body_size) != body_size) {
769769
THROW_EXC("Can't read query from server");

src/tarantool_manager.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
#ifndef PHP_MANAGER_H
22
#define PHP_MANAGER_H
33

4-
#include <php.h>
5-
#include <php_network.h>
6-
#include <zend_API.h>
7-
#include <ext/standard/php_smart_str.h>
8-
9-
#include <sys/queue.h>
4+
#include <php_tarantool.h>
105

116
#include "third_party/PMurHash.h"
127
#define MUR_SEED 13

src/tarantool_msgpack.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,82 +12,82 @@
1212

1313
/* UTILITES */
1414

15-
int smart_str_ensure(smart_str *str, size_t len) {
15+
int smart_string_ensure(smart_string *str, size_t len) {
1616
if (SSTR_AWA(str) > SSTR_LEN(str) + len)
1717
return 0;
1818
size_t needed = str->a * 2;
1919
if (SSTR_LEN(str) + len > needed)
2020
needed = SSTR_LEN(str) + len;
2121
register size_t __n1;
22-
smart_str_alloc4(str, needed, 1, __n1);
22+
smart_string_alloc4(str, needed, 1, __n1);
2323
return 0;
2424
}
2525

26-
void smart_str_nullify(smart_str *str) {
26+
void smart_string_nullify(smart_string *str) {
2727
memset(SSTR_BEG(str), 0, SSTR_AWA(str));
2828
}
2929

3030
/* PACKING ROUTINES */
3131

32-
void php_mp_pack_nil(smart_str *str) {
32+
void php_mp_pack_nil(smart_string *str) {
3333
size_t needed = mp_sizeof_nil();
34-
smart_str_ensure(str, needed);
34+
smart_string_ensure(str, needed);
3535
mp_encode_nil(SSTR_POS(str));
3636
SSTR_LEN(str) += needed;
3737
}
3838

39-
void php_mp_pack_long_pos(smart_str *str, long val) {
39+
void php_mp_pack_long_pos(smart_string *str, long val) {
4040
size_t needed = mp_sizeof_uint(val);
41-
smart_str_ensure(str, needed);
41+
smart_string_ensure(str, needed);
4242
mp_encode_uint(SSTR_POS(str), val);
4343
SSTR_LEN(str) += needed;
4444
}
4545

46-
void php_mp_pack_long_neg(smart_str *str, long val) {
46+
void php_mp_pack_long_neg(smart_string *str, long val) {
4747
size_t needed = mp_sizeof_int(val);
48-
smart_str_ensure(str, needed);
48+
smart_string_ensure(str, needed);
4949
mp_encode_int(SSTR_POS(str), val);
5050
SSTR_LEN(str) += needed;
5151
}
5252

53-
void php_mp_pack_long(smart_str *str, long val) {
53+
void php_mp_pack_long(smart_string *str, long val) {
5454
if (val >= 0)
5555
php_mp_pack_long_pos(str, val);
5656
else
5757
php_mp_pack_long_neg(str, val);
5858
}
5959

60-
void php_mp_pack_double(smart_str *str, double val) {
60+
void php_mp_pack_double(smart_string *str, double val) {
6161
size_t needed = mp_sizeof_double(val);
62-
smart_str_ensure(str, needed);
62+
smart_string_ensure(str, needed);
6363
mp_encode_double(SSTR_POS(str), val);
6464
SSTR_LEN(str) += needed;
6565
}
6666

67-
void php_mp_pack_bool(smart_str *str, unsigned char val) {
67+
void php_mp_pack_bool(smart_string *str, unsigned char val) {
6868
size_t needed = mp_sizeof_bool(val);
69-
smart_str_ensure(str, needed);
69+
smart_string_ensure(str, needed);
7070
mp_encode_bool(SSTR_POS(str), val);
7171
SSTR_LEN(str) += needed;
7272
}
7373

74-
void php_mp_pack_string(smart_str *str, char *c, size_t len) {
74+
void php_mp_pack_string(smart_string *str, char *c, size_t len) {
7575
size_t needed = mp_sizeof_str(len);
76-
smart_str_ensure(str, needed);
76+
smart_string_ensure(str, needed);
7777
mp_encode_str(SSTR_POS(str), c, len);
7878
SSTR_LEN(str) += needed;
7979
}
8080

81-
void php_mp_pack_hash(smart_str *str, size_t len) {
81+
void php_mp_pack_hash(smart_string *str, size_t len) {
8282
size_t needed = mp_sizeof_map(len);
83-
smart_str_ensure(str, needed);
83+
smart_string_ensure(str, needed);
8484
mp_encode_map(SSTR_POS(str), len);
8585
SSTR_LEN(str) += needed;
8686
}
8787

88-
void php_mp_pack_array(smart_str *str, size_t len) {
88+
void php_mp_pack_array(smart_string *str, size_t len) {
8989
size_t needed = mp_sizeof_array(len);
90-
smart_str_ensure(str, needed);
90+
smart_string_ensure(str, needed);
9191
mp_encode_array(SSTR_POS(str), len);
9292
SSTR_LEN(str) += needed;
9393
}
@@ -111,7 +111,7 @@ int php_mp_is_hash(zval *val) {
111111
return 0;
112112
}
113113

114-
void php_mp_pack_array_recursively(smart_str *str, zval *val) {
114+
void php_mp_pack_array_recursively(smart_string *str, zval *val) {
115115
HashTable *ht = Z_ARRVAL_P(val);
116116
size_t n = zend_hash_num_elements(ht);
117117

@@ -136,7 +136,7 @@ void php_mp_pack_array_recursively(smart_str *str, zval *val) {
136136
}
137137
}
138138

139-
void php_mp_pack_hash_recursively(smart_str *str, zval *val) {
139+
void php_mp_pack_hash_recursively(smart_string *str, zval *val) {
140140
HashTable *ht = Z_ARRVAL_P(val);
141141
size_t n = zend_hash_num_elements(ht);
142142

@@ -182,7 +182,7 @@ void php_mp_pack_hash_recursively(smart_str *str, zval *val) {
182182
}
183183
}
184184

185-
void php_mp_pack(smart_str *str, zval *val) {
185+
void php_mp_pack(smart_string *str, zval *val) {
186186
switch(Z_TYPE_P(val)) {
187187
case IS_NULL:
188188
php_mp_pack_nil(str);
@@ -558,9 +558,9 @@ size_t php_mp_check(const char *str, size_t str_size) {
558558
return mp_check(&str, str + str_size);
559559
}
560560

561-
void php_mp_pack_package_size(smart_str *str, size_t val) {
561+
void php_mp_pack_package_size(smart_string *str, size_t val) {
562562
size_t needed = 5;
563-
smart_str_ensure(str, needed);
563+
smart_string_ensure(str, needed);
564564
*(SSTR_POS(str)) = 0xce;
565565
*(uint32_t *)(SSTR_POS(str) + 1) = mp_bswap_u32(val);
566566
SSTR_LEN(str) += needed;

src/tarantool_msgpack.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define PHP_TARANTOOL_DEBUG
55

6-
#include <ext/standard/php_smart_str.h>
6+
#include <php_tarantool.h>
77

88
#define PHP_MP_SERIALIZABLE_PP(v) (Z_TYPE_PP(v) == IS_NULL || \
99
Z_TYPE_PP(v) == IS_LONG || \
@@ -12,27 +12,27 @@
1212
Z_TYPE_PP(v) == IS_ARRAY || \
1313
Z_TYPE_PP(v) == IS_STRING)
1414

15-
size_t php_mp_check (const char *str, size_t str_size);
16-
void php_mp_pack (smart_str *buf, zval *val );
17-
ssize_t php_mp_unpack (zval **oval, char **str );
15+
size_t php_mp_check (const char *str, size_t str_size);
16+
void php_mp_pack (smart_string *buf, zval *val );
17+
ssize_t php_mp_unpack (zval **oval, char **str );
1818
size_t php_mp_sizeof (zval *val);
1919

20-
void php_mp_pack_package_size (smart_str *str, size_t val);
20+
void php_mp_pack_package_size (smart_string *str, size_t val);
2121
size_t php_mp_unpack_package_size (char *buf);
2222

2323
int php_mp_is_hash(zval *val);
2424

25-
void php_mp_pack_nil(smart_str *str);
26-
void php_mp_pack_long_pos(smart_str *str, long val);
27-
void php_mp_pack_long_neg(smart_str *str, long val);
28-
void php_mp_pack_long(smart_str *str, long val);
29-
void php_mp_pack_double(smart_str *str, double val);
30-
void php_mp_pack_bool(smart_str *str, unsigned char val);
31-
void php_mp_pack_string(smart_str *str, char *c, size_t len);
32-
void php_mp_pack_hash(smart_str *str, size_t len);
33-
void php_mp_pack_array(smart_str *str, size_t len);
34-
void php_mp_pack_array_recursively(smart_str *str, zval *val);
35-
void php_mp_pack_hash_recursively(smart_str *str, zval *val);
25+
void php_mp_pack_nil(smart_string *str);
26+
void php_mp_pack_long_pos(smart_string *str, long val);
27+
void php_mp_pack_long_neg(smart_string *str, long val);
28+
void php_mp_pack_long(smart_string *str, long val);
29+
void php_mp_pack_double(smart_string *str, double val);
30+
void php_mp_pack_bool(smart_string *str, unsigned char val);
31+
void php_mp_pack_string(smart_string *str, char *c, size_t len);
32+
void php_mp_pack_hash(smart_string *str, size_t len);
33+
void php_mp_pack_array(smart_string *str, size_t len);
34+
void php_mp_pack_array_recursively(smart_string *str, zval *val);
35+
void php_mp_pack_hash_recursively(smart_string *str, zval *val);
3636

3737
size_t php_mp_sizeof_nil();
3838
size_t php_mp_sizeof_long_pos(long val);
@@ -46,6 +46,6 @@ size_t php_mp_sizeof_array(size_t len);
4646
size_t php_mp_sizeof_array_recursively(zval *val);
4747
size_t php_mp_sizeof_hash_recursively(zval *val);
4848

49-
int smart_str_ensure(smart_str *str, size_t len);
49+
int smart_string_ensure(smart_string *str, size_t len);
5050

5151
#endif /* PHP_MSGPACK_H */

0 commit comments

Comments
 (0)