summaryrefslogtreecommitdiff
path: root/ext/sysvmsg/sysvmsg.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/sysvmsg/sysvmsg.c')
-rw-r--r--ext/sysvmsg/sysvmsg.c65
1 files changed, 34 insertions, 31 deletions
diff --git a/ext/sysvmsg/sysvmsg.c b/ext/sysvmsg/sysvmsg.c
index adf1d2d6be..83875ac9ee 100644
--- a/ext/sysvmsg/sysvmsg.c
+++ b/ext/sysvmsg/sysvmsg.c
@@ -119,9 +119,9 @@ zend_module_entry sysvmsg_module_entry = {
ZEND_GET_MODULE(sysvmsg)
#endif
-static void sysvmsg_release(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+static void sysvmsg_release(zend_resource *rsrc TSRMLS_DC)
{
- sysvmsg_queue_t * mq = (sysvmsg_queue_t *) rsrc->ptr;
+ sysvmsg_queue_t *mq = (sysvmsg_queue_t *) rsrc->ptr;
efree(mq);
}
@@ -164,27 +164,27 @@ PHP_FUNCTION(msg_set_queue)
return;
}
- ZEND_FETCH_RESOURCE(mq, sysvmsg_queue_t *, &queue, -1, "sysvmsg queue", le_sysvmsg);
+ ZEND_FETCH_RESOURCE(mq, sysvmsg_queue_t *, queue, -1, "sysvmsg queue", le_sysvmsg);
if (msgctl(mq->id, IPC_STAT, &stat) == 0) {
- zval **item;
+ zval *item;
/* now pull out members of data and set them in the stat buffer */
- if (zend_hash_find(Z_ARRVAL_P(data), "msg_perm.uid", sizeof("msg_perm.uid"), (void **) &item) == SUCCESS) {
+ if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_perm.uid", sizeof("msg_perm.uid") - 1)) != NULL) {
convert_to_long_ex(item);
- stat.msg_perm.uid = Z_LVAL_PP(item);
+ stat.msg_perm.uid = Z_LVAL_P(item);
}
- if (zend_hash_find(Z_ARRVAL_P(data), "msg_perm.gid", sizeof("msg_perm.gid"), (void **) &item) == SUCCESS) {
+ if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_perm.gid", sizeof("msg_perm.gid") - 1)) != NULL) {
convert_to_long_ex(item);
- stat.msg_perm.gid = Z_LVAL_PP(item);
+ stat.msg_perm.gid = Z_LVAL_P(item);
}
- if (zend_hash_find(Z_ARRVAL_P(data), "msg_perm.mode", sizeof("msg_perm.mode"), (void **) &item) == SUCCESS) {
+ if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_perm.mode", sizeof("msg_perm.mode") - 1)) != NULL) {
convert_to_long_ex(item);
- stat.msg_perm.mode = Z_LVAL_PP(item);
+ stat.msg_perm.mode = Z_LVAL_P(item);
}
- if (zend_hash_find(Z_ARRVAL_P(data), "msg_qbytes", sizeof("msg_qbytes"), (void **) &item) == SUCCESS) {
+ if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_qbytes", sizeof("msg_qbytes") - 1)) != NULL) {
convert_to_long_ex(item);
- stat.msg_qbytes = Z_LVAL_PP(item);
+ stat.msg_qbytes = Z_LVAL_P(item);
}
if (msgctl(mq->id, IPC_SET, &stat) == 0) {
RETVAL_TRUE;
@@ -207,7 +207,7 @@ PHP_FUNCTION(msg_stat_queue)
return;
}
- ZEND_FETCH_RESOURCE(mq, sysvmsg_queue_t *, &queue, -1, "sysvmsg queue", le_sysvmsg);
+ ZEND_FETCH_RESOURCE(mq, sysvmsg_queue_t *, queue, -1, "sysvmsg queue", le_sysvmsg);
if (msgctl(mq->id, IPC_STAT, &stat) == 0) {
array_init(return_value);
@@ -226,7 +226,6 @@ PHP_FUNCTION(msg_stat_queue)
}
/* }}} */
-
/* {{{ proto bool msg_queue_exists(int key)
Check whether a message queue exists */
PHP_FUNCTION(msg_queue_exists)
@@ -245,7 +244,6 @@ PHP_FUNCTION(msg_queue_exists)
}
/* }}} */
-
/* {{{ proto resource msg_get_queue(int key [, int perms])
Attach to a message queue */
PHP_FUNCTION(msg_get_queue)
@@ -271,7 +269,7 @@ PHP_FUNCTION(msg_get_queue)
RETURN_FALSE;
}
}
- RETVAL_RESOURCE(zend_list_insert(mq, le_sysvmsg TSRMLS_CC));
+ RETVAL_ZVAL(zend_list_insert(mq, le_sysvmsg TSRMLS_CC), 0, 0);
}
/* }}} */
@@ -286,7 +284,7 @@ PHP_FUNCTION(msg_remove_queue)
return;
}
- ZEND_FETCH_RESOURCE(mq, sysvmsg_queue_t *, &queue, -1, "sysvmsg queue", le_sysvmsg);
+ ZEND_FETCH_RESOURCE(mq, sysvmsg_queue_t *, queue, -1, "sysvmsg queue", le_sysvmsg);
if (msgctl(mq->id, IPC_RMID, NULL) == 0) {
RETVAL_TRUE;
@@ -338,18 +336,21 @@ PHP_FUNCTION(msg_receive)
}
}
- ZEND_FETCH_RESOURCE(mq, sysvmsg_queue_t *, &queue, -1, "sysvmsg queue", le_sysvmsg);
+ ZEND_FETCH_RESOURCE(mq, sysvmsg_queue_t *, queue, -1, "sysvmsg queue", le_sysvmsg);
messagebuffer = (struct php_msgbuf *) safe_emalloc(maxsize, 1, sizeof(struct php_msgbuf));
result = msgrcv(mq->id, messagebuffer, maxsize, desiredmsgtype, realflags);
+ ZVAL_DEREF(out_msgtype);
+ ZVAL_DEREF(out_message);
zval_dtor(out_msgtype);
zval_dtor(out_message);
ZVAL_LONG(out_msgtype, 0);
ZVAL_FALSE(out_message);
if (zerrcode) {
+ ZVAL_DEREF(zerrcode);
zval_dtor(zerrcode);
ZVAL_LONG(zerrcode, 0);
}
@@ -361,21 +362,19 @@ PHP_FUNCTION(msg_receive)
RETVAL_TRUE;
if (do_unserialize) {
php_unserialize_data_t var_hash;
- zval *tmp = NULL;
+ zval tmp;
const unsigned char *p = (const unsigned char *) messagebuffer->mtext;
- MAKE_STD_ZVAL(tmp);
PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (!php_var_unserialize(&tmp, &p, p + result, &var_hash TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "message corrupted");
RETVAL_FALSE;
} else {
- REPLACE_ZVAL_VALUE(&out_message, tmp, 0);
+ ZVAL_COPY_VALUE(out_message, &tmp);
}
- FREE_ZVAL(tmp);
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
} else {
- ZVAL_STRINGL(out_message, messagebuffer->mtext, result, 1);
+ ZVAL_STRINGL(out_message, messagebuffer->mtext, result);
}
} else if (zerrcode) {
ZVAL_LONG(zerrcode, errno);
@@ -403,21 +402,21 @@ PHP_FUNCTION(msg_send)
return;
}
- ZEND_FETCH_RESOURCE(mq, sysvmsg_queue_t*, &queue, -1, "sysvmsg queue", le_sysvmsg);
+ ZEND_FETCH_RESOURCE(mq, sysvmsg_queue_t*, queue, -1, "sysvmsg queue", le_sysvmsg);
if (do_serialize) {
smart_str msg_var = {0};
php_serialize_data_t var_hash;
PHP_VAR_SERIALIZE_INIT(var_hash);
- php_var_serialize(&msg_var, &message, &var_hash TSRMLS_CC);
+ php_var_serialize(&msg_var, message, &var_hash TSRMLS_CC);
PHP_VAR_SERIALIZE_DESTROY(var_hash);
/* NB: php_msgbuf is 1 char bigger than a long, so there is no need to
* allocate the extra byte. */
- messagebuffer = safe_emalloc(msg_var.len, 1, sizeof(struct php_msgbuf));
- memcpy(messagebuffer->mtext, msg_var.c, msg_var.len + 1);
- message_len = msg_var.len;
+ messagebuffer = safe_emalloc(msg_var.s->len, 1, sizeof(struct php_msgbuf));
+ memcpy(messagebuffer->mtext, msg_var.s->val, msg_var.s->len + 1);
+ message_len = msg_var.s->len;
smart_str_free(&msg_var);
} else {
char *p;
@@ -428,14 +427,17 @@ PHP_FUNCTION(msg_send)
break;
case IS_LONG:
- case IS_BOOL:
message_len = spprintf(&p, 0, "%ld", Z_LVAL_P(message));
break;
-
+ case IS_FALSE:
+ message_len = spprintf(&p, 0, "0");
+ break;
+ case IS_TRUE:
+ message_len = spprintf(&p, 0, "1");
+ break;
case IS_DOUBLE:
message_len = spprintf(&p, 0, "%F", Z_DVAL_P(message));
break;
-
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Message parameter must be either a string or a number.");
RETURN_FALSE;
@@ -459,6 +461,7 @@ PHP_FUNCTION(msg_send)
if (result == -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "msgsnd failed: %s", strerror(errno));
if (zerror) {
+ ZVAL_DEREF(zerror);
ZVAL_LONG(zerror, errno);
}
} else {