reeze/php-leveldb

LevelDBIterator->key and value fails on OS X

Closed this issue · 10 comments

hwde commented

I noticed the following tests fails with leveldb-1.12.0:

FAIL leveldb - iterate thought db [tests/005-iterator.phpt]
FAIL leveldb - different iterators should not affect each other [tests/016-different-iterators-should-differ.phpt]
FAIL leveldb - LevelDB::getIterator() [tests/017-db-getIterator.phpt]

Digging into the source I noticed that int and size_t seems to be different on my Intel Mac running latest OS X, so here is a small patch, which allow to PASS all tests here (not sure how it will looks like here without a preview option)

Best
Heiko

diff --git a/leveldb.c b/leveldb.c
index bd64e56e08bd85e2dc45fbcc679aa5ead927a1f6..8e88544b70283b7594d7114a207778a08a8ba86d 100644
--- a/leveldb.c
+++ b/leveldb.c
@@ -1354,7 +1354,7 @@ PHP_METHOD(LevelDBIterator, getError)
PHP_METHOD(LevelDBIterator, current)
{
char *value = NULL;

  • int value_len;
  • size_t value_len;
    leveldb_iterator_object *intern;

if (zend_parse_parameters_none() == FAILURE) {
@@ -1365,11 +1365,11 @@ PHP_METHOD(LevelDBIterator, current)
LEVELDB_CHECK_ITER_DB_NOT_CLOSED(intern);

if (!leveldb_iter_valid(intern->iterator) ||

  •       !(value = (char *)leveldb_iter_value(intern->iterator, (size_t *)&value_len))) {
    
  •       !(value = (char *)leveldb_iter_value(intern->iterator, &value_len))) {
    RETURN_FALSE;
    

    }

  • RETURN_STRINGL(value, value_len, 1);

  • RETURN_STRINGL(value, value_len, 1);
    }
    /* }}} */

@@ -1378,7 +1378,7 @@ PHP_METHOD(LevelDBIterator, current)
PHP_METHOD(LevelDBIterator, key)
{
char *key = NULL;

  • int key_len;
  • size_t key_len;
    leveldb_iterator_object *intern;

if (zend_parse_parameters_none() == FAILURE) {
@@ -1389,7 +1389,7 @@ PHP_METHOD(LevelDBIterator, key)
LEVELDB_CHECK_ITER_DB_NOT_CLOSED(intern);

if (!leveldb_iter_valid(intern->iterator) ||

  •       !(key = (char *)leveldb_iter_key(intern->iterator, (size_t *)&key_len))) {
    
  •       !(key = (char *)leveldb_iter_key(intern->iterator, &key_len))) {
    RETURN_FALSE;
    
    }
hwde commented

Uhm, looking into the code, I see a few other int / (site_t*) usages, so you might need fix them too.

Best
Heiko

@hwde Thanks very much for you patch, I will look into them this weekend :)

hwde commented

Cool, thanks.

Am 19.07.2013 um 15:20 schrieb Reeze Xia notifications@github.com:

@hwde Thanks very much for you patch, I will look into them this weekend :)


Reply to this email directly or view it on GitHub.

hwde commented

I've added another test, maybe you'll find it useful.

Am 19.07.2013 um 16:05 schrieb Heiko Weber heiko@wecos.de:

Cool, thanks.

Am 19.07.2013 um 15:20 schrieb Reeze Xia notifications@github.com:

@hwde Thanks very much for you patch, I will look into them this weekend :)


Reply to this email directly or view it on GitHub.

Hi Heiko,
where is the test? and what do you mean by latest OSX version ? I'm using 10.8.4 and the tests passed. could you provide more info ? eg:

$ uname
$ php -i 
hwde commented

Hi,

$ uname -a
Darwin Heikos-MacBook-Pro.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64

$ php -i
phpinfo()
PHP Version => 5.3.27

Installed via the ports collection.

Here is a small test C program, do demonstrate the difference:

#include <stdio.h>
#include <stdlib.h>

int main() {
printf("%ld %ld\n", sizeof(int), sizeof(size_t));
return 0;
}

If I compile this on my Mac book pro I get:

$ gcc test.c

$ ./a.out
4 8

Cheers
Heiko

Am 20.07.2013 um 14:47 schrieb Reeze Xia notifications@github.com:

Hi Heiko,
where is the test? and what do you mean by latest OSX version ? I'm using 10.8.4 and the tests passed. could you provide more info ? eg:

$ uname
$ php -i

Reply to this email directly or view it on GitHub.

Any news on this?

I get a segfault under the same $k => $v circumstances

  • FreeBSD defcon.ipviking.com 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 3 07:46:30 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
  • php 5.4.7
hwde commented

This error shows up only if the sizeof(int) != 4

I can upload a patch which make it working for me.

@hwde Thanks a lot, it has been fixed in master

hwde commented

Hi Reeze, thanks. This issue is fixed, all tests passed.