mirror of
https://github.com/php/php-src.git
synced 2025-08-20 09:24:05 +02:00
Merge branch 'phpng' of git.php.net:php-src into phpng
* 'phpng' of git.php.net:php-src: Refactored shmop
This commit is contained in:
commit
fa4b281c56
1 changed files with 18 additions and 35 deletions
|
@ -111,19 +111,9 @@ zend_module_entry shmop_module_entry = {
|
||||||
ZEND_GET_MODULE(shmop)
|
ZEND_GET_MODULE(shmop)
|
||||||
#endif
|
#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
|
/* {{{ rsclean
|
||||||
*/
|
*/
|
||||||
static void rsclean(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
static void rsclean(zend_resource *rsrc TSRMLS_DC)
|
||||||
{
|
{
|
||||||
struct php_shmop *shmop = (struct php_shmop *)rsrc->ptr;
|
struct php_shmop *shmop = (struct php_shmop *)rsrc->ptr;
|
||||||
|
|
||||||
|
@ -159,7 +149,6 @@ PHP_FUNCTION(shmop_open)
|
||||||
long key, mode, size;
|
long key, mode, size;
|
||||||
struct php_shmop *shmop;
|
struct php_shmop *shmop;
|
||||||
struct shmid_ds shm;
|
struct shmid_ds shm;
|
||||||
int rsid;
|
|
||||||
char *flags;
|
char *flags;
|
||||||
int flags_len;
|
int flags_len;
|
||||||
|
|
||||||
|
@ -209,25 +198,25 @@ PHP_FUNCTION(shmop_open)
|
||||||
|
|
||||||
shmop->shmid = shmget(shmop->key, shmop->size, shmop->shmflg);
|
shmop->shmid = shmget(shmop->key, shmop->size, shmop->shmflg);
|
||||||
if (shmop->shmid == -1) {
|
if (shmop->shmid == -1) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to attach or create shared memory segment");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to attach or create shared memory segment '%s'", strerror(errno));
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shmctl(shmop->shmid, IPC_STAT, &shm)) {
|
if (shmctl(shmop->shmid, IPC_STAT, &shm)) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to get shared memory segment information");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to get shared memory segment information '%s'", strerror(errno));
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
shmop->addr = shmat(shmop->shmid, 0, shmop->shmatflg);
|
shmop->addr = shmat(shmop->shmid, 0, shmop->shmatflg);
|
||||||
if (shmop->addr == (char*) -1) {
|
if (shmop->addr == (char*) -1) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to attach to shared memory segment");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to attach to shared memory segment '%s'", strerror(errno));
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
shmop->size = shm.shm_segsz;
|
shmop->size = shm.shm_segsz;
|
||||||
|
|
||||||
rsid = zend_list_insert(shmop, shm_type TSRMLS_CC);
|
ZEND_REGISTER_RESOURCE(return_value, shmop, shm_type);
|
||||||
RETURN_LONG(rsid);
|
RETURN_LONG(Z_RES_HANDLE_P(return_value));
|
||||||
err:
|
err:
|
||||||
efree(shmop);
|
efree(shmop);
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
|
@ -240,16 +229,15 @@ PHP_FUNCTION(shmop_read)
|
||||||
{
|
{
|
||||||
long shmid, start, count;
|
long shmid, start, count;
|
||||||
struct php_shmop *shmop;
|
struct php_shmop *shmop;
|
||||||
int type;
|
|
||||||
char *startaddr;
|
char *startaddr;
|
||||||
int bytes;
|
int bytes;
|
||||||
char *return_string;
|
zend_string *return_string;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &shmid, &start, &count) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &shmid, &start, &count) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PHP_SHMOP_GET_RES
|
ZEND_FETCH_RESOURCE(shmop, struct php_shmop *, NULL, shmid, "shmop", shm_type);
|
||||||
|
|
||||||
if (start < 0 || start > shmop->size) {
|
if (start < 0 || start > shmop->size) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "start is out of range");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "start is out of range");
|
||||||
|
@ -264,11 +252,9 @@ PHP_FUNCTION(shmop_read)
|
||||||
startaddr = shmop->addr + start;
|
startaddr = shmop->addr + start;
|
||||||
bytes = count ? count : shmop->size - start;
|
bytes = count ? count : shmop->size - start;
|
||||||
|
|
||||||
return_string = emalloc(bytes+1);
|
return_string = STR_INIT(startaddr, bytes, 0);
|
||||||
memcpy(return_string, startaddr, bytes);
|
|
||||||
return_string[bytes] = 0;
|
|
||||||
|
|
||||||
RETURN_STRINGL(return_string, bytes, 0);
|
RETURN_STR(return_string);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -277,16 +263,16 @@ PHP_FUNCTION(shmop_read)
|
||||||
PHP_FUNCTION(shmop_close)
|
PHP_FUNCTION(shmop_close)
|
||||||
{
|
{
|
||||||
long shmid;
|
long shmid;
|
||||||
struct php_shmop *shmop;
|
zval *res;
|
||||||
int type;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &shmid) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &shmid) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PHP_SHMOP_GET_RES
|
res = zend_hash_index_find(&EG(regular_list), shmid);
|
||||||
|
if (res) {
|
||||||
zend_list_delete(shmid);
|
zend_list_close(Z_RES_P(res));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -296,13 +282,12 @@ PHP_FUNCTION(shmop_size)
|
||||||
{
|
{
|
||||||
long shmid;
|
long shmid;
|
||||||
struct php_shmop *shmop;
|
struct php_shmop *shmop;
|
||||||
int type;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &shmid) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &shmid) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PHP_SHMOP_GET_RES
|
ZEND_FETCH_RESOURCE(shmop, struct php_shmop *, NULL, shmid, "shmop", shm_type);
|
||||||
|
|
||||||
RETURN_LONG(shmop->size);
|
RETURN_LONG(shmop->size);
|
||||||
}
|
}
|
||||||
|
@ -313,7 +298,6 @@ PHP_FUNCTION(shmop_size)
|
||||||
PHP_FUNCTION(shmop_write)
|
PHP_FUNCTION(shmop_write)
|
||||||
{
|
{
|
||||||
struct php_shmop *shmop;
|
struct php_shmop *shmop;
|
||||||
int type;
|
|
||||||
int writesize;
|
int writesize;
|
||||||
long shmid, offset;
|
long shmid, offset;
|
||||||
char *data;
|
char *data;
|
||||||
|
@ -323,7 +307,7 @@ PHP_FUNCTION(shmop_write)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PHP_SHMOP_GET_RES
|
ZEND_FETCH_RESOURCE(shmop, struct php_shmop *, NULL, shmid, "shmop", shm_type);
|
||||||
|
|
||||||
if ((shmop->shmatflg & SHM_RDONLY) == SHM_RDONLY) {
|
if ((shmop->shmatflg & SHM_RDONLY) == SHM_RDONLY) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "trying to write to a read only segment");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "trying to write to a read only segment");
|
||||||
|
@ -348,13 +332,12 @@ PHP_FUNCTION(shmop_delete)
|
||||||
{
|
{
|
||||||
long shmid;
|
long shmid;
|
||||||
struct php_shmop *shmop;
|
struct php_shmop *shmop;
|
||||||
int type;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &shmid) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &shmid) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PHP_SHMOP_GET_RES
|
ZEND_FETCH_RESOURCE(shmop, struct php_shmop *, NULL, shmid, "shmop", shm_type);
|
||||||
|
|
||||||
if (shmctl(shmop->shmid, IPC_RMID, NULL)) {
|
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?)");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "can't mark segment for deletion (are you the owner?)");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue