Skip to content

Commit

Permalink
port sysvshm, sysvsem and sysvmsg
Browse files Browse the repository at this point in the history
  • Loading branch information
weltling committed Aug 19, 2014
1 parent 58aa0f8 commit 5491d01
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 47 deletions.
4 changes: 2 additions & 2 deletions ext/sysvmsg/php_sysvmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ PHP_FUNCTION(msg_queue_exists);

typedef struct {
key_t key;
long id;
php_int_t id;
} sysvmsg_queue_t;

struct php_msgbuf {
long mtype;
php_int_t mtype;
char mtext[1];
};

Expand Down
22 changes: 11 additions & 11 deletions ext/sysvmsg/sysvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ PHP_FUNCTION(msg_stat_queue)
Check whether a message queue exists */
PHP_FUNCTION(msg_queue_exists)
{
long key;
php_int_t key;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &key) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i", &key) == FAILURE) {
return;
}

Expand All @@ -248,11 +248,11 @@ PHP_FUNCTION(msg_queue_exists)
Attach to a message queue */
PHP_FUNCTION(msg_get_queue)
{
long key;
long perms = 0666;
php_int_t key;
php_int_t perms = 0666;
sysvmsg_queue_t *mq;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &key, &perms) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i|i", &key, &perms) == FAILURE) {
return;
}

Expand Down Expand Up @@ -299,16 +299,16 @@ PHP_FUNCTION(msg_remove_queue)
PHP_FUNCTION(msg_receive)
{
zval *out_message, *queue, *out_msgtype, *zerrcode = NULL;
long desiredmsgtype, maxsize, flags = 0;
long realflags = 0;
php_int_t desiredmsgtype, maxsize, flags = 0;
php_int_t realflags = 0;
zend_bool do_unserialize = 1;
sysvmsg_queue_t *mq = NULL;
struct php_msgbuf *messagebuffer = NULL; /* buffer to transmit */
int result;

RETVAL_FALSE;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz/lz/|blz/",
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "riz/iz/|biz/",
&queue, &desiredmsgtype, &out_msgtype, &maxsize,
&out_message, &do_unserialize, &flags, &zerrcode) == FAILURE) {
return;
Expand Down Expand Up @@ -386,7 +386,7 @@ PHP_FUNCTION(msg_receive)
PHP_FUNCTION(msg_send)
{
zval *message, *queue, *zerror=NULL;
long msgtype;
php_int_t msgtype;
zend_bool do_serialize = 1, blocking = 1;
sysvmsg_queue_t * mq = NULL;
struct php_msgbuf * messagebuffer = NULL; /* buffer to transmit */
Expand All @@ -395,7 +395,7 @@ PHP_FUNCTION(msg_send)

RETVAL_FALSE;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz|bbz/",
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "riz|bbz/",
&queue, &msgtype, &message, &do_serialize, &blocking, &zerror) == FAILURE) {
return;
}
Expand Down Expand Up @@ -425,7 +425,7 @@ PHP_FUNCTION(msg_send)
break;

case IS_INT:
message_len = spprintf(&p, 0, "%ld", Z_IVAL_P(message));
message_len = spprintf(&p, 0, "%pd", Z_IVAL_P(message));
break;
case IS_FALSE:
message_len = spprintf(&p, 0, "0");
Expand Down
4 changes: 2 additions & 2 deletions ext/sysvsem/sysvsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ PHP_MINIT_FUNCTION(sysvsem)
Return an id for the semaphore with the given key, and allow max_acquire (default 1) processes to acquire it simultaneously */
PHP_FUNCTION(sem_get)
{
long key, max_acquire = 1, perm = 0666, auto_release = 1;
php_int_t key, max_acquire = 1, perm = 0666, auto_release = 1;
int semid;
struct sembuf sop[3];
int count;
sysvsem_sem *sem_ptr;

if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|lll", &key, &max_acquire, &perm, &auto_release)) {
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i|iii", &key, &max_acquire, &perm, &auto_release)) {
RETURN_FALSE;
}

Expand Down
10 changes: 5 additions & 5 deletions ext/sysvshm/php_sysvshm.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ extern zend_module_entry sysvshm_module_entry;

