Skip to content

Commit 4a5699a

Browse files
committed
Session: use more appropriate types
1 parent d08451b commit 4a5699a

File tree

6 files changed

+81
-89
lines changed

6 files changed

+81
-89
lines changed

ext/session/mod_files.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static void ps_files_open(ps_files *data, const char *key)
155155
{
156156
char buf[MAXPATHLEN];
157157
#if !defined(O_NOFOLLOW) || !defined(PHP_WIN32)
158-
struct stat sbuf;
158+
struct stat sbuf = {0};
159159
#endif
160160
int ret;
161161

@@ -226,7 +226,7 @@ static void ps_files_open(ps_files *data, const char *key)
226226
}
227227
}
228228

229-
static int ps_files_write(ps_files *data, zend_string *key, zend_string *val)
229+
static zend_result ps_files_write(ps_files *data, zend_string *key, zend_string *val)
230230
{
231231
size_t n = 0;
232232

@@ -337,7 +337,7 @@ static int ps_files_cleanup_dir(const char *dirname, zend_long maxlifetime)
337337
return (nrdels);
338338
}
339339

340-
static int ps_files_key_exists(ps_files *data, const char *key)
340+
static zend_result ps_files_key_exists(ps_files *data, const char *key)
341341
{
342342
char buf[MAXPATHLEN];
343343
zend_stat_t sbuf = {0};

ext/session/mod_mm.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static ps_mm *ps_mm_instance = NULL;
6464
# define ps_mm_debug(a)
6565
#endif
6666

67-
static inline uint32_t ps_sd_hash(const char *data, int len)
67+
static inline uint32_t ps_sd_hash(const char *data, size_t len)
6868
{
6969
uint32_t h;
7070
const char *e = data + len;
@@ -110,7 +110,7 @@ static ps_sd *ps_sd_new(ps_mm *data, const char *key)
110110
{
111111
uint32_t hv, slot;
112112
ps_sd *sd;
113-
int keylen;
113+
size_t keylen;
114114

115115
keylen = strlen(key);
116116

@@ -172,7 +172,7 @@ static void ps_sd_destroy(ps_mm *data, ps_sd *sd)
172172
mm_free(data->mm, sd);
173173
}
174174

175-
static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw)
175+
static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, bool rw)
176176
{
177177
uint32_t hv, slot;
178178
ps_sd *ret, *prev;
@@ -201,7 +201,7 @@ static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw)
201201
return ret;
202202
}
203203

