Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f63a35d

Browse files
committed
ext/sysvmsg: various minor refactorings
1 parent 87d83d1 commit f63a35d

File tree

1 file changed

+27
-38
lines changed

1 file changed

+27
-38
lines changed

‎ext/sysvmsg/sysvmsg.c

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -127,32 +127,32 @@ PHP_MINFO_FUNCTION(sysvmsg)
127127
/* {{{ Set information for a message queue */
128128
PHP_FUNCTION(msg_set_queue)
129129
{
130-
zval *queue, *data;
130+
zval *queue;
131+
HashTable *data;
131132
sysvmsg_queue_t *mq = NULL;
132133
struct msqid_ds stat;
133134

134-
RETVAL_FALSE;
135-
136-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa", &queue, sysvmsg_queue_ce, &data) == FAILURE) {
135+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oh", &queue, sysvmsg_queue_ce, &data) == FAILURE) {
137136
RETURN_THROWS();
138137
}
139138

140139
mq = Z_SYSVMSG_QUEUE_P(queue);
141140

141+
RETVAL_FALSE;
142142
if (msgctl(mq->id, IPC_STAT, &stat) == 0) {
143143
zval *item;
144144

145145
/* now pull out members of data and set them in the stat buffer */
146-
if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_perm.uid", sizeof("msg_perm.uid")-1)) != NULL) {
146+
if ((item = zend_hash_str_find(data, ZEND_STRL("msg_perm.uid"))) != NULL) {
147147
stat.msg_perm.uid = zval_get_long(item);
148148
}
149-
if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_perm.gid", sizeof("msg_perm.gid")-1)) != NULL) {
149+
if ((item = zend_hash_str_find(data, ZEND_STRL("msg_perm.gid"))) != NULL) {
150150
stat.msg_perm.gid = zval_get_long(item);
151151
}
152-
if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_perm.mode", sizeof("msg_perm.mode")-1)) != NULL) {
152+
if ((item = zend_hash_str_find(data, ZEND_STRL("msg_perm.mode"))) != NULL) {
153153
stat.msg_perm.mode = zval_get_long(item);
154154
}
155-
if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_qbytes", sizeof("msg_qbytes")-1)) != NULL) {
155+
if ((item = zend_hash_str_find(data, ZEND_STRL("msg_qbytes"))) != NULL) {
156156
stat.msg_qbytes = zval_get_long(item);
157157
}
158158
if (msgctl(mq->id, IPC_SET, &stat) == 0) {
@@ -169,28 +169,27 @@ PHP_FUNCTION(msg_stat_queue)
169169
sysvmsg_queue_t *mq = NULL;
170170
struct msqid_ds stat;
171171

172-
RETVAL_FALSE;
173-
174172
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &queue, sysvmsg_queue_ce) == FAILURE) {
175173
RETURN_THROWS();
176174
}
177175

178176
mq = Z_SYSVMSG_QUEUE_P(queue);
179177

180-
if (msgctl(mq->id, IPC_STAT, &stat) == 0) {
181-
array_init(return_value);
182-
183-
add_assoc_long(return_value, "msg_perm.uid", stat.msg_perm.uid);
184-
add_assoc_long(return_value, "msg_perm.gid", stat.msg_perm.gid);
185-
add_assoc_long(return_value, "msg_perm.mode", stat.msg_perm.mode);
186-
add_assoc_long(return_value, "msg_stime", stat.msg_stime);
187-
add_assoc_long(return_value, "msg_rtime", stat.msg_rtime);
188-
add_assoc_long(return_value, "msg_ctime", stat.msg_ctime);
189-
add_assoc_long(return_value, "msg_qnum", stat.msg_qnum);
190-
add_assoc_long(return_value, "msg_qbytes", stat.msg_qbytes);
191-
add_assoc_long(return_value, "msg_lspid", stat.msg_lspid);
192-
add_assoc_long(return_value, "msg_lrpid", stat.msg_lrpid);
178+
if (msgctl(mq->id, IPC_STAT, &stat) != 0) {
179+
RETURN_FALSE;
193180
}
181+
182+
array_init_size(return_value, 10);
183+
add_assoc_long(return_value, "msg_perm.uid", stat.msg_perm.uid);
184+
add_assoc_long(return_value, "msg_perm.gid", stat.msg_perm.gid);
185+
add_assoc_long(return_value, "msg_perm.mode", stat.msg_perm.mode);
186+
add_assoc_long(return_value, "msg_stime", stat.msg_stime);
187+
add_assoc_long(return_value, "msg_rtime", stat.msg_rtime);
188+
add_assoc_long(return_value, "msg_ctime", stat.msg_ctime);
189+
add_assoc_long(return_value, "msg_qnum", stat.msg_qnum);
190+
add_assoc_long(return_value, "msg_qbytes", stat.msg_qbytes);
191+
add_assoc_long(return_value, "msg_lspid", stat.msg_lspid);
192+
add_assoc_long(return_value, "msg_lrpid", stat.msg_lrpid);
194193
}
195194
/* }}} */
196195

@@ -203,11 +202,7 @@ PHP_FUNCTION(msg_queue_exists)
203202
RETURN_THROWS();
204203
}
205204

206-
if (msgget(key, 0) < 0) {
207-
RETURN_FALSE;
208-
}
209-
210-
RETURN_TRUE;
205+
RETURN_BOOL(msgget(key, 0) >= 0);
211206
}
212207
/* }}} */
213208

@@ -251,11 +246,7 @@ PHP_FUNCTION(msg_remove_queue)
251246

252247
mq = Z_SYSVMSG_QUEUE_P(queue);
253248

254-
if (msgctl(mq->id, IPC_RMID, NULL) == 0) {
255-
RETVAL_TRUE;
256-
} else {
257-
RETVAL_FALSE;
258-
}
249+
RETURN_BOOL(msgctl(mq->id, IPC_RMID, NULL) == 0);
259250
}
260251
/* }}} */
261252

@@ -270,8 +261,6 @@ PHP_FUNCTION(msg_receive)
270261
struct php_msgbuf *messagebuffer = NULL; /* buffer to transmit */
271262
int result;
272263

273-
RETVAL_FALSE;
274-
275264
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olzlz|blz",
276265
&queue, sysvmsg_queue_ce, &desiredmsgtype, &out_msgtype, &maxsize,
277266
&out_message, &do_unserialize, &flags, &zerrcode) == FAILURE) {
@@ -337,6 +326,7 @@ PHP_FUNCTION(msg_receive)
337326
if (zerrcode) {
338327
ZEND_TRY_ASSIGN_REF_LONG(zerrcode, errno);
339328
}
329+
RETVAL_FALSE;
340330
}
341331
efree(messagebuffer);
342332
}
@@ -353,8 +343,6 @@ PHP_FUNCTION(msg_send)
353343
int result;
354344
size_t message_len = 0;
355345

356-
RETVAL_FALSE;
357-
358346
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olz|bbz",
359347
&queue, sysvmsg_queue_ce, &msgtype, &message, &do_serialize, &blocking, &zerror) == FAILURE) {
360348
RETURN_THROWS();
@@ -429,8 +417,9 @@ PHP_FUNCTION(msg_send)
429417
if (zerror) {
430418
ZEND_TRY_ASSIGN_REF_LONG(zerror, errno);
431419
}
420+
RETURN_FALSE;
432421
} else {
433-
RETVAL_TRUE;
422+
RETURN_TRUE;
434423
}
435424
}
436425
/* }}} */

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /