diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/shmop | |
download | php2-c4dd7a1a684490673e25aaf4fabec5df138854c4.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/shmop')
-rw-r--r-- | ext/shmop/CREDITS | 2 | ||||
-rw-r--r-- | ext/shmop/README | 69 | ||||
-rw-r--r-- | ext/shmop/config.m4 | 8 | ||||
-rw-r--r-- | ext/shmop/config.w32 | 9 | ||||
-rw-r--r-- | ext/shmop/package.xml | 47 | ||||
-rw-r--r-- | ext/shmop/package2.xml | 57 | ||||
-rw-r--r-- | ext/shmop/php_shmop.h | 75 | ||||
-rw-r--r-- | ext/shmop/shmop.c | 377 | ||||
-rw-r--r-- | ext/shmop/shmop.dsp | 107 | ||||
-rw-r--r-- | ext/shmop/tests/001.phpt | 91 |
10 files changed, 842 insertions, 0 deletions
diff --git a/ext/shmop/CREDITS b/ext/shmop/CREDITS new file mode 100644 index 0000000..caab89e --- /dev/null +++ b/ext/shmop/CREDITS @@ -0,0 +1,2 @@ +Shared Memory Operations +Slava Poliakov, Ilia Alshanetsky diff --git a/ext/shmop/README b/ext/shmop/README new file mode 100644 index 0000000..5ec1586 --- /dev/null +++ b/ext/shmop/README @@ -0,0 +1,69 @@ +last update Jan 2, 2002 (hackie@prohost.org/ilia@prohost.org) + +Shared Memory Operations Extension to PHP + + While developing a search deamon we needed a php based front end + to communicate the deamon via SHM. PHP already had a shared memory + extention (sysvshm) written by Christian Cartus <cartus@atrior.de>, + unfortunatly this extention was designed with PHP only in mind and + offers high level features which are extremly bothersome for basic SHM + we had in mind. After spending a day trying to reverse engineer and figure + out the format of sysvshm we decided that it would be much easier to + add our own extention to php for simple SHM operations, we were right :)). + +the functions are: + +int shmop_open(int key, string flags, int mode, int size) + + key - the key of/for the shared memory block + flags - 4 flags are avalible + a for read only access (sets SHM_RDONLY) + w for read & write access + c create or open an existing segment (sets IPC_CREATE) + n create a new segment and fail if one already exists under same name (sets IPC_CREATE|IPC_EXCL) + (the n flag is mostly useful for security perpouses, so that you don't end up opening a faked segment + if someone guesses your key) + mode - acsess mode same as for a file (0644) for example + size - size of the block in bytes + + returns an indentifier + + +char shmop_read(int shmid, int start, int count) + + shmid - shmid from which to read + start - offset from which to start reading + count - how many bytes to read + + returns the data read + +int shmop_write(int shmid, string data, int offset) + + shmid - shmid from which to read + data - string to put into shared memory + offset - offset in shm to write from + + returns bytes written + +int shmop_size(int shmid) + + shmid - shmid for which to return the size + + returns the size in bytes of the shm segment + + +int shmop_delete(int shmid) + + marks the segment for deletion, the segment will be deleted when all processes mapping it will detach + + shmid - shmid which to mark for deletion + + returns 1 if all ok, zero on failure + +int shmop_close(int shmid) + + shmid - shmid which to close + + returns zero + + diff --git a/ext/shmop/config.m4 b/ext/shmop/config.m4 new file mode 100644 index 0000000..6c1709d --- /dev/null +++ b/ext/shmop/config.m4 @@ -0,0 +1,8 @@ +dnl $Id$ +PHP_ARG_ENABLE(shmop, whether to enable shmop support, +[ --enable-shmop Enable shmop support]) + +if test "$PHP_SHMOP" != "no"; then + AC_DEFINE(HAVE_SHMOP, 1, [ ]) + PHP_NEW_EXTENSION(shmop, shmop.c, $ext_shared) +fi diff --git a/ext/shmop/config.w32 b/ext/shmop/config.w32 new file mode 100644 index 0000000..9302184 --- /dev/null +++ b/ext/shmop/config.w32 @@ -0,0 +1,9 @@ +// $Id$ +// vim:ft=javascript + +ARG_ENABLE("shmop", "shmop support", "no"); + +if (PHP_SHMOP == "yes") { + EXTENSION("shmop", "shmop.c"); + AC_DEFINE('HAVE_SHMOP', 1, 'Have SHMOP support'); +} diff --git a/ext/shmop/package.xml b/ext/shmop/package.xml new file mode 100644 index 0000000..2bba143 --- /dev/null +++ b/ext/shmop/package.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<!DOCTYPE package SYSTEM "../pear/package.dtd"> +<package> + <name>shmop</name> + <summary>Portable shared memory access</summary> + <maintainers> + <maintainer> + <user>iliaa</user> + <name>Ilia Alshanetsky</name> + <email>ilia@prohost.org</email> + <role>lead</role> + </maintainer> + <maintainer> + <name>Slava Poliakov</name> + <email>hackie@prohost.org</email> + <role>developer</role> + </maintainer> + </maintainers> + <description> + Portable Shared Memory access + </description> + <license>PHP</license> + <release> + <state>stable</state> + <version>5.0.0rc1</version> + <date>2004-03-19</date> + <notes> +package.xml added to support installation using pear installer + </notes> + <filelist> + <file role="doc" name="CREDITS"/> + <file role="doc" name="README"/> + <file role="src" name="config.m4"/> + <file role="src" name="config.w32"/> + <file role="src" name="shmop.dsp"/> + <file role="src" name="shmop.c"/> + <file role="src" name="php_shmop.h"/> + <file role="test" name="tests/001.phpt"/> + </filelist> + <deps> + <dep type="php" rel="ge" version="5" /> + </deps> + </release> +</package> +<!-- +vim:et:ts=1:sw=1 +--> diff --git a/ext/shmop/package2.xml b/ext/shmop/package2.xml new file mode 100644 index 0000000..e592615 --- /dev/null +++ b/ext/shmop/package2.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<package packagerversion="1.4.6" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 +http://pear.php.net/dtd/tasks-1.0.xsd +http://pear.php.net/dtd/package-2.0 +http://pear.php.net/dtd/package-2.0.xsd"> + <name>shmop</name> + <channel>pecl.php.net</channel> + <summary>Portable shared memory access</summary> + <description>Portable Shared Memory access + </description> + <lead> + <name>Ilia Alshanetsky</name> + <user>iliaa</user> + <email>ilia@prohost.org</email> + <active>yes</active> + </lead> + <date>2007-07-03</date> + <time>19:58:51</time> + <version> + <release>5.0.0rc1</release> + <api>5.0.0rc1</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.php.net/license">PHP</license> + <notes>package.xml added to support installation using pear installer + + </notes> + <contents> + <dir name="/"> + <dir name="tests"> + <file name="001.phpt" role="test" /> + </dir> <!-- //tests --> + <file name="config.m4" role="src" /> + <file name="config.w32" role="src" /> + <file name="CREDITS" role="doc" /> + <file name="php_shmop.h" role="src" /> + <file name="README" role="doc" /> + <file name="shmop.c" role="src" /> + <file name="shmop.dsp" role="src" /> + </dir> <!-- / --> + </contents> + <dependencies> + <required> + <php> + <min>5</min> + </php> + <pearinstaller> + <min>1.4.0b1</min> + </pearinstaller> + </required> + </dependencies> + <providesextension>shmop</providesextension> + <extsrcrelease /> +</package> diff --git a/ext/shmop/php_shmop.h b/ext/shmop/php_shmop.h new file mode 100644 index 0000000..0abc703 --- /dev/null +++ b/ext/shmop/php_shmop.h @@ -0,0 +1,75 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Slava Poliakov <hackie@prohost.org> | + | Ilia Alshanetsky <ilia@prohost.org> | + +----------------------------------------------------------------------+ + */ +#ifndef PHP_SHMOP_H +#define PHP_SHMOP_H + +#if HAVE_SHMOP + +extern zend_module_entry shmop_module_entry; +#define phpext_shmop_ptr &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 +typedef int key_t; +#endif + +struct php_shmop +{ + int shmid; + key_t key; + int shmflg; + int shmatflg; + char *addr; + int size; +}; + +typedef struct { + int le_shmop; +} php_shmop_globals; + +#ifdef ZTS +#define SHMOPG(v) TSRMG(shmop_globals_id, php_shmop_globals *, v) +#else +#define SHMOPG(v) (shmop_globals.v) +#endif + +#else + +#define phpext_shmop_ptr NULL + +#endif + +#endif /* PHP_SHMOP_H */ + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/ext/shmop/shmop.c b/ext/shmop/shmop.c new file mode 100644 index 0000000..a14a0b7 --- /dev/null +++ b/ext/shmop/shmop.c @@ -0,0 +1,377 @@ +/* + +----------------------------------------------------------------------+ + | PHP version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Slava Poliakov <hackie@prohost.org> | + | Ilia Alshanetsky <ilia@prohost.org> | + +----------------------------------------------------------------------+ + */ +/* $Id$ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" +#include "php_ini.h" +#include "php_shmop.h" +# ifndef PHP_WIN32 +# include <sys/ipc.h> +# include <sys/shm.h> +#else +#include "tsrm_win32.h" +#endif + + +#if HAVE_SHMOP + +#include "ext/standard/info.h" + +#ifdef ZTS +int shmop_globals_id; +#else +php_shmop_globals shmop_globals; +#endif + +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[] + */ +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, + PHP_MINIT(shmop), + NULL, + NULL, + NULL, + PHP_MINFO(shmop), + NO_VERSION_YET, + STANDARD_MODULE_PROPERTIES +}; +/* }}} */ + +#ifdef COMPILE_DL_SHMOP +ZEND_GET_MODULE(shmop) +#endif + +#define PHP_SHMOP_GET_RES \ + shmop = zend_list_find(shmid, &type); \ + if (!shmop) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "no shared memory segment with an id of [%lu]", shmid); \ + RETURN_FALSE; \ + } else if (type != shm_type) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "not a shmop resource"); \ + RETURN_FALSE; \ + } \ + +/* {{{ rsclean + */ +static void rsclean(zend_rsrc_list_entry *rsrc TSRMLS_DC) +{ + struct php_shmop *shmop = (struct php_shmop *)rsrc->ptr; + + shmdt(shmop->addr); + efree(shmop); +} +/* }}} */ + +/* {{{ PHP_MINIT_FUNCTION + */ +PHP_MINIT_FUNCTION(shmop) +{ + shm_type = zend_register_list_destructors_ex(rsclean, NULL, "shmop", module_number); + + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_MINFO_FUNCTION + */ +PHP_MINFO_FUNCTION(shmop) +{ + php_info_print_table_start(); + php_info_print_table_row(2, "shmop support", "enabled"); + php_info_print_table_end(); +} +/* }}} */ + +/* {{{ proto int shmop_open (int key, string flags, int mode, int size) + gets and attaches a shared memory segment */ +PHP_FUNCTION(shmop_open) +{ + long key, mode, size; + struct php_shmop *shmop; + struct shmid_ds shm; + int rsid; + char *flags; + int flags_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsll", &key, &flags, &flags_len, &mode, &size) == FAILURE) { + return; + } + + if (flags_len != 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s is not a valid flag", flags); + RETURN_FALSE; + } + + shmop = emalloc(sizeof(struct php_shmop)); + memset(shmop, 0, sizeof(struct php_shmop)); + + shmop->key = key; + shmop->shmflg |= mode; + + switch (flags[0]) + { + case 'a': + shmop->shmatflg |= SHM_RDONLY; + break; + case 'c': + shmop->shmflg |= IPC_CREAT; + shmop->size = size; + break; + case 'n': + shmop->shmflg |= (IPC_CREAT | IPC_EXCL); + shmop->size = size; + break; + case 'w': + /* noop + shm segment is being opened for read & write + will fail if segment does not exist + */ + break; + default: + php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid access mode"); + goto err; + } + + if (shmop->shmflg & IPC_CREAT && shmop->size < 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Shared memory segment size must be greater than zero"); + goto err; + } + + shmop->shmid = shmget(shmop->key, shmop->size, shmop->shmflg); + if (shmop->shmid == -1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to attach or create shared memory segment"); + goto err; + } + + if (shmctl(shmop->shmid, IPC_STAT, &shm)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to get shared memory segment information"); + goto err; + } + + shmop->addr = shmat(shmop->shmid, 0, shmop->shmatflg); + if (shmop->addr == (char*) -1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to attach to shared memory segment"); + goto err; + } + + shmop->size = shm.shm_segsz; + + rsid = zend_list_insert(shmop, shm_type TSRMLS_CC); + RETURN_LONG(rsid); +err: + efree(shmop); + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto string shmop_read (int shmid, int start, int count) + reads from a shm segment */ +PHP_FUNCTION(shmop_read) +{ + long shmid, start, count; + struct php_shmop *shmop; + int type; + char *startaddr; + int bytes; + char *return_string; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &shmid, &start, &count) == FAILURE) { + return; + } + + PHP_SHMOP_GET_RES + + if (start < 0 || start > shmop->size) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "start is out of range"); + RETURN_FALSE; + } + + if (count < 0 || start > (INT_MAX - count) || start + count > shmop->size) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "count is out of range"); + RETURN_FALSE; + } + + startaddr = shmop->addr + start; + bytes = count ? count : shmop->size - start; + + return_string = emalloc(bytes+1); + memcpy(return_string, startaddr, bytes); + return_string[bytes] = 0; + + RETURN_STRINGL(return_string, bytes, 0); +} +/* }}} */ + +/* {{{ proto void shmop_close (int shmid) + closes a shared memory segment */ +PHP_FUNCTION(shmop_close) +{ + long shmid; + struct php_shmop *shmop; + int type; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &shmid) == FAILURE) { + return; + } + + PHP_SHMOP_GET_RES + + zend_list_delete(shmid); +} +/* }}} */ + +/* {{{ proto int shmop_size (int shmid) + returns the shm size */ +PHP_FUNCTION(shmop_size) +{ + long shmid; + struct php_shmop *shmop; + int type; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &shmid) == FAILURE) { + return; + } + + PHP_SHMOP_GET_RES + + RETURN_LONG(shmop->size); +} +/* }}} */ + +/* {{{ proto int shmop_write (int shmid, string data, int offset) + writes to a shared memory segment */ +PHP_FUNCTION(shmop_write) +{ + struct php_shmop *shmop; + int type; + int writesize; + long shmid, offset; + char *data; + int data_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsl", &shmid, &data, &data_len, &offset) == FAILURE) { + return; + } + + PHP_SHMOP_GET_RES + + if ((shmop->shmatflg & SHM_RDONLY) == SHM_RDONLY) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "trying to write to a read only segment"); + RETURN_FALSE; + } + + if (offset < 0 || offset > shmop->size) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "offset out of range"); + RETURN_FALSE; + } + + writesize = (data_len < shmop->size - offset) ? data_len : shmop->size - offset; + memcpy(shmop->addr + offset, data, writesize); + + RETURN_LONG(writesize); +} +/* }}} */ + +/* {{{ proto bool shmop_delete (int shmid) + mark segment for deletion */ +PHP_FUNCTION(shmop_delete) +{ + long shmid; + struct php_shmop *shmop; + int type; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &shmid) == FAILURE) { + return; + } + + PHP_SHMOP_GET_RES + + if (shmctl(shmop->shmid, IPC_RMID, NULL)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "can't mark segment for deletion (are you the owner?)"); + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + +#endif /* HAVE_SHMOP */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/ext/shmop/shmop.dsp b/ext/shmop/shmop.dsp new file mode 100644 index 0000000..848f0bd --- /dev/null +++ b/ext/shmop/shmop.dsp @@ -0,0 +1,107 @@ +# Microsoft Developer Studio Project File - Name="shmop" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=shmop - Win32 Debug_TS
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "shmop.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "shmop.mak" CFG="shmop - Win32 Debug_TS"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "shmop - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "shmop - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "shmop - Win32 Release_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release_TS"
+# PROP BASE Intermediate_Dir "Release_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_TS"
+# PROP Intermediate_Dir "Release_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SHMOP_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\\" /I "..\..\main" /I "..\..\TSRM" /I "..\..\ZEND" /D "WIN32" /D ZEND_WIN32=1 /D PHP_WIN32=1 /D "NDEBUG" /D "PHP_EXPORTS" /D "HAVE_SHMOP" /D COMPILE_DL_SHMOP=1 /D ZEND_DEBUG=0 /D "ZTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 php5ts.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_shmop.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
+
+!ELSEIF "$(CFG)" == "shmop - Win32 Debug_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug_TS"
+# PROP BASE Intermediate_Dir "Debug_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug_TS"
+# PROP Intermediate_Dir "Debug_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SHMOP_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\..\\" /I "..\..\main" /I "..\..\TSRM" /I "..\..\ZEND" /D "WIN32" /D ZEND_DEBUG=1 /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP_EXPORTS" /D "COMPILE_DL_SHMOP" /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_SHMOP=1 /D ZTS=1 /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 php5ts_debug.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_shmop.dll" /pdbtype:sept /libpath:"..\..\Debug_TS"
+
+!ENDIF
+
+# Begin Target
+
+# Name "shmop - Win32 Release_TS"
+# Name "shmop - Win32 Debug_TS"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\shmop.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\php_shmop.h
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/ext/shmop/tests/001.phpt b/ext/shmop/tests/001.phpt new file mode 100644 index 0000000..74f53a0 --- /dev/null +++ b/ext/shmop/tests/001.phpt @@ -0,0 +1,91 @@ +--TEST-- +shmop extension test +--SKIPIF-- +<?php + if (!extension_loaded("shmop")) { + die("skip shmop() extension not available"); + } +?> +--FILE-- +<?php + $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 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 "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n"; + + 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 "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); + echo $php_errormsg . "\n"; + + 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 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 "deletion of shm segment: "; + if (!shmop_delete($shm_id)) { + echo "failed\n"; + } else { + echo "ok\n"; + } + + shmop_close($shm_id); +?> +--EXPECT-- +shm open for create: ok +shm size is: 1024 +shm write test #1: ok +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 +shmop_write(): trying to write to a read only segment +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 +deletion of shm segment: ok |