reeze / php-leveldb

The PHP Binding for LevelDB
Other
240 stars 44 forks source link

LevelDBIterator->key and value fails on OS X #7

Closed hwde closed 11 years ago

hwde commented 11 years ago

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;

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

hwde commented 11 years ago

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

Best Heiko

reeze commented 11 years ago

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

hwde commented 11 years ago

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 11 years ago

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.

reeze commented 11 years ago

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 11 years ago

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

include

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.

chichicuervo commented 11 years ago

Any news on this?

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

hwde commented 11 years ago

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

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

reeze commented 11 years ago

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

hwde commented 11 years ago

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