typedef struct {
int le_shm;
long init_mem;
php_int_t init_mem;
} sysvshm_module;

typedef struct {
long key;
long length;
long next;
php_int_t key;
php_int_t length;
php_int_t next;
char mem;
} sysvshm_chunk;

Expand All @@ -54,7 +54,7 @@ typedef struct {

typedef struct {
key_t key; /* key set by user */
long id; /* returned by shmget */
php_int_t id; /* returned by shmget */
sysvshm_chunk_head *ptr; /* memory address of shared memory */
} sysvshm_shm;

Expand Down
54 changes: 27 additions & 27 deletions ext/sysvshm/sysvshm.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ ZEND_GET_MODULE(sysvshm)

THREAD_LS sysvshm_module php_sysvshm;

static int php_put_shm_data(sysvshm_chunk_head *ptr, long key, const char *data, long len);
static long php_check_shm_data(sysvshm_chunk_head *ptr, long key);
static int php_remove_shm_data(sysvshm_chunk_head *ptr, long shm_varpos);
static int php_put_shm_data(sysvshm_chunk_head *ptr, php_int_t key, const char *data, php_int_t len);
static php_int_t php_check_shm_data(sysvshm_chunk_head *ptr, php_int_t key);
static int php_remove_shm_data(sysvshm_chunk_head *ptr, php_int_t shm_varpos);

/* {{{ php_release_sysvshm
*/
Expand Down Expand Up @@ -150,9 +150,9 @@ PHP_FUNCTION(shm_attach)
sysvshm_shm *shm_list_ptr;
char *shm_ptr;
sysvshm_chunk_head *chunk_ptr;
long shm_key, shm_id, shm_size = php_sysvshm.init_mem, shm_flag = 0666;
php_int_t shm_key, shm_id, shm_size = php_sysvshm.init_mem, shm_flag = 0666;

if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|ll", &shm_key, &shm_size, &shm_flag)) {
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i|ii", &shm_key, &shm_size, &shm_flag)) {
return;
}

Expand All @@ -166,19 +166,19 @@ PHP_FUNCTION(shm_attach)
/* get the id from a specified key or create new shared memory */
if ((shm_id = shmget(shm_key, 0, 0)) < 0) {
if (shm_size < sizeof(sysvshm_chunk_head)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed for key 0x%lx: memorysize too small", shm_key);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed for key 0x%px: memorysize too small", shm_key);
efree(shm_list_ptr);
RETURN_FALSE;
}
if ((shm_id = shmget(shm_key, shm_size, shm_flag | IPC_CREAT | IPC_EXCL)) < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed for key 0x%lx: %s", shm_key, strerror(errno));
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed for key 0x%px: %s", shm_key, strerror(errno));
efree(shm_list_ptr);
RETURN_FALSE;
}
}

if ((shm_ptr = shmat(shm_id, NULL, 0)) == (void *) -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed for key 0x%lx: %s", shm_key, strerror(errno));
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed for key 0x%px: %s", shm_key, strerror(errno));
efree(shm_list_ptr);
RETURN_FALSE;
}
Expand Down Expand Up @@ -243,12 +243,12 @@ PHP_FUNCTION(shm_put_var)
{
zval *shm_id, *arg_var;
int ret;
long shm_key;
php_int_t shm_key;
sysvshm_shm *shm_list_ptr;
smart_str shm_var = {0};
php_serialize_data_t var_hash;

if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &shm_id, &shm_key, &arg_var)) {
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "riz", &shm_id, &shm_key, &arg_var)) {
return;
}

Expand Down Expand Up @@ -282,14 +282,14 @@ PHP_FUNCTION(shm_put_var)
PHP_FUNCTION(shm_get_var)
{
zval *shm_id;
long shm_key;
php_int_t shm_key;
sysvshm_shm *shm_list_ptr;
char *shm_data;
long shm_varpos;
php_int_t shm_varpos;
sysvshm_chunk *shm_var;
php_unserialize_data_t var_hash;

if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &shm_id, &shm_key)) {
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ri", &shm_id, &shm_key)) {
return;
}
SHM_FETCH_RESOURCE(shm_list_ptr, shm_id);
Expand All @@ -299,7 +299,7 @@ PHP_FUNCTION(shm_get_var)
shm_varpos = php_check_shm_data((shm_list_ptr->ptr), shm_key);

