diff options
Diffstat (limited to 'ext/shmop')
-rw-r--r-- | ext/shmop/php_shmop.h | 9 | ||||
-rw-r--r-- | ext/shmop/shmop.c | 90 | ||||
-rw-r--r-- | ext/shmop/shmop.stub.php | 21 | ||||
-rw-r--r-- | ext/shmop/shmop_arginfo.h | 51 | ||||
-rw-r--r-- | ext/shmop/tests/001.phpt | 108 | ||||
-rw-r--r-- | ext/shmop/tests/002.phpt | 95 |
6 files changed, 174 insertions, 200 deletions
diff --git a/ext/shmop/php_shmop.h b/ext/shmop/php_shmop.h index 1aafa6c6f4..af17a2b899 100644 --- a/ext/shmop/php_shmop.h +++ b/ext/shmop/php_shmop.h @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | @@ -30,13 +28,6 @@ extern zend_module_entry shmop_module_entry; PHP_MINIT_FUNCTION(shmop); PHP_MINFO_FUNCTION(shmop); -PHP_FUNCTION(shmop_open); -PHP_FUNCTION(shmop_read); -PHP_FUNCTION(shmop_close); -PHP_FUNCTION(shmop_size); -PHP_FUNCTION(shmop_write); -PHP_FUNCTION(shmop_delete); - #ifdef PHP_WIN32 # include "win32/ipc.h" #endif diff --git a/ext/shmop/shmop.c b/ext/shmop/shmop.c index 07414f2bca..de2d966143 100644 --- a/ext/shmop/shmop.c +++ b/ext/shmop/shmop.c @@ -24,6 +24,8 @@ #include "php.h" #include "php_ini.h" #include "php_shmop.h" +#include "shmop_arginfo.h" + # ifndef PHP_WIN32 # include <sys/ipc.h> # include <sys/shm.h> @@ -44,58 +46,12 @@ php_shmop_globals shmop_globals; int shm_type; -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_shmop_open, 0, 0, 4) - ZEND_ARG_INFO(0, key) - ZEND_ARG_INFO(0, flags) - ZEND_ARG_INFO(0, mode) - ZEND_ARG_INFO(0, size) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_shmop_read, 0, 0, 3) - ZEND_ARG_INFO(0, shmid) - ZEND_ARG_INFO(0, start) - ZEND_ARG_INFO(0, count) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_shmop_close, 0, 0, 1) - ZEND_ARG_INFO(0, shmid) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_shmop_size, 0, 0, 1) - ZEND_ARG_INFO(0, shmid) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_shmop_write, 0, 0, 3) - ZEND_ARG_INFO(0, shmid) - ZEND_ARG_INFO(0, data) - ZEND_ARG_INFO(0, offset) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_shmop_delete, 0, 0, 1) - ZEND_ARG_INFO(0, shmid) -ZEND_END_ARG_INFO() -/* }}} */ - -/* {{{ shmop_functions[] - */ -static const zend_function_entry shmop_functions[] = { - PHP_FE(shmop_open, arginfo_shmop_open) - PHP_FE(shmop_read, arginfo_shmop_read) - PHP_FE(shmop_close, arginfo_shmop_close) - PHP_FE(shmop_size, arginfo_shmop_size) - PHP_FE(shmop_write, arginfo_shmop_write) - PHP_FE(shmop_delete, arginfo_shmop_delete) - PHP_FE_END -}; -/* }}} */ - /* {{{ shmop_module_entry */ zend_module_entry shmop_module_entry = { STANDARD_MODULE_HEADER, "shmop", - shmop_functions, + ext_functions, PHP_MINIT(shmop), NULL, NULL, @@ -152,7 +108,7 @@ PHP_FUNCTION(shmop_open) size_t flags_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "lsll", &key, &flags, &flags_len, &mode, &size) == FAILURE) { - return; + RETURN_THROWS(); } if (flags_len != 1) { @@ -186,7 +142,7 @@ PHP_FUNCTION(shmop_open) */ break; default: - php_error_docref(NULL, E_WARNING, "invalid access mode"); + php_error_docref(NULL, E_WARNING, "Invalid access mode"); goto err; } @@ -197,13 +153,13 @@ PHP_FUNCTION(shmop_open) shmop->shmid = shmget(shmop->key, shmop->size, shmop->shmflg); if (shmop->shmid == -1) { - php_error_docref(NULL, E_WARNING, "unable to attach or create shared memory segment '%s'", strerror(errno)); + php_error_docref(NULL, E_WARNING, "Unable to attach or create shared memory segment '%s'", strerror(errno)); goto err; } if (shmctl(shmop->shmid, IPC_STAT, &shm)) { /* please do not add coverage here: the segment would be leaked and impossible to delete via php */ - php_error_docref(NULL, E_WARNING, "unable to get shared memory segment information '%s'", strerror(errno)); + php_error_docref(NULL, E_WARNING, "Unable to get shared memory segment information '%s'", strerror(errno)); goto err; } @@ -214,7 +170,7 @@ PHP_FUNCTION(shmop_open) shmop->addr = shmat(shmop->shmid, 0, shmop->shmatflg); if (shmop->addr == (char*) -1) { - php_error_docref(NULL, E_WARNING, "unable to attach to shared memory segment '%s'", strerror(errno)); + php_error_docref(NULL, E_WARNING, "Unable to attach to shared memory segment '%s'", strerror(errno)); goto err; } @@ -239,20 +195,20 @@ PHP_FUNCTION(shmop_read) zend_string *return_string; if (zend_parse_parameters(ZEND_NUM_ARGS(), "rll", &shmid, &start, &count) == FAILURE) { - return; + RETURN_THROWS(); } if ((shmop = (struct php_shmop *)zend_fetch_resource(Z_RES_P(shmid), "shmop", shm_type)) == NULL) { - RETURN_FALSE; + RETURN_THROWS(); } if (start < 0 || start > shmop->size) { - php_error_docref(NULL, E_WARNING, "start is out of range"); + php_error_docref(NULL, E_WARNING, "Start is out of range"); RETURN_FALSE; } if (count < 0 || start > (INT_MAX - count) || start + count > shmop->size) { - php_error_docref(NULL, E_WARNING, "count is out of range"); + php_error_docref(NULL, E_WARNING, "Count is out of range"); RETURN_FALSE; } @@ -273,12 +229,12 @@ PHP_FUNCTION(shmop_close) struct php_shmop *shmop; if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &shmid) == FAILURE) { - return; + RETURN_THROWS(); } if ((shmop = (struct php_shmop *)zend_fetch_resource(Z_RES_P(shmid), "shmop", shm_type)) == NULL) { - RETURN_FALSE; + RETURN_THROWS(); } zend_list_close(Z_RES_P(shmid)); @@ -293,11 +249,11 @@ PHP_FUNCTION(shmop_size) struct php_shmop *shmop; if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &shmid) == FAILURE) { - return; + RETURN_THROWS(); } if ((shmop = (struct php_shmop *)zend_fetch_resource(Z_RES_P(shmid), "shmop", shm_type)) == NULL) { - RETURN_FALSE; + RETURN_THROWS(); } RETURN_LONG(shmop->size); @@ -315,20 +271,20 @@ PHP_FUNCTION(shmop_write) zval *shmid; if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSl", &shmid, &data, &offset) == FAILURE) { - return; + RETURN_THROWS(); } if ((shmop = (struct php_shmop *)zend_fetch_resource(Z_RES_P(shmid), "shmop", shm_type)) == NULL) { - RETURN_FALSE; + RETURN_THROWS(); } if ((shmop->shmatflg & SHM_RDONLY) == SHM_RDONLY) { - php_error_docref(NULL, E_WARNING, "trying to write to a read only segment"); + php_error_docref(NULL, E_WARNING, "Trying to write to a read only segment"); RETURN_FALSE; } if (offset < 0 || offset > shmop->size) { - php_error_docref(NULL, E_WARNING, "offset out of range"); + php_error_docref(NULL, E_WARNING, "Offset out of range"); RETURN_FALSE; } @@ -347,15 +303,15 @@ PHP_FUNCTION(shmop_delete) struct php_shmop *shmop; if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &shmid) == FAILURE) { - return; + RETURN_THROWS(); } if ((shmop = (struct php_shmop *)zend_fetch_resource(Z_RES_P(shmid), "shmop", shm_type)) == NULL) { - RETURN_FALSE; + RETURN_THROWS(); } if (shmctl(shmop->shmid, IPC_RMID, NULL)) { - php_error_docref(NULL, E_WARNING, "can't mark segment for deletion (are you the owner?)"); + php_error_docref(NULL, E_WARNING, "Can't mark segment for deletion (are you the owner?)"); RETURN_FALSE; } diff --git a/ext/shmop/shmop.stub.php b/ext/shmop/shmop.stub.php new file mode 100644 index 0000000000..92f5c212b8 --- /dev/null +++ b/ext/shmop/shmop.stub.php @@ -0,0 +1,21 @@ +<?php + +/** @generate-function-entries */ + +/** @return resource|false */ +function shmop_open(int $key, string $flags, int $mode, int $size) {} + +/** @param resource $shmid */ +function shmop_read($shmid, int $start, int $count): string|false {} + +/** @param resource $shmid */ +function shmop_close($shmid): void {} + +/** @param resource $shmid */ +function shmop_size($shmid): int {} + +/** @param resource $shmid */ +function shmop_write($shmid, string $data, int $offset): int|false {} + +/** @param resource $shmid */ +function shmop_delete($shmid): bool {} diff --git a/ext/shmop/shmop_arginfo.h b/ext/shmop/shmop_arginfo.h new file mode 100644 index 0000000000..8832596db1 --- /dev/null +++ b/ext/shmop/shmop_arginfo.h @@ -0,0 +1,51 @@ +/* This is a generated file, edit the .stub.php file instead. */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_shmop_open, 0, 0, 4) + ZEND_ARG_TYPE_INFO(0, key, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, flags, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_shmop_read, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_INFO(0, shmid) + ZEND_ARG_TYPE_INFO(0, start, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, count, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shmop_close, 0, 1, IS_VOID, 0) + ZEND_ARG_INFO(0, shmid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shmop_size, 0, 1, IS_LONG, 0) + ZEND_ARG_INFO(0, shmid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_shmop_write, 0, 3, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_INFO(0, shmid) + ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shmop_delete, 0, 1, _IS_BOOL, 0) + ZEND_ARG_INFO(0, shmid) +ZEND_END_ARG_INFO() + + +ZEND_FUNCTION(shmop_open); +ZEND_FUNCTION(shmop_read); +ZEND_FUNCTION(shmop_close); +ZEND_FUNCTION(shmop_size); +ZEND_FUNCTION(shmop_write); +ZEND_FUNCTION(shmop_delete); + + +static const zend_function_entry ext_functions[] = { + ZEND_FE(shmop_open, arginfo_shmop_open) + ZEND_FE(shmop_read, arginfo_shmop_read) + ZEND_FE(shmop_close, arginfo_shmop_close) + ZEND_FE(shmop_size, arginfo_shmop_size) + ZEND_FE(shmop_write, arginfo_shmop_write) + ZEND_FE(shmop_delete, arginfo_shmop_delete) + ZEND_FE_END +}; diff --git a/ext/shmop/tests/001.phpt b/ext/shmop/tests/001.phpt index a5ad01c302..48e722d2f0 100644 --- a/ext/shmop/tests/001.phpt +++ b/ext/shmop/tests/001.phpt @@ -8,73 +8,73 @@ shmop extension test ?> --FILE-- <?php - $hex_shm_id = 0xff3; - $write_d1 = "test #1 of the shmop() extension"; - $write_d2 = "test #2 append data to shared memory segment"; + $hex_shm_id = 0xff3; + $write_d1 = "test #1 of the shmop() extension"; + $write_d2 = "test #2 append data to shared memory segment"; - echo "shm open for create: "; - $shm_id = shmop_open($hex_shm_id, "n", 0644, 1024); - if (!$shm_id) { - die("failed\n"); - } else { - echo "ok\n"; - } + echo "shm open for create: "; + $shm_id = shmop_open($hex_shm_id, "n", 0644, 1024); + if (!$shm_id) { + die("failed\n"); + } else { + echo "ok\n"; + } - echo "shm size is: " . ($shm_size = shmop_size($shm_id)) . "\n"; + echo "shm size is: " . ($shm_size = shmop_size($shm_id)) . "\n"; - echo "shm write test #1: "; - $written = shmop_write($shm_id, $write_d1, 0); - if ($written != strlen($write_d1)) { - echo "failed\n"; - } else { - echo "ok\n"; - } + echo "shm write test #1: "; + $written = shmop_write($shm_id, $write_d1, 0); + if ($written != strlen($write_d1)) { + echo "failed\n"; + } else { + echo "ok\n"; + } - echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n"; + echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n"; - shmop_close($shm_id); + shmop_close($shm_id); - echo "shm open for read only: "; - $shm_id = shmop_open($hex_shm_id, "a", 0644, 1024); - if (!$shm_id) { - echo "failed\n"; - } else { - echo "ok\n"; - } + echo "shm open for read only: "; + $shm_id = shmop_open($hex_shm_id, "a", 0644, 1024); + if (!$shm_id) { + echo "failed\n"; + } else { + echo "ok\n"; + } - echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n"; + echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n"; - /* try to append data to the shared memory segment, this should fail */ - shmop_write($shm_id, $write_d1, $written); + /* try to append data to the shared memory segment, this should fail */ + shmop_write($shm_id, $write_d1, $written); - shmop_close($shm_id); + shmop_close($shm_id); - echo "shm open for read only: "; - $shm_id = shmop_open($hex_shm_id, "w", 0644, 1024); - if (!$shm_id) { - echo "failed\n"; - } else { - echo "ok\n"; - } + echo "shm open for read only: "; + $shm_id = shmop_open($hex_shm_id, "w", 0644, 1024); + if (!$shm_id) { + echo "failed\n"; + } else { + echo "ok\n"; + } - echo "shm write test #1: "; - $written = shmop_write($shm_id, $write_d2, $written); - if ($written != strlen($write_d2)) { - die("failed\n"); - } else { - echo "ok\n"; - } + echo "shm write test #1: "; + $written = shmop_write($shm_id, $write_d2, $written); + if ($written != strlen($write_d2)) { + die("failed\n"); + } else { + echo "ok\n"; + } - echo "data in memory is: " . shmop_read($shm_id, 0, strlen($write_d1 . $write_d2)) . "\n"; + echo "data in memory is: " . shmop_read($shm_id, 0, strlen($write_d1 . $write_d2)) . "\n"; - echo "deletion of shm segment: "; - if (!shmop_delete($shm_id)) { - echo "failed\n"; - } else { - echo "ok\n"; - } + echo "deletion of shm segment: "; + if (!shmop_delete($shm_id)) { + echo "failed\n"; + } else { + echo "ok\n"; + } - shmop_close($shm_id); + shmop_close($shm_id); ?> --EXPECTF-- shm open for create: ok @@ -84,7 +84,7 @@ data in memory is: test #1 of the shmop() extension shm open for read only: ok data in memory is: test #1 of the shmop() extension -Warning: shmop_write(): trying to write to a read only segment in %s on line %d +Warning: shmop_write(): Trying to write to a read only segment in %s on line %d shm open for read only: ok shm write test #1: ok data in memory is: test #1 of the shmop() extensiontest #2 append data to shared memory segment diff --git a/ext/shmop/tests/002.phpt b/ext/shmop/tests/002.phpt index 94d536a175..f1f084fdbf 100644 --- a/ext/shmop/tests/002.phpt +++ b/ext/shmop/tests/002.phpt @@ -4,9 +4,6 @@ shmop extension error messages edgarsandi - <edgar.r.sandi@gmail.com> --SKIPIF-- <?php - if( substr(PHP_OS, 0, 3) == "WIN") { - die('skip not for Windows'); - } if (!extension_loaded("shmop")) { die("skip shmop() extension not available"); } @@ -15,98 +12,56 @@ edgarsandi - <edgar.r.sandi@gmail.com> <?php echo PHP_EOL, '## shmop_open function tests ##'; - // warning outputs: 4 parameters expected - var_dump($shm_id = shmop_open()); - - // warning outputs: invalid flag when the flags length != 1 - var_dump(shmop_open(1338, '', 0644, 1024)); + // warning outputs: invalid flag when the flags length != 1 + var_dump(shmop_open(1338, '', 0644, 1024)); - // warning outputs: invalid access mode - var_dump(shmop_open(1338, 'b', 0644, 1024)); + // warning outputs: invalid access mode + var_dump(shmop_open(1338, 'b', 0644, 1024)); - // warning outputs: unable to attach or create shared memory segment - var_dump(shmop_open(null, 'a', 0644, 1024)); + // warning outputs: unable to attach or create shared memory segment + var_dump(shmop_open(null, 'a', 0644, 1024)); - // warning outputs: Shared memory segment size must be greater than zero - var_dump(shmop_open(1338, "c", 0666, 0)); + // warning outputs: Shared memory segment size must be greater than zero + var_dump(shmop_open(1338, "c", 0666, 0)); echo PHP_EOL, '## shmop_read function tests ##'; - // warning outputs: 3 parameters expected - var_dump(shmop_read()); + // warning outputs: start is out of range + $shm_id = shmop_open(1338, 'n', 0600, 1024); + var_dump(shmop_read($shm_id, -10, 0)); + shmop_delete($shm_id); - // warning outputs: start is out of range - $shm_id = shmop_open(1338, 'n', 0600, 1024); - var_dump(shmop_read($shm_id, -10, 0)); - shmop_delete($shm_id); - - // warning outputs: count is out of range - $shm_id = shmop_open(1339, 'n', 0600, 1024); - var_dump(shmop_read($shm_id, 0, -10)); - shmop_delete($shm_id); + // warning outputs: count is out of range + $shm_id = shmop_open(1339, 'n', 0600, 1024); + var_dump(shmop_read($shm_id, 0, -10)); + shmop_delete($shm_id); echo PHP_EOL, '## shmop_write function tests ##'; - // warning outputs: 3 parameters expected - var_dump(shmop_write()); - - // warning outputs: offset out of range - $shm_id = shmop_open(1340, 'n', 0600, 1024); - var_dump(shmop_write($shm_id, 'text to try write', -10)); - shmop_delete($shm_id); - -echo PHP_EOL, '## shmop_size function tests ##'; - // warning outputs: 1 parameter expected - var_dump(shmop_size()); - -echo PHP_EOL, '## shmop_delete function tests ##'; - // warning outputs: 1 parameter expected - var_dump(shmop_delete()); - -echo PHP_EOL, '## shmop_close function tests ##'; - // warning outputs: 1 parameter expected - var_dump(shmop_close()); + // warning outputs: offset out of range + $shm_id = shmop_open(1340, 'n', 0600, 1024); + var_dump(shmop_write($shm_id, 'text to try write', -10)); + shmop_delete($shm_id); ?> --EXPECTF-- ## shmop_open function tests ## -Warning: shmop_open() expects exactly 4 parameters, 0 given in %s on line %d -NULL - Warning: shmop_open(): is not a valid flag in %s on line %d bool(false) -Warning: shmop_open(): invalid access mode in %s on line %d +Warning: shmop_open(): Invalid access mode in %s on line %d bool(false) -Warning: shmop_open(): unable to attach or create shared memory segment 'Invalid argument' in %s on line %d +Warning: shmop_open(): Unable to attach or create shared memory segment '%s' in %s on line %d bool(false) Warning: shmop_open(): Shared memory segment size must be greater than zero in %s on line %d bool(false) ## shmop_read function tests ## -Warning: shmop_read() expects exactly 3 parameters, 0 given in %s on line %d -NULL - -Warning: shmop_read(): start is out of range in %s on line %d +Warning: shmop_read(): Start is out of range in %s on line %d bool(false) -Warning: shmop_read(): count is out of range in %s on line %d +Warning: shmop_read(): Count is out of range in %s on line %d bool(false) ## shmop_write function tests ## -Warning: shmop_write() expects exactly 3 parameters, 0 given in %s on line %d -NULL - -Warning: shmop_write(): offset out of range in %s on line %d +Warning: shmop_write(): Offset out of range in %s on line %d bool(false) - -## shmop_size function tests ## -Warning: shmop_size() expects exactly 1 parameter, 0 given in %s on line %d -NULL - -## shmop_delete function tests ## -Warning: shmop_delete() expects exactly 1 parameter, 0 given in %s on line %d -NULL - -## shmop_close function tests ## -Warning: shmop_close() expects exactly 1 parameter, 0 given in %s on line %d -NULL |