Switch the extension to use Fast Parameter Parsing API
This commit is contained in:
@@ -73,10 +73,14 @@ PHP_METHOD(WrenchBoard, wrenchboard_api)
|
||||
wrenchboard_object *intern;
|
||||
CVars input, output;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", ¶m, ¶m_out) == FAILURE) {
|
||||
/* if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", ¶m, ¶m_out) == FAILURE) {
|
||||
// Bad parameters
|
||||
RETURN_NULL();
|
||||
}
|
||||
} */
|
||||
ZEND_PARSE_PARAMETERS_START(2, 2)
|
||||
Z_PARAM_ARRAY_EX(param, 0, 1)
|
||||
Z_PARAM_ARRAY_EX(param_out, 0, 1)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
intern = Z_TSTOBJ_P(id);
|
||||
if(intern != NULL) {
|
||||
@@ -121,7 +125,7 @@ PHP_METHOD(WrenchBoard, wrenchboard_api)
|
||||
char out_key[out_value_size], out_value[out_value_size];
|
||||
|
||||
if (!output.empty()) {
|
||||
array_init(param_out);
|
||||
// array_init(param_out); // deferences variable & nothing comes out :(
|
||||
// for ( i=output.begin(); i != output.end() && j<out_size ; i++ ) {
|
||||
while (!output.empty()) {
|
||||
bzero(out_key, out_value_size);
|
||||
@@ -130,12 +134,20 @@ PHP_METHOD(WrenchBoard, wrenchboard_api)
|
||||
logfmt( logINFO, "RET: %s=%s", i->first.c_str(), i->second.c_str() );
|
||||
strsafecpy( out_key, i->first.c_str(), out_value_size );
|
||||
strsafecpy( out_value, i->second.c_str(), out_value_size );
|
||||
//add_assoc_string( param_out, out_key, out_value);
|
||||
add_assoc_string_ex( param_out, out_key, strlen(out_key), out_value);
|
||||
if (strlen(out_key)>0) {
|
||||
/*
|
||||
char *str;
|
||||
str = estrdup(i->second.c_str());
|
||||
add_assoc_string( param_out, out_key, str, 0);
|
||||
*/
|
||||
//add_assoc_string( param_out, out_key, out_value);
|
||||
add_assoc_string_ex( param_out, out_key, strlen(out_key), out_value);
|
||||
}
|
||||
//SAFE_STRING
|
||||
//efree(out_value);
|
||||
output.erase(output.begin());
|
||||
}
|
||||
//RETURN_ZVAL(param_out, 0, 0); // Possible workaround to return array
|
||||
}
|
||||
logfmt( logDEBUG, "About to return %ld", retval );
|
||||
RETURN_LONG(retval);
|
||||
@@ -214,13 +226,41 @@ PHP_METHOD(WrenchBoard, logMessage)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ // ------------------------------------------------------------------
|
||||
|
||||
// https://www.phpinternalsbook.com/php7/extensions_design/php_functions.html
|
||||
// https://github.com/php/php-src/blob/master/Zend/zend_builtin_functions_arginfo.h
|
||||
|
||||
// ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args)
|
||||
// ZEND_ARG_INFO(pass_by_ref, name)
|
||||
// ZEND_ARG_OBJ_INFO(pass_by_ref, name, classname, allow_null)
|
||||
// ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null)
|
||||
// ZEND_ARG_CALLABLE_INFO(pass_by_ref, name, allow_null)
|
||||
// ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null)
|
||||
// ZEND_ARG_VARIADIC_INFO(pass_by_ref, name)
|
||||
// ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_string, 0, 0, 1)
|
||||
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_api, 0, 0, 2)
|
||||
//ZEND_ARG_TYPE_INFO(1, in, IS_ARRAY, 0)
|
||||
//ZEND_ARG_TYPE_INFO(1, out, IS_ARRAY, 0)
|
||||
ZEND_ARG_ARRAY_INFO(1, in, 0)
|
||||
ZEND_ARG_ARRAY_INFO(1, out, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
// ------------------------------------------------------------------ // ------------------------------------------------------------------
|
||||
const zend_function_entry wrenchboard_methods[] = {
|
||||
PHP_ME(WrenchBoard, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
|
||||
PHP_ME(WrenchBoard, wrenchboard_api, NULL, ZEND_ACC_PUBLIC)
|
||||
PHP_ME(WrenchBoard, cfgReadChar, NULL, ZEND_ACC_PUBLIC)
|
||||
PHP_ME(WrenchBoard, cfgReadLong, NULL, ZEND_ACC_PUBLIC)
|
||||
PHP_ME(WrenchBoard, logMessage, NULL, ZEND_ACC_PUBLIC)
|
||||
PHP_ME(WrenchBoard, __construct, arginfo_void, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
|
||||
PHP_ME(WrenchBoard, wrenchboard_api, arginfo_api, ZEND_ACC_PUBLIC)
|
||||
PHP_ME(WrenchBoard, cfgReadChar, arginfo_string, ZEND_ACC_PUBLIC)
|
||||
PHP_ME(WrenchBoard, cfgReadLong, arginfo_string, ZEND_ACC_PUBLIC)
|
||||
PHP_ME(WrenchBoard, logMessage, arginfo_string, ZEND_ACC_PUBLIC)
|
||||
PHP_FE_END
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user