if (shm_varpos < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "variable key %ld doesn't exist", shm_key);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "variable key %pd doesn't exist", shm_key);
RETURN_FALSE;
}
shm_var = (sysvshm_chunk*) ((char *)shm_list_ptr->ptr + shm_varpos);
Expand All @@ -319,10 +319,10 @@ PHP_FUNCTION(shm_get_var)
PHP_FUNCTION(shm_has_var)
{
zval *shm_id;
long shm_key;
php_int_t shm_key;
sysvshm_shm *shm_list_ptr;

if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &shm_id, &shm_key)) {
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ri", &shm_id, &shm_key)) {
return;
}
SHM_FETCH_RESOURCE(shm_list_ptr, shm_id);
Expand All @@ -335,18 +335,18 @@ PHP_FUNCTION(shm_has_var)
PHP_FUNCTION(shm_remove_var)
{
zval *shm_id;
long shm_key, shm_varpos;
php_int_t shm_key, shm_varpos;
sysvshm_shm *shm_list_ptr;

if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &shm_id, &shm_key)) {
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ri", &shm_id, &shm_key)) {
return;
}
SHM_FETCH_RESOURCE(shm_list_ptr, shm_id);

shm_varpos = php_check_shm_data((shm_list_ptr->ptr), shm_key);

if (shm_varpos < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "variable key %ld doesn't exist", shm_key);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "variable key %id doesn't exist", shm_key);
RETURN_FALSE;
}
php_remove_shm_data((shm_list_ptr->ptr), shm_varpos);
Expand All @@ -356,13 +356,13 @@ PHP_FUNCTION(shm_remove_var)

/* {{{ php_put_shm_data
* inserts an ascii-string into shared memory */
static int php_put_shm_data(sysvshm_chunk_head *ptr, long key, const char *data, long len)
static int php_put_shm_data(sysvshm_chunk_head *ptr, php_int_t key, const char *data, php_int_t len)
{
sysvshm_chunk *shm_var;
long total_size;
long shm_varpos;
php_int_t total_size;
php_int_t shm_varpos;

total_size = ((long) (len + sizeof(sysvshm_chunk) - 1) / sizeof(long)) * sizeof(long) + sizeof(long); /* long alligment */
total_size = ((php_int_t) (len + sizeof(sysvshm_chunk) - 1) / sizeof(php_int_t)) * sizeof(php_int_t) + sizeof(php_int_t); /* php_int_t alligment */

if ((shm_varpos = php_check_shm_data(ptr, key)) > 0) {
php_remove_shm_data(ptr, shm_varpos);
Expand All @@ -385,9 +385,9 @@ static int php_put_shm_data(sysvshm_chunk_head *ptr, long key, const char *data,

/* {{{ php_check_shm_data
*/
static long php_check_shm_data(sysvshm_chunk_head *ptr, long key)
static php_int_t php_check_shm_data(sysvshm_chunk_head *ptr, php_int_t key)
{
long pos;
php_int_t pos;
sysvshm_chunk *shm_var;

pos = ptr->start;
Expand All @@ -412,10 +412,10 @@ static long php_check_shm_data(sysvshm_chunk_head *ptr, long key)

/* {{{ php_remove_shm_data
*/
static int php_remove_shm_data(sysvshm_chunk_head *ptr, long shm_varpos)
static int php_remove_shm_data(sysvshm_chunk_head *ptr, php_int_t shm_varpos)
{
sysvshm_chunk *chunk_ptr, *next_chunk_ptr;
long memcpy_len;
php_int_t memcpy_len;

chunk_ptr = (sysvshm_chunk *) ((char *) ptr + shm_varpos);
next_chunk_ptr = (sysvshm_chunk *) ((char *) ptr + shm_varpos + chunk_ptr->next);
Expand Down

0 comments on commit 5491d01

Please sign in to comment.