204-
static int ps_mm_key_exists(ps_mm *data, const char *key)
204+
static zend_result ps_mm_key_exists(ps_mm *data, const char *key)
205205
{
206206
ps_sd *sd;
207207

@@ -221,7 +221,7 @@ const ps_module ps_mod_mm = {
221221

222222
#define PS_MM_DATA ps_mm *data = PS_GET_MOD_DATA()
223223

224-
static int ps_mm_initialize(ps_mm *data, const char *path)
224+
static zend_result ps_mm_initialize(ps_mm *data, const char *path)
225225
{
226226
data->owner = getpid();
227227
data->mm = mm_create(0, path);
@@ -242,7 +242,6 @@ static int ps_mm_initialize(ps_mm *data, const char *path)
242242

243243
static void ps_mm_destroy(ps_mm *data)
244244
{
245-
int h;
246245
ps_sd *sd, *next;
247246

248247
/* This function is called during each module shutdown,
@@ -252,7 +251,7 @@ static void ps_mm_destroy(ps_mm *data)
252251
return;
253252
}
254253

255-
for (h = 0; h < data->hash_max + 1; h++) {
254+
for (int h = 0; h < data->hash_max + 1; h++) {
256255
for (sd = data->hash[h]; sd; sd = next) {
257256
next = sd->next;
258257
ps_sd_destroy(data, sd);
@@ -266,11 +265,11 @@ static void ps_mm_destroy(ps_mm *data)
266265

267266
PHP_MINIT_FUNCTION(ps_mm)
268267
{
269-
int save_path_len = strlen(PS(save_path));
270-
int mod_name_len = strlen(sapi_module.name);
271-
int euid_len;
268+
size_t save_path_len = strlen(PS(save_path));
269+
size_t mod_name_len = strlen(sapi_module.name);
270+
size_t euid_len;
272271
char *ps_mm_path, euid[30];
273-
int ret;
272+
zend_result ret;
274273

275274
ps_mm_instance = calloc(sizeof(*ps_mm_instance), 1);
276275
if (!ps_mm_instance) {
@@ -302,7 +301,7 @@ PHP_MINIT_FUNCTION(ps_mm)
302301

303302
efree(ps_mm_path);
304303

305-
if (ret != SUCCESS) {
304+
if (ret == FAILURE) {
306305
free(ps_mm_instance);
307306
ps_mm_instance = NULL;
308307
return FAILURE;
@@ -344,7 +343,7 @@ PS_READ_FUNC(mm)
344343
{
345344
PS_MM_DATA;
346345
ps_sd *sd;
347-
int ret = FAILURE;
346+
zend_result ret = FAILURE;
348347

349348
mm_lock(data->mm, MM_LOCK_RD);
350349

ext/session/mod_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void ps_call_handler(zval *func, int argc, zval *argv, zval *retval)
4747

4848
#define STDVARS \
4949
zval retval; \
50-
int ret = FAILURE
50+
zend_result ret = FAILURE
5151

5252
#define PSF(a) PS(mod_user_names).name.ps_##a
5353

ext/session/mod_user_class.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ PHP_METHOD(SessionHandler, open)
3939
{
4040
char *save_path = NULL, *session_name = NULL;
4141
size_t save_path_len, session_name_len;
42-
int ret;
42+
zend_result ret;
4343

4444
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &save_path, &save_path_len, &session_name, &session_name_len) == FAILURE) {
4545
RETURN_THROWS();
@@ -56,14 +56,14 @@ PHP_METHOD(SessionHandler, open)
5656
zend_bailout();
5757
} zend_end_try();
5858

59-
RETVAL_BOOL(SUCCESS == ret);
59+
RETURN_BOOL(SUCCESS == ret);
6060
}
6161
/* }}} */
6262

6363
/* {{{ Wraps the old close handler */
6464
PHP_METHOD(SessionHandler, close)
6565
{
66-
int ret;
66+
zend_result ret;
6767

6868
// don't return on failure, since not closing the default handler
6969
// could result in memory leaks or other nasties
@@ -80,7 +80,7 @@ PHP_METHOD(SessionHandler, close)
8080
zend_bailout();
8181
} zend_end_try();
8282

83-
RETVAL_BOOL(SUCCESS == ret);
83+
RETURN_BOOL(SUCCESS == ret);
8484
}
8585
/* }}} */
8686

ext/session/php_session.h

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,29 @@
3939

4040
typedef struct ps_module_struct {
4141
const char *s_name;
42-
int (*s_open)(PS_OPEN_ARGS);
43-
int (*s_close)(PS_CLOSE_ARGS);
44-
int (*s_read)(PS_READ_ARGS);
45-
int (*s_write)(PS_WRITE_ARGS);
46-
int (*s_destroy)(PS_DESTROY_ARGS);
42+
zend_result (*s_open)(PS_OPEN_ARGS);
43+
zend_result (*s_close)(PS_CLOSE_ARGS);
44+
zend_result (*s_read)(PS_READ_ARGS);
45+
zend_result (*s_write)(PS_WRITE_ARGS);
46+
zend_result (*s_destroy)(PS_DESTROY_ARGS);
4747
zend_long (*s_gc)(PS_GC_ARGS);
4848
zend_string *(*s_create_sid)(PS_CREATE_SID_ARGS);
49-
int (*s_validate_sid)(PS_VALIDATE_SID_ARGS);
50-
int (*s_update_timestamp)(PS_UPDATE_TIMESTAMP_ARGS);
49+
zend_result (*s_validate_sid)(PS_VALIDATE_SID_ARGS);
50+
zend_result (*s_update_timestamp)(PS_UPDATE_TIMESTAMP_ARGS);
5151
} ps_module;
5252

5353
#define PS_GET_MOD_DATA() *mod_data
5454
#define PS_SET_MOD_DATA(a) *mod_data = (a)
5555

56-
#define PS_OPEN_FUNC(x) int ps_open_##x(PS_OPEN_ARGS)
57-
#define PS_CLOSE_FUNC(x) int ps_close_##x(PS_CLOSE_ARGS)
58-
#define PS_READ_FUNC(x) int ps_read_##x(PS_READ_ARGS)
59-
#define PS_WRITE_FUNC(x) int ps_write_##x(PS_WRITE_ARGS)
60-
#define PS_DESTROY_FUNC(x) int ps_delete_##x(PS_DESTROY_ARGS)
56+
#define PS_OPEN_FUNC(x) zend_result ps_open_##x(PS_OPEN_ARGS)
57+
#define PS_CLOSE_FUNC(x) zend_result ps_close_##x(PS_CLOSE_ARGS)
58+
#define PS_READ_FUNC(x) zend_result ps_read_##x(PS_READ_ARGS)
59+
#define PS_WRITE_FUNC(x) zend_result ps_write_##x(PS_WRITE_ARGS)
60+
#define PS_DESTROY_FUNC(x) zend_result ps_delete_##x(PS_DESTROY_ARGS)
6161
#define PS_GC_FUNC(x) zend_long ps_gc_##x(PS_GC_ARGS)
6262
#define PS_CREATE_SID_FUNC(x) zend_string *ps_create_sid_##x(PS_CREATE_SID_ARGS)
63-
#define PS_VALIDATE_SID_FUNC(x) int ps_validate_sid_##x(PS_VALIDATE_SID_ARGS)
64-
#define PS_UPDATE_TIMESTAMP_FUNC(x) int ps_update_timestamp_##x(PS_UPDATE_TIMESTAMP_ARGS)
63+
#define PS_VALIDATE_SID_FUNC(x) zend_result ps_validate_sid_##x(PS_VALIDATE_SID_ARGS)
64+
#define PS_UPDATE_TIMESTAMP_FUNC(x) zend_result ps_update_timestamp_##x(PS_UPDATE_TIMESTAMP_ARGS)
6565

6666
/* Legacy save handler module definitions */
6767
#define PS_FUNCS(x) \
@@ -224,7 +224,7 @@ ZEND_TSRMLS_CACHE_EXTERN()
224224
typedef struct ps_serializer_struct {
225225
const char *name;
226226
zend_string *(*encode)(PS_SERIALIZER_ENCODE_ARGS);
227-
int (*decode)(PS_SERIALIZER_DECODE_ARGS);
227+
zend_result (*decode)(PS_SERIALIZER_DECODE_ARGS);
228228
} ps_serializer;
229229

230230
#define PS_SERIALIZER_ENCODE_NAME(x) ps_srlzr_encode_##x
@@ -233,7 +233,7 @@ typedef struct ps_serializer_struct {
233233
#define PS_SERIALIZER_ENCODE_FUNC(x) \
234234
zend_string *PS_SERIALIZER_ENCODE_NAME(x)(PS_SERIALIZER_ENCODE_ARGS)
235235
#define PS_SERIALIZER_DECODE_FUNC(x) \
236-
int PS_SERIALIZER_DECODE_NAME(x)(PS_SERIALIZER_DECODE_ARGS)
236+
zend_result PS_SERIALIZER_DECODE_NAME(x)(PS_SERIALIZER_DECODE_ARGS)
237237

238238
#define PS_SERIALIZER_FUNCS(x) \
239239
PS_SERIALIZER_ENCODE_FUNC(x); \
@@ -245,30 +245,30 @@ typedef struct ps_serializer_struct {
245245
/* default create id function */
246246
PHPAPI zend_string *php_session_create_id(PS_CREATE_SID_ARGS);
247247
/* Dummy PS module functions */
248-
PHPAPI int php_session_validate_sid(PS_VALIDATE_SID_ARGS);
249-
PHPAPI int php_session_update_timestamp(PS_UPDATE_TIMESTAMP_ARGS);
248+
PHPAPI zend_result php_session_validate_sid(PS_VALIDATE_SID_ARGS);
249+
PHPAPI zend_result php_session_update_timestamp(PS_UPDATE_TIMESTAMP_ARGS);
250250

251251
PHPAPI void session_adapt_url(const char *url, size_t url_len, char **new_url, size_t *new_len);
252252

253-
PHPAPI int php_session_destroy(void);
253+
PHPAPI zend_result php_session_destroy(void);
254254
PHPAPI void php_add_session_var(zend_string *name);
255255
PHPAPI zval *php_set_session_var(zend_string *name, zval *state_val, php_unserialize_data_t *var_hash);
256256
PHPAPI zval *php_get_session_var(zend_string *name);
257257

258-
PHPAPI int php_session_register_module(const ps_module *);
258+
PHPAPI zend_result php_session_register_module(const ps_module *);
259259

260-
PHPAPI int php_session_register_serializer(const char *name,
260+
PHPAPI zend_result php_session_register_serializer(const char *name,
261261
zend_string *(*encode)(PS_SERIALIZER_ENCODE_ARGS),
262-
int (*decode)(PS_SERIALIZER_DECODE_ARGS));
262+
zend_result (*decode)(PS_SERIALIZER_DECODE_ARGS));
263263

264-
PHPAPI int php_session_start(void);
265-
PHPAPI int php_session_flush(int write);
264+
PHPAPI zend_result php_session_start(void);
265+
PHPAPI zend_result php_session_flush(int write);
266266

267267
PHPAPI const ps_module *_php_find_ps_module(const char *name);
268268
PHPAPI const ps_serializer *_php_find_ps_serializer(const char *name);
269269

270-
PHPAPI int php_session_valid_key(const char *key);
271-
PHPAPI int php_session_reset_id(void);
270+
PHPAPI zend_result php_session_valid_key(const char *key);
271+
PHPAPI zend_result php_session_reset_id(void);
272272

273273
#define PS_ADD_VARL(name) do { \
274274
php_add_session_var(name); \

0 commit comments

Comments
 (0)