summaryrefslogtreecommitdiff
path: root/ext/shmop
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2015-02-02 13:23:16 +0800
committerXinchen Hui <laruence@gmail.com>2015-02-02 13:23:16 +0800
commit942809909e1bc125db038796c0a1a0b53eeaca7d (patch)
treebddec8b44878488fc73e8fe2fb9e30b7ee4f9b67 /ext/shmop
parentc9e44dc2dfa7ad91fe9253378a49e9f5b057992e (diff)
downloadphp-git-942809909e1bc125db038796c0a1a0b53eeaca7d.tar.gz
Cleanup resource handling APIs
Diffstat (limited to 'ext/shmop')
-rw-r--r--ext/shmop/shmop.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/ext/shmop/shmop.c b/ext/shmop/shmop.c
index 3377405701..0779d27671 100644
--- a/ext/shmop/shmop.c
+++ b/ext/shmop/shmop.c
@@ -215,8 +215,7 @@ PHP_FUNCTION(shmop_open)
shmop->size = shm.shm_segsz;
- ZEND_REGISTER_RESOURCE(return_value, shmop, shm_type);
- RETURN_LONG(Z_RES_HANDLE_P(return_value));
+ RETURN_RES(zend_register_resource(shmop, shm_type));
err:
efree(shmop);
RETURN_FALSE;
@@ -227,17 +226,20 @@ err:
reads from a shm segment */
PHP_FUNCTION(shmop_read)
{
- zend_long shmid, start, count;
+ zval *shmid;
+ zend_long start, count;
struct php_shmop *shmop;
char *startaddr;
int bytes;
zend_string *return_string;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &shmid, &start, &count) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rll", &shmid, &start, &count) == FAILURE) {
return;
}
- ZEND_FETCH_RESOURCE(shmop, struct php_shmop *, NULL, shmid, "shmop", shm_type);
+ if ((shmop = (struct php_shmop *)zend_fetch_resource(Z_RES_P(shmid), "shmop", shm_type))) {
+ RETURN_FALSE;
+ }
if (start < 0 || start > shmop->size) {
php_error_docref(NULL, E_WARNING, "start is out of range");
@@ -280,14 +282,16 @@ PHP_FUNCTION(shmop_close)
returns the shm size */
PHP_FUNCTION(shmop_size)
{
- zend_long shmid;
+ zval *shmid;
struct php_shmop *shmop;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &shmid) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &shmid) == FAILURE) {
return;
}
- ZEND_FETCH_RESOURCE(shmop, struct php_shmop *, NULL, shmid, "shmop", shm_type);
+ if ((shmop = (struct php_shmop *)zend_fetch_resource(Z_RES_P(shmid), "shmop", shm_type))) {
+ RETURN_FALSE;
+ }
RETURN_LONG(shmop->size);
}
@@ -299,14 +303,17 @@ PHP_FUNCTION(shmop_write)
{
struct php_shmop *shmop;
int writesize;
- zend_long shmid, offset;
+ zend_long offset;
zend_string *data;
+ zval *shmid;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "lSl", &shmid, &data, &offset) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSl", &shmid, &data, &offset) == FAILURE) {
return;
}
- ZEND_FETCH_RESOURCE(shmop, struct php_shmop *, NULL, shmid, "shmop", shm_type);
+ if ((shmop = (struct php_shmop *)zend_fetch_resource(Z_RES_P(shmid), "shmop", shm_type))) {
+ RETURN_FALSE;
+ }
if ((shmop->shmatflg & SHM_RDONLY) == SHM_RDONLY) {
php_error_docref(NULL, E_WARNING, "trying to write to a read only segment");
@@ -329,14 +336,16 @@ PHP_FUNCTION(shmop_write)
mark segment for deletion */
PHP_FUNCTION(shmop_delete)
{
- zend_long shmid;
+ zval *shmid;
struct php_shmop *shmop;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &shmid) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &shmid) == FAILURE) {
return;
}
- ZEND_FETCH_RESOURCE(shmop, struct php_shmop *, NULL, shmid, "shmop", shm_type);
+ if ((shmop = (struct php_shmop *)zend_fetch_resource(Z_RES_P(shmid), "shmop", shm_type))) {
+ RETURN_FALSE;
+ }
if (shmctl(shmop->shmid, IPC_RMID, NULL)) {
php_error_docref(NULL, E_WARNING, "can't mark segment for deletion (are you the owner?)");