Skip to content

Commit

Permalink
mdb_version
Browse files Browse the repository at this point in the history
  • Loading branch information
Luciano Andrade committed May 26, 2014
1 parent 6f43fa8 commit 6084718
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
1 change: 0 additions & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ if test "$PHP_LMDB" != "no"; then
AC_MSG_RESULT(lmdb lib found in $i/lib)
fi

dnl from Leveldb build dir
if test -r $i/$SEARCH_LIB.a || test -r $i/$SEARCH_LIB.$SHLIB_SUFFIX_NAME; then
LMDB_LIB_DIR=$i
AC_MSG_RESULT(lmdb lib found in $i)
Expand Down
34 changes: 34 additions & 0 deletions lmdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,22 @@
\
return retval;

ZEND_BEGIN_ARG_INFO(void_arg, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(int_arg, 0)
ZEND_ARG_INFO(0, err)
ZEND_END_ARG_INFO()


/* {{{ lmdb_functions[]
*/
const zend_function_entry lmdb_functions[] = {
PHP_FE(mdb_version, void_arg)
// PHP_FE(mdb_strerror, int_arg)
PHP_FE_END /* Must be the last line in lmdb_functions[] */
};

/* }}} */

/* {{{ lmdb_module_entry
Expand All @@ -117,6 +126,31 @@ zend_module_entry lmdb_module_entry = {
ZEND_GET_MODULE(lmdb)
#endif

/* {{{ proto array mdb_version()
Return the mdb library version information. */
PHP_FUNCTION(mdb_version) {

array_init(return_value);


int major;
int minor;
int patch;
char* mdb_version_str = mdb_version(&major, &minor, &patch);
add_assoc_string_ex(return_value, "version", sizeof("version"), mdb_version_str,0);
add_assoc_long(return_value, "major", major);
add_assoc_long(return_value, "minor", minor);
add_assoc_long(return_value, "patch", patch);

RETVAL_ZVAL(return_value,1,0);
}

/* {{{ proto string mdb_strerror(int err)
Return a string describing a given error code. */
PHP_FUNCTION(mdb_strerror) {
RETURN_TRUE;
}

/* Objects */
typedef struct {
zend_object std;
Expand Down
3 changes: 3 additions & 0 deletions php_lmdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ PHP_RINIT_FUNCTION(lmdb);
PHP_RSHUTDOWN_FUNCTION(lmdb);
PHP_MINFO_FUNCTION(lmdb);

PHP_FUNCTION(mdb_version);
PHP_FUNCTION(mdb_strerror);

#ifdef ZTS
#define LDB_G(v) TSRMG(lmdb_globals_id, zend_lmdb_globals *, v)
#else
Expand Down
21 changes: 21 additions & 0 deletions tests/000-test-basic-functions.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
lmdb - info functions
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
$functions = get_defined_functions();
var_dump(in_array("mdb_version", $functions["internal"]));
var_dump(mdb_version());
--EXPECTF--
bool(true)
array(4) {
["version"]=>
string(30) "MDB 0.9.11: (January 15, 2014)"
["major"]=>
int(0)
["minor"]=>
int(9)
["patch"]=>
int(11)
}

0 comments on commit 6084718

Please sign in to comment.