Skip to content

Commit 66d42e9

Browse files
committed
remove deprecated call and deprecate function to be removed in libenchant v2
add LIBENCHANT_VERSION constant
1 parent 8ddaf13 commit 66d42e9

11 files changed

+74
-31
lines changed

ext/enchant/config.m4

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PHP_ARG_WITH([enchant],
44
[Include Enchant support])])
55

66
if test "$PHP_ENCHANT" != "no"; then
7-
PKG_CHECK_MODULES([ENCHANT], [enchant])
7+
PKG_CHECK_MODULES([ENCHANT], [enchant >= 1.4.2])
88

99
PHP_EVAL_INCLINE($ENCHANT_CFLAGS)
1010
PHP_EVAL_LIBLINE($ENCHANT_LIBS, ENCHANT_SHARED_LIBADD)
@@ -13,14 +13,14 @@ if test "$PHP_ENCHANT" != "no"; then
1313

1414
PHP_CHECK_LIBRARY(enchant, enchant_get_version,
1515
[
16-
AC_DEFINE(HAVE_ENCHANT_GET_VERSION, 1, [ ])
16+
AC_DEFINE(HAVE_ENCHANT_GET_VERSION, 1, [ enchant_get_version since 1.6.0 ])
1717
], [ ], [
1818
$ENCHANT_LIBS
1919
])
2020

2121
PHP_CHECK_LIBRARY(enchant, enchant_broker_set_param,
2222
[
23-
AC_DEFINE(HAVE_ENCHANT_BROKER_SET_PARAM, 1, [ ])
23+
AC_DEFINE(HAVE_ENCHANT_BROKER_SET_PARAM, 1, [ enchant_broker_set_param since 1.5.0 and removed in 2.x ])
2424
], [ ], [
2525
$ENCHANT_LIBS
2626
])

ext/enchant/enchant.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ PHP_MINIT_FUNCTION(enchant)
197197
le_enchant_dict = zend_register_list_destructors_ex(php_enchant_dict_free, NULL, "enchant_dict", module_number);
198198
REGISTER_LONG_CONSTANT("ENCHANT_MYSPELL", PHP_ENCHANT_MYSPELL, CONST_CS | CONST_PERSISTENT);
199199
REGISTER_LONG_CONSTANT("ENCHANT_ISPELL", PHP_ENCHANT_ISPELL, CONST_CS | CONST_PERSISTENT);
200+
#ifdef HAVE_ENCHANT_GET_VERSION
201+
REGISTER_STRING_CONSTANT("LIBENCHANT_VERSION", enchant_get_version(), CONST_CS | CONST_PERSISTENT);
202+
#endif
200203
return SUCCESS;
201204
}
202205
/* }}} */
@@ -304,7 +307,7 @@ PHP_FUNCTION(enchant_broker_get_error)
304307
{
305308
zval *broker;
306309
enchant_broker *pbroker;
307-
char *msg;
310+
const char *msg;
308311

309312
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &broker) == FAILURE) {
310313
RETURN_THROWS();
@@ -650,7 +653,7 @@ PHP_FUNCTION(enchant_dict_quick_check)
650653
for (i = 0; i < n_sugg; i++) {
651654
add_next_index_string(sugg, suggs[i]);
652655
}
653-
enchant_dict_free_suggestions(pdict->pdict, suggs);
656+
enchant_dict_free_string_list(pdict->pdict, suggs);
654657
}
655658

656659

@@ -705,14 +708,14 @@ PHP_FUNCTION(enchant_dict_suggest)
705708
add_next_index_string(return_value, suggs[i]);
706709
}
707710

708-
enchant_dict_free_suggestions(pdict->pdict, suggs);
711+
enchant_dict_free_string_list(pdict->pdict, suggs);
709712
}
710713
}
711714
/* }}} */
712715

713-
/* {{{ proto void enchant_dict_add_to_personal(resource dict, string word)
716+
/* {{{ proto void enchant_dict_add(resource dict, string word)
714717
add 'word' to personal word list */
715-
PHP_FUNCTION(enchant_dict_add_to_personal)
718+
PHP_FUNCTION(enchant_dict_add)
716719
{
717720
zval *dict;
718721
char *word;
@@ -725,7 +728,7 @@ PHP_FUNCTION(enchant_dict_add_to_personal)
725728

726729
PHP_ENCHANT_GET_DICT;
727730

728-
enchant_dict_add_to_personal(pdict->pdict, word, wordlen);
731+
enchant_dict_add(pdict->pdict, word, wordlen);
729732
}
730733
/* }}} */
731734

