Browse Source

Initial Unicode support

migration/RELEASE_1_0_0
Ilia Alshanetsky 20 years ago
parent
commit
f50a50ebc8
  1. 36
      ext/shmop/shmop.c
  2. 4
      ext/shmop/tests/001.phpt

36
ext/shmop/shmop.c

@ -109,7 +109,7 @@ PHP_MINFO_FUNCTION(shmop)
}
/* }}} */
/* {{{ proto int shmop_open (int key, string flags, int mode, int size)
/* {{{ proto int shmop_open (int key, string flags, int mode, int size) U
gets and attaches a shared memory segment */
PHP_FUNCTION(shmop_open)
{
@ -119,12 +119,24 @@ PHP_FUNCTION(shmop_open)
int rsid;
char *flags;
int flags_len;
zend_uchar flag_type;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsll", &key, &flags, &flags_len, &mode, &size) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ltll", &key, &flags, &flags_len, &flag_type, &mode, &size) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (flag_type == IS_UNICODE) {
flags = zend_unicode_to_ascii((UChar*)flags, flags_len);
if (!flags) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received");
RETURN_FALSE;
}
}
if (flags_len != 1) {
if (flag_type == IS_UNICODE) {
efree(flags);
}
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s is not a valid flag", flags);
RETURN_FALSE;
}
@ -179,14 +191,20 @@ PHP_FUNCTION(shmop_open)
shmop->size = shm.shm_segsz;
rsid = zend_list_insert(shmop, shm_type);
if (flag_type == IS_UNICODE) {
efree(flags);
}
RETURN_LONG(rsid);
err:
if (flag_type == IS_UNICODE) {
efree(flags);
}
efree(shmop);
RETURN_FALSE;
}
/* }}} */
/* {{{ proto string shmop_read (int shmid, int start, int count)
/* {{{ proto string shmop_read (int shmid, int start, int count) U
reads from a shm segment */
PHP_FUNCTION(shmop_read)
{
@ -229,7 +247,7 @@ PHP_FUNCTION(shmop_read)
}
/* }}} */
/* {{{ proto void shmop_close (int shmid)
/* {{{ proto void shmop_close (int shmid) U
closes a shared memory segment */
PHP_FUNCTION(shmop_close)
{
@ -252,7 +270,7 @@ PHP_FUNCTION(shmop_close)
}
/* }}} */
/* {{{ proto int shmop_size (int shmid)
/* {{{ proto int shmop_size (int shmid) U
returns the shm size */
PHP_FUNCTION(shmop_size)
{
@ -275,18 +293,18 @@ PHP_FUNCTION(shmop_size)
}
/* }}} */
/* {{{ proto int shmop_write (int shmid, string data, int offset)
/* {{{ proto int shmop_write (int shmid, string data, int offset) U
writes to a shared memory segment */
PHP_FUNCTION(shmop_write)
{
struct php_shmop *shmop;
int type;
int writesize;
long shmid, offset;
long shmid, offset=0;
char *data;
int data_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsl", &shmid, &data, &data_len, &offset) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lS|l", &shmid, &data, &data_len, &offset) == FAILURE) {
WRONG_PARAM_COUNT;
}
@ -314,7 +332,7 @@ PHP_FUNCTION(shmop_write)
}
/* }}} */
/* {{{ proto bool shmop_delete (int shmid)
/* {{{ proto bool shmop_delete (int shmid) U
mark segment for deletion */
PHP_FUNCTION(shmop_delete)
{

4
ext/shmop/tests/001.phpt

@ -9,8 +9,8 @@ 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";
$write_d1 = b"test #1 of the shmop() extension";
$write_d2 = b"test #2 append data to shared memory segment";
echo "shm open for create: ";
$shm_id = shmop_open($hex_shm_id, "n", 0644, 1024);

Loading…
Cancel
Save