From bd12c94f46438dad03d1d3c02fff37b9b950ae6f Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Thu, 22 Oct 2020 00:12:55 +0000 Subject: [PATCH] Convert pspell resources to objects --- NEWS | 4 + ext/pspell/pspell.c | 305 +++++++++++++++++++++--------------- ext/pspell/pspell.stub.php | 61 +++----- ext/pspell/pspell_arginfo.h | 42 +++-- ext/pspell/tests/003.phpt | 2 +- 5 files changed, 235 insertions(+), 179 deletions(-) diff --git a/NEWS b/NEWS index 63812c76cd..5fc105a2f1 100644 --- a/NEWS +++ b/NEWS @@ -8,4 +8,8 @@ PHP NEWS - GD: . Convert resource to object \GdFont. (Sara) +- PSpell: + . Convert resource to object \PSpell. (Sara) + . Convert resource to object \PSPellConfig. (Sara) + <<< NOTE: Insert NEWS from last stable release here prior to actual release! >>> diff --git a/ext/pspell/pspell.c b/ext/pspell/pspell.c index 63732b77b0..34859076a2 100644 --- a/ext/pspell/pspell.c +++ b/ext/pspell/pspell.c @@ -19,6 +19,7 @@ #endif #include "php.h" +#include "zend_interfaces.h" #include #include @@ -48,58 +49,139 @@ static PHP_MINIT_FUNCTION(pspell); static PHP_MINFO_FUNCTION(pspell); -static int le_pspell, le_pspell_config; +static zend_class_entry *php_pspell_ce = NULL; +static zend_object_handlers php_pspell_handlers; +static zend_class_entry *php_pspell_config_ce = NULL; +static zend_object_handlers php_pspell_config_handlers; zend_module_entry pspell_module_entry = { STANDARD_MODULE_HEADER, - "pspell", ext_functions, PHP_MINIT(pspell), NULL, NULL, NULL, PHP_MINFO(pspell), PHP_PSPELL_VERSION, STANDARD_MODULE_PROPERTIES + "pspell", + ext_functions, + PHP_MINIT(pspell), + NULL, + NULL, + NULL, + PHP_MINFO(pspell), + PHP_PSPELL_VERSION, + STANDARD_MODULE_PROPERTIES, }; #ifdef COMPILE_DL_PSPELL ZEND_GET_MODULE(pspell) #endif -static void php_pspell_close(zend_resource *rsrc) +/* class PSpell */ + +typedef struct _php_pspell_object { + PspellManager *mgr; + zend_object std; +} php_pspell_object; + +static php_pspell_object *php_pspell_object_from_zend_object(zend_object *zobj) { + return ((php_pspell_object*)(zobj + 1)) - 1; +} + +static zend_object *php_pspell_object_to_zend_object(php_pspell_object *obj) { + return ((zend_object*)(obj + 1)) - 1; +} + +static zend_function *php_pspell_object_get_constructor(zend_object *object) { - PspellManager *manager = (PspellManager *)rsrc->ptr; + zend_throw_error(NULL, "You cannot initialize a PSpell object except through helper functions"); + return NULL; +} + +static zend_object *php_pspell_object_create(zend_class_entry *ce) +{ + php_pspell_object *obj = zend_object_alloc(sizeof(php_pspell_object), ce); + zend_object *zobj = php_pspell_object_to_zend_object(obj); + + obj->mgr = NULL; + zend_object_std_init(zobj, ce); + object_properties_init(zobj, ce); + zobj->handlers = &php_pspell_handlers; + + return zobj; +} + +static void php_pspell_object_free(zend_object *zobj) { + delete_pspell_manager(php_pspell_object_from_zend_object(zobj)->mgr); +} - delete_pspell_manager(manager); +/* class PSpellConfig */ + +typedef struct _php_pspell_config_object { + PspellConfig *cfg; + zend_object std; +} php_pspell_config_object; + +static php_pspell_config_object *php_pspell_config_object_from_zend_object(zend_object *zobj) { + return ((php_pspell_config_object*)(zobj + 1)) - 1; } -static void php_pspell_close_config(zend_resource *rsrc) +static zend_object *php_pspell_config_object_to_zend_object(php_pspell_config_object *obj) { + return ((zend_object*)(obj + 1)) - 1; +} + +static zend_function *php_pspell_config_object_get_constructor(zend_object *object) { - PspellConfig *config = (PspellConfig *)rsrc->ptr; + zend_throw_error(NULL, "You cannot initialize a PSpellConfig object except through helper functions"); + return NULL; +} - delete_pspell_config(config); +static zend_object *php_pspell_config_object_create(zend_class_entry *ce) +{ + php_pspell_config_object *obj = zend_object_alloc(sizeof(php_pspell_config_object), ce); + zend_object *zobj = php_pspell_config_object_to_zend_object(obj); + + obj->cfg = NULL; + zend_object_std_init(zobj, ce); + object_properties_init(zobj, ce); + zobj->handlers = &php_pspell_config_handlers; + + return zobj; } -#define PSPELL_FETCH_CONFIG do { \ - zval *res = zend_hash_index_find(&EG(regular_list), conf); \ - if (res == NULL || Z_RES_P(res)->type != le_pspell_config) { \ - zend_throw_error(NULL, "%s(): " ZEND_LONG_FMT " is not a PSPELL config index", get_active_function_name(), conf); \ - RETURN_THROWS(); \ - } \ - config = (PspellConfig *)Z_RES_P(res)->ptr; \ -} while (0) - -#define PSPELL_FETCH_MANAGER do { \ - zval *res = zend_hash_index_find(&EG(regular_list), scin); \ - if (res == NULL || Z_RES_P(res)->type != le_pspell) { \ - zend_throw_error(NULL, "%s(): " ZEND_LONG_FMT " is not a PSPELL result index", get_active_function_name(), scin); \ - RETURN_THROWS(); \ - } \ - manager = (PspellManager *)Z_RES_P(res)->ptr; \ -} while (0); +static void php_pspell_config_object_free(zend_object *zobj) { + delete_pspell_config(php_pspell_config_object_from_zend_object(zobj)->cfg); +} /* {{{ PHP_MINIT_FUNCTION */ static PHP_MINIT_FUNCTION(pspell) { + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "PSpell", class_PSpell_methods); + php_pspell_ce = zend_register_internal_class(&ce); + php_pspell_ce->ce_flags |= ZEND_ACC_FINAL; + php_pspell_ce->create_object = php_pspell_object_create; + php_pspell_ce->serialize = zend_class_serialize_deny; + php_pspell_ce->unserialize = zend_class_unserialize_deny; + + memcpy(&php_pspell_handlers, &std_object_handlers, sizeof(zend_object_handlers)); + php_pspell_handlers.clone_obj = NULL; + php_pspell_handlers.free_obj = php_pspell_object_free; + php_pspell_handlers.get_constructor = php_pspell_object_get_constructor; + php_pspell_handlers.offset = XtOffsetOf(php_pspell_object, std); + + INIT_CLASS_ENTRY(ce, "PSpellConfig", class_PSpellConfig_methods); + php_pspell_config_ce = zend_register_internal_class(&ce); + php_pspell_config_ce->ce_flags |= ZEND_ACC_FINAL; + php_pspell_config_ce->create_object = php_pspell_config_object_create; + php_pspell_config_ce->serialize = zend_class_serialize_deny; + php_pspell_config_ce->unserialize = zend_class_unserialize_deny; + + memcpy(&php_pspell_config_handlers, &std_object_handlers, sizeof(zend_object_handlers)); + php_pspell_config_handlers.clone_obj = NULL; + php_pspell_config_handlers.free_obj = php_pspell_config_object_free; + php_pspell_config_handlers.get_constructor = php_pspell_config_object_get_constructor; + php_pspell_config_handlers.offset = XtOffsetOf(php_pspell_config_object, std); + REGISTER_LONG_CONSTANT("PSPELL_FAST", PSPELL_FAST, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("PSPELL_NORMAL", PSPELL_NORMAL, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("PSPELL_BAD_SPELLERS", PSPELL_BAD_SPELLERS, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("PSPELL_RUN_TOGETHER", PSPELL_RUN_TOGETHER, CONST_PERSISTENT | CONST_CS); - le_pspell = zend_register_list_destructors_ex(php_pspell_close, NULL, "pspell", module_number); - le_pspell_config = zend_register_list_destructors_ex(php_pspell_close_config, NULL, "pspell config", module_number); + return SUCCESS; } /* }}} */ @@ -111,7 +193,6 @@ PHP_FUNCTION(pspell_new) size_t language_len, spelling_len = 0, jargon_len = 0, encoding_len = 0; zend_long mode = Z_L(0), speed = Z_L(0); int argc = ZEND_NUM_ARGS(); - zval *ind; #ifdef PHP_WIN32 TCHAR aspell_dir[200]; @@ -122,7 +203,6 @@ PHP_FUNCTION(pspell_new) #endif PspellCanHaveError *ret; - PspellManager *manager; PspellConfig *config; if (zend_parse_parameters(argc, "s|sssl", &language, &language_len, &spelling, &spelling_len, @@ -194,9 +274,8 @@ PHP_FUNCTION(pspell_new) RETURN_FALSE; } - manager = to_pspell_manager(ret); - ind = zend_list_insert(manager, le_pspell); - RETURN_LONG(Z_RES_HANDLE_P(ind)); + object_init_ex(return_value, php_pspell_ce); + php_pspell_object_from_zend_object(Z_OBJ_P(return_value))->mgr = to_pspell_manager(ret); } /* }}} */ @@ -207,7 +286,6 @@ PHP_FUNCTION(pspell_new_personal) size_t personal_len, language_len, spelling_len = 0, jargon_len = 0, encoding_len = 0; zend_long mode = Z_L(0), speed = Z_L(0); int argc = ZEND_NUM_ARGS(); - zval *ind; #ifdef PHP_WIN32 TCHAR aspell_dir[200]; @@ -218,7 +296,6 @@ PHP_FUNCTION(pspell_new_personal) #endif PspellCanHaveError *ret; - PspellManager *manager; PspellConfig *config; if (zend_parse_parameters(argc, "ps|sssl", &personal, &personal_len, &language, &language_len, @@ -298,26 +375,22 @@ PHP_FUNCTION(pspell_new_personal) RETURN_FALSE; } - manager = to_pspell_manager(ret); - ind = zend_list_insert(manager, le_pspell); - RETURN_LONG(Z_RES_HANDLE_P(ind)); + object_init_ex(return_value, php_pspell_ce); + php_pspell_object_from_zend_object(Z_OBJ_P(return_value))->mgr = to_pspell_manager(ret); } /* }}} */ /* {{{ Load a dictionary based on the given config */ PHP_FUNCTION(pspell_new_config) { - zend_long conf; - zval *ind; + zval *zcfg; PspellCanHaveError *ret; - PspellManager *manager; PspellConfig *config; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &conf) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zcfg, php_pspell_config_ce) == FAILURE) { RETURN_THROWS(); } - - PSPELL_FETCH_CONFIG; + config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg; ret = new_pspell_manager(config); @@ -327,27 +400,24 @@ PHP_FUNCTION(pspell_new_config) RETURN_FALSE; } - manager = to_pspell_manager(ret); - ind = zend_list_insert(manager, le_pspell); - RETURN_LONG(Z_RES_HANDLE_P(ind)); + object_init_ex(return_value, php_pspell_ce); + php_pspell_object_from_zend_object(Z_OBJ_P(return_value))->mgr = to_pspell_manager(ret); } /* }}} */ /* {{{ Returns true if word is valid */ PHP_FUNCTION(pspell_check) { - size_t word_len; - zend_long scin; - char *word; + zval *zmgr; + zend_string *word; PspellManager *manager; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &scin, &word, &word_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &zmgr, php_pspell_ce, &word) == FAILURE) { RETURN_THROWS(); } + manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr; - PSPELL_FETCH_MANAGER; - - if (pspell_manager_check(manager, word)) { + if (pspell_manager_check(manager, ZSTR_VAL(word))) { RETURN_TRUE; } else { RETURN_FALSE; @@ -358,22 +428,20 @@ PHP_FUNCTION(pspell_check) /* {{{ Returns array of suggestions */ PHP_FUNCTION(pspell_suggest) { - zend_long scin; - char *word; - size_t word_len; + zval *zmgr; + zend_string *word; PspellManager *manager; const PspellWordList *wl; const char *sug; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &scin, &word, &word_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &zmgr, php_pspell_ce, &word) == FAILURE) { RETURN_THROWS(); } - - PSPELL_FETCH_MANAGER; + manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr; array_init(return_value); - wl = pspell_manager_suggest(manager, word); + wl = pspell_manager_suggest(manager, ZSTR_VAL(word)); if (wl) { PspellStringEmulation *els = pspell_word_list_elements(wl); while ((sug = pspell_string_emulation_next(els)) != 0) { @@ -390,18 +458,16 @@ PHP_FUNCTION(pspell_suggest) /* {{{ Notify the dictionary of a user-selected replacement */ PHP_FUNCTION(pspell_store_replacement) { - size_t miss_len, corr_len; - zend_long scin; - char *miss, *corr; + zval *zmgr; + zend_string *miss, *corr; PspellManager *manager; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lss", &scin, &miss, &miss_len, &corr, &corr_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSS", &zmgr, php_pspell_ce, &miss, &corr) == FAILURE) { RETURN_THROWS(); } + manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr; - PSPELL_FETCH_MANAGER; - - pspell_manager_store_replacement(manager, miss, corr); + pspell_manager_store_replacement(manager, ZSTR_VAL(miss), ZSTR_VAL(corr)); if (pspell_manager_error_number(manager) == 0) { RETURN_TRUE; } else { @@ -414,23 +480,21 @@ PHP_FUNCTION(pspell_store_replacement) /* {{{ Adds a word to a personal list */ PHP_FUNCTION(pspell_add_to_personal) { - size_t word_len; - zend_long scin; - char *word; + zval *zmgr; + zend_string *word; PspellManager *manager; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &scin, &word, &word_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &zmgr, php_pspell_ce, &word) == FAILURE) { RETURN_THROWS(); } - - PSPELL_FETCH_MANAGER; + manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr; /*If the word is empty, we have to return; otherwise we'll segfault! ouch!*/ - if (word_len == 0) { + if (ZSTR_LEN(word) == 0) { RETURN_FALSE; } - pspell_manager_add_to_personal(manager, word); + pspell_manager_add_to_personal(manager, ZSTR_VAL(word)); if (pspell_manager_error_number(manager) == 0) { RETURN_TRUE; } else { @@ -443,23 +507,21 @@ PHP_FUNCTION(pspell_add_to_personal) /* {{{ Adds a word to the current session */ PHP_FUNCTION(pspell_add_to_session) { - size_t word_len; - zend_long scin; - char *word; + zval *zmgr; + zend_string *word; PspellManager *manager; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &scin, &word, &word_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &zmgr, php_pspell_ce, &word) == FAILURE) { RETURN_THROWS(); } - - PSPELL_FETCH_MANAGER; + manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr; /*If the word is empty, we have to return; otherwise we'll segfault! ouch!*/ - if (word_len == 0) { + if (ZSTR_LEN(word) == 0) { RETURN_FALSE; } - pspell_manager_add_to_session(manager, word); + pspell_manager_add_to_session(manager, ZSTR_VAL(word)); if (pspell_manager_error_number(manager) == 0) { RETURN_TRUE; } else { @@ -472,14 +534,13 @@ PHP_FUNCTION(pspell_add_to_session) /* {{{ Clears the current session */ PHP_FUNCTION(pspell_clear_session) { - zend_long scin; + zval *zmgr; PspellManager *manager; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &scin) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zmgr, php_pspell_ce) == FAILURE) { RETURN_THROWS(); } - - PSPELL_FETCH_MANAGER; + manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr; pspell_manager_clear_session(manager); if (pspell_manager_error_number(manager) == 0) { @@ -494,14 +555,13 @@ PHP_FUNCTION(pspell_clear_session) /* {{{ Saves the current (personal) wordlist */ PHP_FUNCTION(pspell_save_wordlist) { - zend_long scin; + zval *zmgr; PspellManager *manager; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &scin) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zmgr, php_pspell_ce) == FAILURE) { RETURN_THROWS(); } - - PSPELL_FETCH_MANAGER; + manager = php_pspell_object_from_zend_object(Z_OBJ_P(zmgr))->mgr; pspell_manager_save_all_word_lists(manager); @@ -520,7 +580,6 @@ PHP_FUNCTION(pspell_config_create) { char *language, *spelling = NULL, *jargon = NULL, *encoding = NULL; size_t language_len, spelling_len = 0, jargon_len = 0, encoding_len = 0; - zval *ind; PspellConfig *config; #ifdef PHP_WIN32 @@ -577,23 +636,22 @@ PHP_FUNCTION(pspell_config_create) which is not what we want */ pspell_config_replace(config, "save-repl", "false"); - ind = zend_list_insert(config, le_pspell_config); - RETURN_LONG(Z_RES_HANDLE_P(ind)); + object_init_ex(return_value, php_pspell_config_ce); + php_pspell_config_object_from_zend_object(Z_OBJ_P(return_value))->cfg = config; } /* }}} */ /* {{{ Consider run-together words as valid components */ PHP_FUNCTION(pspell_config_runtogether) { - zend_long conf; + zval *zcfg; zend_bool runtogether; PspellConfig *config; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &conf, &runtogether) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ob", &zcfg, php_pspell_config_ce, &runtogether) == FAILURE) { RETURN_THROWS(); } - - PSPELL_FETCH_CONFIG; + config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg; pspell_config_replace(config, "run-together", runtogether ? "true" : "false"); @@ -604,14 +662,14 @@ PHP_FUNCTION(pspell_config_runtogether) /* {{{ Select mode for config (PSPELL_FAST, PSPELL_NORMAL or PSPELL_BAD_SPELLERS) */ PHP_FUNCTION(pspell_config_mode) { - zend_long conf, mode; + zval *zcfg; + zend_long mode; PspellConfig *config; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &conf, &mode) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &zcfg, php_pspell_config_ce, &mode) == FAILURE) { RETURN_THROWS(); } - - PSPELL_FETCH_CONFIG; + config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg; /* First check what mode we want (how many suggestions) */ if (mode == PSPELL_FAST) { @@ -630,14 +688,14 @@ PHP_FUNCTION(pspell_config_mode) PHP_FUNCTION(pspell_config_ignore) { char ignore_str[MAX_LENGTH_OF_LONG + 1]; - zend_long conf, ignore = 0L; + zval *zcfg; + zend_long ignore = 0L; PspellConfig *config; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &conf, &ignore) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &zcfg, php_pspell_config_ce, &ignore) == FAILURE) { RETURN_THROWS(); } - - PSPELL_FETCH_CONFIG; + config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg; snprintf(ignore_str, sizeof(ignore_str), ZEND_LONG_FMT, ignore); @@ -648,22 +706,20 @@ PHP_FUNCTION(pspell_config_ignore) static void pspell_config_path(INTERNAL_FUNCTION_PARAMETERS, char *option) { - zend_long conf; - char *value; - size_t value_len; + zval *zcfg; + zend_string *value; PspellConfig *config; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lp", &conf, &value, &value_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OP", &zcfg, php_pspell_config_ce, &value) == FAILURE) { RETURN_THROWS(); } + config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg; - PSPELL_FETCH_CONFIG; - - if (php_check_open_basedir(value)) { + if (php_check_open_basedir(ZSTR_VAL(value))) { RETURN_FALSE; } - pspell_config_replace(config, option, value); + pspell_config_replace(config, option, ZSTR_VAL(value)); RETURN_TRUE; } @@ -692,24 +748,22 @@ PHP_FUNCTION(pspell_config_data_dir) /* {{{ Use a personal dictionary with replacement pairs for this config */ PHP_FUNCTION(pspell_config_repl) { - zend_long conf; - char *repl; - size_t repl_len; + zval *zcfg; + zend_string *repl; PspellConfig *config; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lp", &conf, &repl, &repl_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OP", &zcfg, php_pspell_config_ce, &repl) == FAILURE) { RETURN_THROWS(); } - - PSPELL_FETCH_CONFIG; + config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg; pspell_config_replace(config, "save-repl", "true"); - if (php_check_open_basedir(repl)) { + if (php_check_open_basedir(ZSTR_VAL(repl))) { RETURN_FALSE; } - pspell_config_replace(config, "repl", repl); + pspell_config_replace(config, "repl", ZSTR_VAL(repl)); RETURN_TRUE; } @@ -718,15 +772,14 @@ PHP_FUNCTION(pspell_config_repl) /* {{{ Save replacement pairs when personal list is saved for this config */ PHP_FUNCTION(pspell_config_save_repl) { - zend_long conf; + zval *zcfg; zend_bool save; PspellConfig *config; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &conf, &save) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ob", &zcfg, php_pspell_config_ce, &save) == FAILURE) { RETURN_THROWS(); } - - PSPELL_FETCH_CONFIG; + config = php_pspell_config_object_from_zend_object(Z_OBJ_P(zcfg))->cfg; pspell_config_replace(config, "save-repl", save ? "true" : "false"); diff --git a/ext/pspell/pspell.stub.php b/ext/pspell/pspell.stub.php index 241e510471..606052c21e 100644 --- a/ext/pspell/pspell.stub.php +++ b/ext/pspell/pspell.stub.php @@ -2,7 +2,10 @@ /** @generate-function-entries */ -function pspell_new(string $language, string $spelling = "", string $jargon = "", string $encoding = "", int $mode = 0): int|false {} +final class PSpell {} +final class PSpellConfig {} + +function pspell_new(string $language, string $spelling = "", string $jargon = "", string $encoding = "", int $mode = 0): PSpell|false {} function pspell_new_personal( string $filename, @@ -11,38 +14,24 @@ function pspell_new_personal( string $jargon = "", string $encoding = "", int $mode = 0 -): int|false {} - -function pspell_new_config(int $config): int|false {} - -function pspell_check(int $dictionary, string $word): bool {} - -function pspell_suggest(int $dictionary, string $word): array|false {} - -function pspell_store_replacement(int $dictionary, string $misspelled, string $correct): bool {} - -function pspell_add_to_personal(int $dictionary, string $word): bool {} - -function pspell_add_to_session(int $dictionary, string $word): bool {} - -function pspell_clear_session(int $dictionary): bool {} - -function pspell_save_wordlist(int $dictionary): bool {} - -function pspell_config_create(string $language, string $spelling = "", string $jargon = "", string $encoding = ""): int {} - -function pspell_config_runtogether(int $config, bool $allow): bool {} - -function pspell_config_mode(int $config, int $mode): bool {} - -function pspell_config_ignore(int $config, int $min_length): bool {} - -function pspell_config_personal(int $config, string $filename): bool {} - -function pspell_config_dict_dir(int $config, string $directory): bool {} - -function pspell_config_data_dir(int $config, string $directory): bool {} - -function pspell_config_repl(int $config, string $filename): bool {} - -function pspell_config_save_repl(int $dictionary, bool $save): bool {} +): PSpell|false {} + +function pspell_new_config(PSpellConfig $config): PSpell|false {} + +function pspell_check(PSpell $dictionary, string $word): bool {} +function pspell_suggest(PSpell $dictionary, string $word): array|false {} +function pspell_store_replacement(PSpell $dictionary, string $misspelled, string $correct): bool {} +function pspell_add_to_personal(PSpell $dictionary, string $word): bool {} +function pspell_add_to_session(PSpell $dictionary, string $word): bool {} +function pspell_clear_session(PSpell $dictionary): bool {} +function pspell_save_wordlist(PSpell $dictionary): bool {} + +function pspell_config_create(string $language, string $spelling = "", string $jargon = "", string $encoding = ""): PSpellConfig {} +function pspell_config_runtogether(PSpellConfig $config, bool $allow): bool {} +function pspell_config_mode(PSpellConfig $config, int $mode): bool {} +function pspell_config_ignore(PSpellConfig $config, int $min_length): bool {} +function pspell_config_personal(PSpellConfig $config, string $filename): bool {} +function pspell_config_dict_dir(PSpellConfig $config, string $directory): bool {} +function pspell_config_data_dir(PSpellConfig $config, string $directory): bool {} +function pspell_config_repl(PSpellConfig $config, string $filename): bool {} +function pspell_config_save_repl(PSpellConfig $dictionary, bool $save): bool {} diff --git a/ext/pspell/pspell_arginfo.h b/ext/pspell/pspell_arginfo.h index 93fd069e9e..a73b27a734 100644 --- a/ext/pspell/pspell_arginfo.h +++ b/ext/pspell/pspell_arginfo.h @@ -1,7 +1,7 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 9a6f7791175f73d92c3b92da45f282805ea09a1c */ + * Stub hash: c5195a21d76b23878f26d592ee75bea68941ce51 */ -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pspell_new, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new, 0, 1, PSpell, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, language, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, spelling, IS_STRING, 0, "\"\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, jargon, IS_STRING, 0, "\"\"") @@ -9,7 +9,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pspell_new, 0, 1, MAY_BE_LONG|MA ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "0") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pspell_new_personal, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new_personal, 0, 2, PSpell, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, language, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, spelling, IS_STRING, 0, "\"\"") @@ -18,22 +18,22 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pspell_new_personal, 0, 2, MAY_B ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "0") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pspell_new_config, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) - ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pspell_new_config, 0, 1, PSpell, MAY_BE_FALSE) + ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_check, 0, 2, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO(0, dictionary, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, dictionary, PSpell, 0) ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pspell_suggest, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_TYPE_INFO(0, dictionary, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, dictionary, PSpell, 0) ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_store_replacement, 0, 3, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO(0, dictionary, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, dictionary, PSpell, 0) ZEND_ARG_TYPE_INFO(0, misspelled, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, correct, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -43,12 +43,12 @@ ZEND_END_ARG_INFO() #define arginfo_pspell_add_to_session arginfo_pspell_check ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_clear_session, 0, 1, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO(0, dictionary, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, dictionary, PSpell, 0) ZEND_END_ARG_INFO() #define arginfo_pspell_save_wordlist arginfo_pspell_clear_session -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_create, 0, 1, IS_LONG, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_pspell_config_create, 0, 1, PSpellConfig, 0) ZEND_ARG_TYPE_INFO(0, language, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, spelling, IS_STRING, 0, "\"\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, jargon, IS_STRING, 0, "\"\"") @@ -56,27 +56,27 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_create, 0, 1, IS_L ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_runtogether, 0, 2, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0) ZEND_ARG_TYPE_INFO(0, allow, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_mode, 0, 2, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0) ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_ignore, 0, 2, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0) ZEND_ARG_TYPE_INFO(0, min_length, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_personal, 0, 2, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_dict_dir, 0, 2, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO(0, config, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, config, PSpellConfig, 0) ZEND_ARG_TYPE_INFO(0, directory, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -85,7 +85,7 @@ ZEND_END_ARG_INFO() #define arginfo_pspell_config_repl arginfo_pspell_config_personal ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pspell_config_save_repl, 0, 2, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO(0, dictionary, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, dictionary, PSpellConfig, 0) ZEND_ARG_TYPE_INFO(0, save, _IS_BOOL, 0) ZEND_END_ARG_INFO() @@ -133,3 +133,13 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(pspell_config_save_repl, arginfo_pspell_config_save_repl) ZEND_FE_END }; + + +static const zend_function_entry class_PSpell_methods[] = { + ZEND_FE_END +}; + + +static const zend_function_entry class_PSpellConfig_methods[] = { + ZEND_FE_END +}; diff --git a/ext/pspell/tests/003.phpt b/ext/pspell/tests/003.phpt index e8677ae826..63291a8d42 100644 --- a/ext/pspell/tests/003.phpt +++ b/ext/pspell/tests/003.phpt @@ -34,7 +34,7 @@ var_dump(pspell_config_ignore($cfg, PHP_INT_MAX)); bool(false) Warning: pspell_new_config(): PSPELL couldn't open the dictionary. reason: The encoding "b0rked" is not known. This could also mean that the file "%sb0rked.%s" could not be opened for reading or does not exist. in %s003.php on line 9 -pspell_check(): 0 is not a PSPELL result index +pspell_check(): Argument #1 ($dictionary) must be of type PSpell, bool given --- bool(true) bool(true) -- 2.50.1