@@ -748,9 +751,9 @@ PHP_FUNCTION(enchant_dict_add_to_session)
748751
}
749752
/* }}} */
750753

751-
/* {{{ proto bool enchant_dict_is_in_session(resource dict, string word)
754+
/* {{{ proto bool enchant_dict_is_added(resource dict, string word)
752755
whether or not 'word' exists in this spelling-session */
753-
PHP_FUNCTION(enchant_dict_is_in_session)
756+
PHP_FUNCTION(enchant_dict_is_added)
754757
{
755758
zval *dict;
756759
char *word;
@@ -763,7 +766,7 @@ PHP_FUNCTION(enchant_dict_is_in_session)
763766

764767
PHP_ENCHANT_GET_DICT;
765768

766-
RETURN_BOOL(enchant_dict_is_in_session(pdict->pdict, word, wordlen));
769+
RETURN_BOOL(enchant_dict_is_added(pdict->pdict, word, wordlen));
767770
}
768771
/* }}} */
769772

@@ -796,7 +799,7 @@ PHP_FUNCTION(enchant_dict_get_error)
796799
{
797800
zval *dict;
798801
enchant_dict *pdict;
799-
char *msg;
802+
const char *msg;
800803

801804
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &dict) == FAILURE) {
802805
RETURN_THROWS();

ext/enchant/enchant.stub.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ function enchant_broker_free($broker): bool {}
1414
*/
1515
function enchant_broker_get_error($broker) {}
1616

17-
/** @param resource $broker */
17+
/**
18+
* @param resource $broker
19+
* @deprecated
20+
*/
1821
function enchant_broker_set_dict_path($broker, int $name, string $value): bool {}
1922

20-
/** @param resource $broker */
23+
/**
24+
* @param resource $broker
25+
* @deprecated
26+
*/
2127
function enchant_broker_get_dict_path($broker, int $name): string|false {}
2228

2329
/** @param resource $broker */
@@ -57,12 +63,26 @@ function enchant_dict_check($dict, string $word): bool {}
5763
function enchant_dict_suggest($dict, string $word): ?array {}
5864

5965
/** @param resource $dict */
66+
function enchant_dict_add($dict, string $word): void {}
67+
68+
/**
69+
* @param resource $dict
70+
* @alias enchant_dict_add
71+
* @deprecated
72+
*/
6073
function enchant_dict_add_to_personal($dict, string $word): void {}
6174

6275
/** @param resource $dict */
6376
function enchant_dict_add_to_session($dict, string $word): void {}
6477

6578
/** @param resource $dict */
79+
function enchant_dict_is_added($dict, string $word): bool {}
80+
81+
/**
82+
* @param resource $dict
83+
* @alias enchant_dict_is_added
84+
* @deprecated
85+
*/
6686
function enchant_dict_is_in_session($dict, string $word): bool {}
6787

6888
/** @param resource $dict */

ext/enchant/enchant_arginfo.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_suggest, 0, 2, IS_A
6969
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
7070
ZEND_END_ARG_INFO()
7171

72-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_add_to_personal, 0, 2, IS_VOID, 0)
72+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_add, 0, 2, IS_VOID, 0)
7373
ZEND_ARG_INFO(0, dict)
7474
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
7575
ZEND_END_ARG_INFO()
7676

77-
#define arginfo_enchant_dict_add_to_session arginfo_enchant_dict_add_to_personal
77+
#define arginfo_enchant_dict_add_to_personal arginfo_enchant_dict_add
78+
79+
#define arginfo_enchant_dict_add_to_session arginfo_enchant_dict_add
80+
81+
#define arginfo_enchant_dict_is_added arginfo_enchant_dict_check
7882

7983
#define arginfo_enchant_dict_is_in_session arginfo_enchant_dict_check
8084

