php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #53173
Patch sysvshm.diff revision 2010-10-26 19:19 UTC by marc-bennewitz at arcor dot de

Patch sysvshm.diff for Semaphore related Bug #53173

Patch version 2010-10-26 19:19 UTC

Return to Bug #53173 | Download this patch
Patch Revisions:

Developer: marc-bennewitz@arcor.de

Index: tests/008.phpt
===================================================================
--- tests/008.phpt	(revision 0)
+++ tests/008.phpt	(revision 0)
@@ -0,0 +1,98 @@
+--TEST--
+shm_stat() tests
+--SKIPIF--
+<?php if (!extension_loaded("sysvshm")) print "skip"; ?>
+--FILE--
+<?php
+
+// test errors
+var_dump(shm_stat());
+var_dump(shm_stat(1));
+var_dump(shm_stat(""));
+
+// open shm segment
+$key = ftok(dirname(__FILE__)."/008.phpt", 't');
+$shmId = shm_attach($key, 1024);
+var_dump($shmId);
+
+// first stat call
+var_dump(shm_stat($shmId));
+
+// write data + stat
+var_dump(shm_put_var($shmId, 10, '10'));
+var_dump(shm_put_var($shmId, 20, '20'));
+var_dump(shm_put_var($shmId, 30, '30'));
+var_dump(shm_stat($shmId));
+
+// remove data + stat
+var_dump(shm_remove_var($shmId, 20));
+var_dump(shm_stat($shmId));
+
+// re-open shm segment with different size + stat
+var_dump(shm_detach($shmId));
+$shmId = shm_attach($key, 10240);
+var_dump($shmId);
+var_dump(shm_stat($shmId));
+
+// remove shm segment + stat
+var_dump(shm_remove($shmId));
+var_dump(shm_stat($shmId));
+
+echo "Done\n";
+?>
+--CLEAN--
+<?php
+
+$key = ftok(dirname(__FILE__)."/008.phpt", 't');
+$s = shm_attach($key);
+shm_remove($s);
+
+?>
+--EXPECTF--	
+Warning: shm_stat() expects exactly 1 parameter, 0 given in %s on line %d
+bool(false)
+
+Warning: shm_stat() expects parameter 1 to be resource, integer given in %s on line %d
+bool(false)
+
+Warning: shm_stat() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+resource(%d) of type (sysvshm)
+array(2) {
+  ["total"]=>
+  int(1024)
+  ["free"]=>
+  int(%d)
+}
+bool(true)
+bool(true)
+bool(true)
+array(2) {
+  ["total"]=>
+  int(1024)
+  ["free"]=>
+  int(%d)
+}
+bool(true)
+array(2) {
+  ["total"]=>
+  int(1024)
+  ["free"]=>
+  int(%d)
+}
+bool(true)
+resource(%d) of type (sysvshm)
+array(2) {
+  ["total"]=>
+  int(1024)
+  ["free"]=>
+  int(%d)
+}
+bool(true)
+array(2) {
+  ["total"]=>
+  int(1024)
+  ["free"]=>
+  int(%d)
+}
+Done
Index: php_sysvshm.h
===================================================================
--- php_sysvshm.h	(revision 304930)
+++ php_sysvshm.h	(working copy)
@@ -60,6 +60,7 @@
 
 PHP_MINIT_FUNCTION(sysvshm);
 PHP_FUNCTION(shm_attach);
+PHP_FUNCTION(shm_stat);
 PHP_FUNCTION(shm_detach);
 PHP_FUNCTION(shm_remove);
 PHP_FUNCTION(shm_put_var);
Index: sysvshm.c
===================================================================
--- sysvshm.c	(revision 304930)
+++ sysvshm.c	(working copy)
@@ -46,6 +46,10 @@
 	ZEND_ARG_INFO(0, perm)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_shm_stat, 0, 0, 1)
+  ZEND_ARG_INFO(0, shm_identifier)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_shm_detach, 0, 0, 1)
 	ZEND_ARG_INFO(0, shm_identifier)
 ZEND_END_ARG_INFO()
@@ -80,6 +84,7 @@
  */
 const zend_function_entry sysvshm_functions[] = {
 	PHP_FE(shm_attach,		arginfo_shm_attach)
+	PHP_FE(shm_stat,    	arginfo_shm_stat)
 	PHP_FE(shm_remove,		arginfo_shm_detach)
 	PHP_FE(shm_detach, 		arginfo_shm_remove)
 	PHP_FE(shm_put_var,		arginfo_shm_put_var)
@@ -201,6 +206,24 @@
 }
 /* }}} */
 
+/* {{{ proto array shm_stat(resource shm_identifier)
+   Get status of shared memory segment */
+PHP_FUNCTION(shm_stat)
+{
+  zval *shm_id;
+  sysvshm_shm *shm_list_ptr;
+
+  if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &shm_id)) {
+		RETURN_FALSE;
+  }
+  SHM_FETCH_RESOURCE(shm_list_ptr, shm_id);
+
+  array_init(return_value);
+  add_assoc_long(return_value, "total", shm_list_ptr->ptr->total);
+  add_assoc_long(return_value, "free", shm_list_ptr->ptr->free);
+}
+/* }}} */
+
 /* {{{ proto bool shm_detach(resource shm_identifier)
    Disconnects from shared memory segment */
 PHP_FUNCTION(shm_detach)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 08:01:32 2024 UTC