Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
Merge remote branch 'tricky/master'
Browse files Browse the repository at this point in the history
* tricky/master:
  Remove unnecessary etrsndup.
  Better test.
  • Loading branch information
phadej committed Aug 23, 2010
2 parents 7fa4f23 + 8f41c07 commit df02311
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 48 deletions.
29 changes: 16 additions & 13 deletions igbinary.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ struct igbinary_unserialize_data {
size_t references_count; /**< Unserialized array/objects count. */
size_t references_capacity; /**< Unserialized array/object array capacity. */

int error; /**< Error number. Not used. */
int error; /**< Error number. Not used. */
smart_str string0_buf; /**< Temporary buffer for strings */
};
/* }}} */
/* {{{ Serializing functions prototypes */
Expand Down Expand Up @@ -1145,13 +1146,16 @@ static int igbinary_serialize_zval(struct igbinary_serialize_data *igsd, zval *z
/* {{{ igbinary_unserialize_data_init */
/** Inits igbinary_unserialize_data_init. */
inline static int igbinary_unserialize_data_init(struct igbinary_unserialize_data *igsd TSRMLS_DC) {
smart_str empty_str = { 0 };

igsd->buffer = NULL;
igsd->buffer_size = 0;
igsd->buffer_offset = 0;

igsd->strings = NULL;
igsd->strings_count = 0;
igsd->strings_capacity = 4;
igsd->string0_buf = empty_str;

igsd->error = 0;
igsd->references = NULL;
Expand All @@ -1175,14 +1179,6 @@ inline static int igbinary_unserialize_data_init(struct igbinary_unserialize_dat
/* {{{ igbinary_unserialize_data_deinit */
/** Deinits igbinary_unserialize_data_init. */
inline static void igbinary_unserialize_data_deinit(struct igbinary_unserialize_data *igsd TSRMLS_DC) {
size_t i;

for (i = 0; i < igsd->strings_count; i++) {
if (igsd->strings[i].data != NULL) {
efree(igsd->strings[i].data);
}
}

if (igsd->strings) {
efree(igsd->strings);
}
Expand All @@ -1191,6 +1187,8 @@ inline static void igbinary_unserialize_data_deinit(struct igbinary_unserialize_
efree(igsd->references);
}

smart_str_free(&igsd->string0_buf);

return;
}
/* }}} */
Expand Down Expand Up @@ -1436,7 +1434,7 @@ inline static int igbinary_unserialize_chararray(struct igbinary_unserialize_dat
}
}

igsd->strings[igsd->strings_count].data = estrndup((char *) (igsd->buffer + igsd->buffer_offset), l);
igsd->strings[igsd->strings_count].data = (char *) (igsd->buffer + igsd->buffer_offset);
igsd->strings[igsd->strings_count].len = l;

igsd->buffer_offset += l;
Expand Down Expand Up @@ -1565,8 +1563,8 @@ inline static int igbinary_unserialize_array(struct igbinary_unserialize_data *i
case igbinary_type_string16:
case igbinary_type_string32:
if (igbinary_unserialize_chararray(igsd, key_type, &key, &key_len TSRMLS_CC)) {
zval_dtor(*z);
ZVAL_NULL(*z);
zval_dtor(*z);
ZVAL_NULL(*z);
return 1;
}
break;
Expand All @@ -1593,12 +1591,17 @@ inline static int igbinary_unserialize_array(struct igbinary_unserialize_data *i
}

if (key) {
/* Keys must include a terminating null. */
/* Ensure buffer starts at the beginning. */
igsd->string0_buf.len = 0;
smart_str_appendl(&igsd->string0_buf, key, key_len);
smart_str_0(&igsd->string0_buf);
/*
if (zend_symtable_find(h, key, key_len + 1, (void **)&old_v) == SUCCESS) {
var_push_dtor(var_hash, old_v);
}
*/
zend_symtable_update(h, key, key_len + 1, &v, sizeof(v), NULL);
zend_symtable_update(h, igsd->string0_buf.c, igsd->string0_buf.len + 1, &v, sizeof(v), NULL);
} else {
/*
if (zend_hash_index_find(h, key_index, (void **)&old_v) == SUCCESS) {
Expand Down
38 changes: 3 additions & 35 deletions tests/023.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
Resource
--SKIPIF--
<?php
if (!extension_loaded("igbinary")) print "skip\n";
if (!function_exists('curl_init')
&& !function_exists('sqlite_open')) print "skip\n";
?>
if (!extension_loaded("igbinary")) print "skip extenion not loaded\n";
--FILE--
<?php
if(!extension_loaded('igbinary')) {
dl('igbinary.' . PHP_SHLIB_SUFFIX);
}

function test($type, $variable, $test) {
$serialized = igbinary_serialize($variable);
Expand All @@ -22,38 +16,12 @@ function test($type, $variable, $test) {
echo "\n";
}

if (function_exists('curl_init')) {
$test = 'curl';
$res = curl_init('http:https://opensource.dynamoid.com');
} else if (function_exists('sqlite_open')) {
$test = 'sqlite';
$res = sqlite_open('db.txt');
}
$res = tmpfile();

test('resource', $res, false);

switch ($test) {
case 'curl':
curl_close($res);
break;
case 'sqlite':
sqlite_close($res);
@unlink('db.txt');
break;
}
fclose($res);

/*
* you can add regression tests for your extension here
*
* the output of your test code has to be equal to the
* text in the --EXPECT-- section below for the tests
* to pass, differences between the output and the
* expected text are interpreted as failure
*
* see php5/README.TESTING for further information on
* writing regression tests
*/
?>
--EXPECT--
resource
00
Expand Down

0 comments on commit df02311

Please sign in to comment.