@@ -108,9 +112,9 @@ ZEND_FUNCTION(enchant_broker_describe);
108112
ZEND_FUNCTION(enchant_dict_quick_check);
109113
ZEND_FUNCTION(enchant_dict_check);
110114
ZEND_FUNCTION(enchant_dict_suggest);
111-
ZEND_FUNCTION(enchant_dict_add_to_personal);
115+
ZEND_FUNCTION(enchant_dict_add);
112116
ZEND_FUNCTION(enchant_dict_add_to_session);
113-
ZEND_FUNCTION(enchant_dict_is_in_session);
117+
ZEND_FUNCTION(enchant_dict_is_added);
114118
ZEND_FUNCTION(enchant_dict_store_replacement);
115119
ZEND_FUNCTION(enchant_dict_get_error);
116120
ZEND_FUNCTION(enchant_dict_describe);
@@ -120,8 +124,8 @@ static const zend_function_entry ext_functions[] = {
120124
ZEND_FE(enchant_broker_init, arginfo_enchant_broker_init)
121125
ZEND_FE(enchant_broker_free, arginfo_enchant_broker_free)
122126
ZEND_FE(enchant_broker_get_error, arginfo_enchant_broker_get_error)
123-
ZEND_FE(enchant_broker_set_dict_path, arginfo_enchant_broker_set_dict_path)
124-
ZEND_FE(enchant_broker_get_dict_path, arginfo_enchant_broker_get_dict_path)
127+
ZEND_DEP_FE(enchant_broker_set_dict_path, arginfo_enchant_broker_set_dict_path)
128+
ZEND_DEP_FE(enchant_broker_get_dict_path, arginfo_enchant_broker_get_dict_path)
125129
ZEND_FE(enchant_broker_list_dicts, arginfo_enchant_broker_list_dicts)
126130
ZEND_FE(enchant_broker_request_dict, arginfo_enchant_broker_request_dict)
127131
ZEND_FE(enchant_broker_request_pwl_dict, arginfo_enchant_broker_request_pwl_dict)
@@ -132,9 +136,11 @@ static const zend_function_entry ext_functions[] = {
132136
ZEND_FE(enchant_dict_quick_check, arginfo_enchant_dict_quick_check)
133137
ZEND_FE(enchant_dict_check, arginfo_enchant_dict_check)
134138
ZEND_FE(enchant_dict_suggest, arginfo_enchant_dict_suggest)
135-
ZEND_FE(enchant_dict_add_to_personal, arginfo_enchant_dict_add_to_personal)
139+
ZEND_FE(enchant_dict_add, arginfo_enchant_dict_add)
140+
ZEND_DEP_FALIAS(enchant_dict_add_to_personal, enchant_dict_add, arginfo_enchant_dict_add_to_personal)
136141
ZEND_FE(enchant_dict_add_to_session, arginfo_enchant_dict_add_to_session)
137-
ZEND_FE(enchant_dict_is_in_session, arginfo_enchant_dict_is_in_session)
142+
ZEND_FE(enchant_dict_is_added, arginfo_enchant_dict_is_added)
143+
ZEND_DEP_FALIAS(enchant_dict_is_in_session, enchant_dict_is_added, arginfo_enchant_dict_is_in_session)
138144
ZEND_FE(enchant_dict_store_replacement, arginfo_enchant_dict_store_replacement)
139145
ZEND_FE(enchant_dict_get_error, arginfo_enchant_dict_get_error)
140146
ZEND_FE(enchant_dict_describe, arginfo_enchant_dict_describe)

ext/enchant/tests/broker_free_02.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if (is_resource($broker)) {
2121
if ($requestDict) {
2222
echo("OK\n");
2323
for($x=0;$x<count($newWord);$x++) {
24-
$AddtoPersonalDict = enchant_dict_add_to_personal($requestDict,$newWord[$x]);
24+
$AddtoPersonalDict = enchant_dict_add($requestDict,$newWord[$x]);
2525
}
2626

2727
if (NULL === $AddtoPersonalDict) {

ext/enchant/tests/broker_free_dict.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (is_resource($broker)) {
1919

2020
if ($requestDict) {
2121
echo("OK\n");
22-
$AddtoPersonalDict = enchant_dict_add_to_personal($requestDict, $newWord);
22+
$AddtoPersonalDict = enchant_dict_add($requestDict, $newWord);
2323

2424
if (NULL === $AddtoPersonalDict) {
2525
var_dump($AddtoPersonalDict);

ext/enchant/tests/bug53070.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Bug #53070 (enchant_broker_get_path crashes if no path is set)
44
<?php
55
if(!extension_loaded('enchant')) die('skip, enchant not loader');
66
if (!is_resource(enchant_broker_init())) {die("skip, resource dont load\n");}
7+
if (defined("LIBENCHANT_VERSION") && version_compare(LIBENCHANT_VERSION, "2", ">")) die('skip libenchant v1 only');
78
?>
89
--FILE--
910
<?php
@@ -12,8 +13,12 @@ var_dump(enchant_broker_get_dict_path($broker, ENCHANT_MYSPELL));
1213
var_dump(enchant_broker_get_dict_path($broker, ENCHANT_ISPELL));
1314
?>
1415
--EXPECTF--
16+
Deprecated: Function enchant_broker_get_dict_path() is deprecated in %s
17+
1518
Warning: enchant_broker_get_dict_path(): dict_path not set in %s on line %d
1619
bool(false)
1720

21+
Deprecated: Function enchant_broker_get_dict_path() is deprecated in %s
22+
1823
Warning: enchant_broker_get_dict_path(): dict_path not set in %s on line %d
1924
bool(false)

ext/enchant/tests/dict_add_to_personal.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
enchant_dict_add_to_personal() function
2+
enchant_dict_add() function
33
--CREDITS--
44
marcosptf - <marcosptf@yahoo.com.br>
55
--SKIPIF--
@@ -20,7 +20,7 @@ if (is_resource($broker)) {
2020

2121
if ($requestDict) {
2222
echo("OK\n");
23-
$AddtoPersonalDict = enchant_dict_add_to_personal($requestDict,$newWord);
23+
$AddtoPersonalDict = enchant_dict_add($requestDict,$newWord);
2424

2525
if (NULL === $AddtoPersonalDict) {
2626
var_dump($AddtoPersonalDict);

ext/enchant/tests/dict_check.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (is_resource($broker)) {
2020

2121
if ($requestDict) {
2222
echo("OK\n");
23-
enchant_dict_add_to_personal($requestDict, $newWord);
23+
enchant_dict_add($requestDict, $newWord);
2424

2525
if (enchant_dict_check($requestDict, $newWord)) {
2626
echo("OK\n");

ext/enchant/tests/dict_is_in_session.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ if (is_resource($broker)) {
2020

2121
if ($requestDict) {
2222
echo("OK\n");
23-
$AddtoPersonalDict = enchant_dict_add_to_personal($requestDict,$newWord);
23+
$AddtoPersonalDict = enchant_dict_add($requestDict,$newWord);
2424

2525
if (NULL === $AddtoPersonalDict) {
26-
var_dump(enchant_dict_is_in_session($requestDict,$newWord));
26+
var_dump(enchant_dict_is_added($requestDict,$newWord));
2727
} else {
2828
echo("dict add to personal failed\n");
2929
}

ext/enchant/tests/enchant_broker_set_dict_path.phpt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ marcosptf - <marcosptf@yahoo.com.br>
88
if(!extension_loaded('enchant')) die('skip, enchant not loader');
99
if (!is_resource(enchant_broker_init())) {die("skip, resource dont load\n");}
1010
if (!is_array(enchant_broker_list_dicts(enchant_broker_init()))) {die("skip, no dictionary installed on this machine! \n");}
11+
if (defined("LIBENCHANT_VERSION") && version_compare(LIBENCHANT_VERSION, "2", ">")) die('skip libenchant v1 only');
1112
?>
1213
--FILE--
1314
<?php
@@ -46,8 +47,16 @@ if (is_resource($broker)) {
4647
echo("broker is not a resource; failed; \n");
4748
}
4849
?>
49-
--EXPECT--
50+
--EXPECTF--
5051
OK
52+
53+
Deprecated: Function enchant_broker_set_dict_path() is deprecated in %s
5154
OK
55+
56+
Deprecated: Function enchant_broker_set_dict_path() is deprecated in %s
5257
OK
58+
59+
Deprecated: Function enchant_broker_get_dict_path() is deprecated in %s
60+
61+
Deprecated: Function enchant_broker_get_dict_path() is deprecated in %s
5362
OK

0 commit comments

Comments
 (0)