Skip to content

Commit 8db5d60

Browse files
Convert enchant resources to opaque objects
Additionally, deprecate ENCHANT_MYSPELL and ENCHANT_ISPELL constants. Co-authored-by: Remi Collet <remi@php.net>
1 parent f6ae728 commit 8db5d60

30 files changed

+335
-289
lines changed

ext/enchant/enchant.c

Lines changed: 159 additions & 141 deletions
Large diffs are not rendered by default.

ext/enchant/enchant.stub.php

Lines changed: 36 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,70 @@
22

33
/** @generate-function-entries */
44

5-
/** @return resource|false */
6-
function enchant_broker_init() {}
5+
final class EnchantBroker
6+
{
7+
}
78

8-
/** @param resource $broker */
9-
function enchant_broker_free($broker): bool {}
9+
final class EnchantDict
10+
{
11+
}
1012

11-
/**
12-
* @param resource $broker
13-
* @return string|false
14-
*/
15-
function enchant_broker_get_error($broker) {}
13+
function enchant_broker_init(): EnchantBroker|false {}
1614

17-
/**
18-
* @param resource $broker
19-
* @deprecated
20-
*/
21-
function enchant_broker_set_dict_path($broker, int $name, string $value): bool {}
15+
/** @deprecated */
16+
function enchant_broker_free(EnchantBroker $broker): bool {}
2217

23-
/**
24-
* @param resource $broker
25-
* @deprecated
26-
*/
27-
function enchant_broker_get_dict_path($broker, int $name): string|false {}
18+
function enchant_broker_get_error(EnchantBroker $broker): string|false {}
2819

29-
/** @param resource $broker */
30-
function enchant_broker_list_dicts($broker): ?array {}
20+
/** @deprecated */
21+
function enchant_broker_set_dict_path(EnchantBroker $broker, int $name, string $value): bool {}
3122

32-
/**
33-
* @param resource $broker
34-
* @return resource|false
35-
*/
36-
function enchant_broker_request_dict($broker, string $tag) {}
23+
/** @deprecated */
24+
function enchant_broker_get_dict_path(EnchantBroker $broker, int $name): string|false {}
3725

38-
/**
39-
* @param resource $broker
40-
* @return resource|false
41-
*/
42-
function enchant_broker_request_pwl_dict($broker, string $filename) {}
26+
function enchant_broker_list_dicts(EnchantBroker $broker): ?array {}
27+
28+
function enchant_broker_request_dict(EnchantBroker $broker, string $tag): EnchantDict|false {}
4329

44-
/** @param resource $dict */
45-
function enchant_broker_free_dict($dict): bool {}
30+
function enchant_broker_request_pwl_dict(EnchantBroker $broker, string $filename): EnchantDict|false {}
4631

47-
/** @param resource $broker */
48-
function enchant_broker_dict_exists($broker, string $tag): bool {}
32+
/** @deprecated */
33+
function enchant_broker_free_dict(EnchantDict $dict): bool {}
4934

50-
/** @param resource $broker */
51-
function enchant_broker_set_ordering($broker, string $tag, string $ordering): bool {}
35+
function enchant_broker_dict_exists(EnchantBroker $broker, string $tag): bool {}
5236

53-
/** @param resource $broker */
54-
function enchant_broker_describe($broker): ?array {}
37+
function enchant_broker_set_ordering(EnchantBroker $broker, string $tag, string $ordering): bool {}
5538

56-
/** @param resource $dict */
57-
function enchant_dict_quick_check($dict, string $word, &$suggestions = null): bool {}
39+
function enchant_broker_describe(EnchantBroker $broker): ?array {}
5840

59-
/** @param resource $dict */
60-
function enchant_dict_check($dict, string $word): bool {}
41+
function enchant_dict_quick_check(EnchantDict $dict, string $word, &$suggestions = null): bool {}
6142

62-
/** @param resource $dict */
63-
function enchant_dict_suggest($dict, string $word): ?array {}
43+
function enchant_dict_check(EnchantDict $dict, string $word): bool {}
6444

65-
/** @param resource $dict */
66-
function enchant_dict_add($dict, string $word): void {}
45+
function enchant_dict_suggest(EnchantDict $dict, string $word): ?array {}
46+
47+
function enchant_dict_add(EnchantDict $dict, string $word): void {}
6748

6849
/**
69-
* @param resource $dict
7050
* @alias enchant_dict_add
7151
* @deprecated
7252
*/
73-
function enchant_dict_add_to_personal($dict, string $word): void {}
53+
function enchant_dict_add_to_personal(EnchantDict $dict, string $word): void {}
7454

75-
/** @param resource $dict */
76-
function enchant_dict_add_to_session($dict, string $word): void {}
55+
function enchant_dict_add_to_session(EnchantDict $dict, string $word): void {}
7756

78-
/** @param resource $dict */
79-
function enchant_dict_is_added($dict, string $word): bool {}
57+
function enchant_dict_is_added(EnchantDict $dict, string $word): bool {}
8058

8159
/**
8260
* @param resource $dict
8361
* @alias enchant_dict_is_added
8462
* @deprecated
8563
*/
86-
function enchant_dict_is_in_session($dict, string $word): bool {}
64+
function enchant_dict_is_in_session(EnchantDict $dict, string $word): bool {}
65+
66+
function enchant_dict_store_replacement(EnchantDict $dict, string $mis, string $cor): void {}
8767

88-
/** @param resource $dict */
89-
function enchant_dict_store_replacement($dict, string $mis, string $cor): void {}
68+
function enchant_dict_get_error(EnchantDict $dict): string|false {}
9069

91-
/** @param resource $dict */
92-
function enchant_dict_get_error($dict): string|false {}
70+
function enchant_dict_describe(EnchantDict $dict): array {}
9371

94-
/** @param resource $dict */
95-
function enchant_dict_describe($dict): array {}

ext/enchant/enchant_arginfo.h

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
11
/* This is a generated file, edit the .stub.php file instead. */
22

3-
ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_init, 0, 0, 0)
3+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_enchant_broker_init, 0, 0, EnchantBroker, MAY_BE_FALSE)
44
ZEND_END_ARG_INFO()
55

66
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_broker_free, 0, 1, _IS_BOOL, 0)
7-
ZEND_ARG_INFO(0, broker)
7+
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
88
ZEND_END_ARG_INFO()
99

10-
ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_get_error, 0, 0, 1)
11-
ZEND_ARG_INFO(0, broker)
10+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_enchant_broker_get_error, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
11+
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
1212
ZEND_END_ARG_INFO()
1313

1414
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_broker_set_dict_path, 0, 3, _IS_BOOL, 0)
15-
ZEND_ARG_INFO(0, broker)
15+
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
1616
ZEND_ARG_TYPE_INFO(0, name, IS_LONG, 0)
1717
ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0)
1818
ZEND_END_ARG_INFO()
1919

2020
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_enchant_broker_get_dict_path, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
21-
ZEND_ARG_INFO(0, broker)
21+
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
2222
ZEND_ARG_TYPE_INFO(0, name, IS_LONG, 0)
2323
ZEND_END_ARG_INFO()
2424

2525
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_broker_list_dicts, 0, 1, IS_ARRAY, 1)
26-
ZEND_ARG_INFO(0, broker)
26+
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
2727
ZEND_END_ARG_INFO()
2828

29-
ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_request_dict, 0, 0, 2)
30-
ZEND_ARG_INFO(0, broker)
29+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_enchant_broker_request_dict, 0, 2, EnchantDict, MAY_BE_FALSE)
30+
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
3131
ZEND_ARG_TYPE_INFO(0, tag, IS_STRING, 0)
3232
ZEND_END_ARG_INFO()
3333

34-
ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_request_pwl_dict, 0, 0, 2)
35-
ZEND_ARG_INFO(0, broker)
34+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_enchant_broker_request_pwl_dict, 0, 2, EnchantDict, MAY_BE_FALSE)
35+
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
3636
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
3737
ZEND_END_ARG_INFO()
3838

3939
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_broker_free_dict, 0, 1, _IS_BOOL, 0)
40-
ZEND_ARG_INFO(0, dict)
40+
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
4141
ZEND_END_ARG_INFO()
4242

4343
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_broker_dict_exists, 0, 2, _IS_BOOL, 0)
44-
ZEND_ARG_INFO(0, broker)
44+
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
4545
ZEND_ARG_TYPE_INFO(0, tag, IS_STRING, 0)
4646
ZEND_END_ARG_INFO()
4747

4848
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_broker_set_ordering, 0, 3, _IS_BOOL, 0)
49-
ZEND_ARG_INFO(0, broker)
49+
ZEND_ARG_OBJ_INFO(0, broker, EnchantBroker, 0)
5050
ZEND_ARG_TYPE_INFO(0, tag, IS_STRING, 0)
5151
ZEND_ARG_TYPE_INFO(0, ordering, IS_STRING, 0)
5252
ZEND_END_ARG_INFO()
5353

5454
#define arginfo_enchant_broker_describe arginfo_enchant_broker_list_dicts
5555

5656
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_quick_check, 0, 2, _IS_BOOL, 0)
57-
ZEND_ARG_INFO(0, dict)
57+
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
5858
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
5959
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, suggestions, "null")
6060
ZEND_END_ARG_INFO()
6161

6262
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_check, 0, 2, _IS_BOOL, 0)
63-
ZEND_ARG_INFO(0, dict)
63+
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
6464
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
6565
ZEND_END_ARG_INFO()
6666

6767
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_suggest, 0, 2, IS_ARRAY, 1)
68-
ZEND_ARG_INFO(0, dict)
68+
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
6969
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
7070
ZEND_END_ARG_INFO()
7171

7272
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_add, 0, 2, IS_VOID, 0)
73-
ZEND_ARG_INFO(0, dict)
73+
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
7474
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
7575
ZEND_END_ARG_INFO()
7676

@@ -83,17 +83,17 @@ ZEND_END_ARG_INFO()
8383
#define arginfo_enchant_dict_is_in_session arginfo_enchant_dict_check
8484

8585
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_store_replacement, 0, 3, IS_VOID, 0)
86-
ZEND_ARG_INFO(0, dict)
86+
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
8787
ZEND_ARG_TYPE_INFO(0, mis, IS_STRING, 0)
8888
ZEND_ARG_TYPE_INFO(0, cor, IS_STRING, 0)
8989
ZEND_END_ARG_INFO()
9090

9191
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_enchant_dict_get_error, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
92-
ZEND_ARG_INFO(0, dict)
92+
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
9393
ZEND_END_ARG_INFO()
9494

9595
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_describe, 0, 1, IS_ARRAY, 0)
96-
ZEND_ARG_INFO(0, dict)
96+
ZEND_ARG_OBJ_INFO(0, dict, EnchantDict, 0)
9797
ZEND_END_ARG_INFO()
9898

9999

@@ -122,14 +122,14 @@ ZEND_FUNCTION(enchant_dict_describe);
122122

123123
static const zend_function_entry ext_functions[] = {
124124
ZEND_FE(enchant_broker_init, arginfo_enchant_broker_init)
125-
ZEND_FE(enchant_broker_free, arginfo_enchant_broker_free)
125+
ZEND_DEP_FE(enchant_broker_free, arginfo_enchant_broker_free)
126126
ZEND_FE(enchant_broker_get_error, arginfo_enchant_broker_get_error)
127127
ZEND_DEP_FE(enchant_broker_set_dict_path, arginfo_enchant_broker_set_dict_path)
128128
ZEND_DEP_FE(enchant_broker_get_dict_path, arginfo_enchant_broker_get_dict_path)
129129
ZEND_FE(enchant_broker_list_dicts, arginfo_enchant_broker_list_dicts)
130130
ZEND_FE(enchant_broker_request_dict, arginfo_enchant_broker_request_dict)
131131
ZEND_FE(enchant_broker_request_pwl_dict, arginfo_enchant_broker_request_pwl_dict)
132-
ZEND_FE(enchant_broker_free_dict, arginfo_enchant_broker_free_dict)
132+
ZEND_DEP_FE(enchant_broker_free_dict, arginfo_enchant_broker_free_dict)
133133
ZEND_FE(enchant_broker_dict_exists, arginfo_enchant_broker_dict_exists)
134134
ZEND_FE(enchant_broker_set_ordering, arginfo_enchant_broker_set_ordering)
135135
ZEND_FE(enchant_broker_describe, arginfo_enchant_broker_describe)
@@ -146,3 +146,13 @@ static const zend_function_entry ext_functions[] = {
146146
ZEND_FE(enchant_dict_describe, arginfo_enchant_dict_describe)
147147
ZEND_FE_END
148148
};
149+
150+
151+
static const zend_function_entry class_EnchantBroker_methods[] = {
152+
ZEND_FE_END
153+
};
154+
155+
156+
static const zend_function_entry class_EnchantDict_methods[] = {
157+
ZEND_FE_END
158+
};

ext/enchant/tests/broker_describe.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ if (!$broker) {
1717
}
1818

1919
if (!enchant_broker_describe($broker)) {
20-
enchant_broker_free($broker);
20+
@enchant_broker_free($broker);
2121

2222
echo "skip: No broker providers found\n";
2323
}
2424

25-
enchant_broker_free($broker);
25+
@enchant_broker_free($broker);
2626
?>
2727
--FILE--
2828
<?php
@@ -47,7 +47,7 @@ if($broker) {
4747
echo "failed, brocker describe array \n";
4848
}
4949

50-
enchant_broker_free($broker);
50+
@enchant_broker_free($broker);
5151

5252
} else {
5353
echo("failed, broker_init failure\n");

ext/enchant/tests/broker_dict_exists.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ marcosptf - <marcosptf@yahoo.com.br>
55
--SKIPIF--
66
<?php
77
if(!extension_loaded('enchant')) die('skip, enchant not loader');
8-
if (!is_resource(enchant_broker_init())) {die("skip, resource dont load\n");}
8+
if (!is_object(enchant_broker_init())) {die("skip, resource dont load\n");}
99
if (!is_array(enchant_broker_list_dicts(enchant_broker_init()))) {die("skip, no dictionary installed on this machine! \n");}
1010
?>
1111
--FILE--

ext/enchant/tests/broker_free.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ marcosptf - <marcosptf@yahoo.com.br>
55
--SKIPIF--
66
<?php
77
if(!extension_loaded('enchant')) die('skip, enchant not loader');
8-
if (!is_resource(enchant_broker_init())) {die("skip, resource dont load\n");}
8+
if (!is_object(enchant_broker_init())) {die("skip, resource dont load\n");}
99
?>
1010
--FILE--
1111
<?php
1212
$broker = enchant_broker_init();
13-
if (is_resource($broker)) {
13+
if (is_object($broker)) {
1414
echo "OK\n";
1515
enchant_broker_free($broker);
1616

@@ -19,6 +19,8 @@ if (is_resource($broker)) {
1919
}
2020
echo "OK\n";
2121
?>
22-
--EXPECT--
22+
--EXPECTF--
2323
OK
24+
25+
Deprecated: Function enchant_broker_free() is deprecated in %s
2426
OK

ext/enchant/tests/broker_free_01.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
--TEST--
2-
enchant_broker_free() function
2+
@enchant_broker_free() function
33
--CREDITS--
44
marcosptf - <marcosptf@yahoo.com.br>
55
--SKIPIF--
66
<?php
77
if(!extension_loaded('enchant')) die('skip, enchant not loader');
8-
if (!is_resource(enchant_broker_init())) {die("skip, resource dont load\n");}
8+
if (!is_object(enchant_broker_init())) {die("skip, resource dont load\n");}
99
?>
1010
--FILE--
1111
<?php
1212
$broker = enchant_broker_init();
13-
if (is_resource($broker)) {
13+
if (is_object($broker)) {
1414
echo("OK\n");
1515

16-
if (enchant_broker_free($broker)) {
16+
if (@enchant_broker_free($broker)) {
1717
echo("OK\n");
1818
} else {
1919
echo("broker free failed\n");

ext/enchant/tests/broker_free_02.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
--TEST--
2-
enchant_broker_free() function
2+
@enchant_broker_free() function
33
--CREDITS--
44
marcosptf - <marcosptf@yahoo.com.br>
55
--SKIPIF--
66
<?php
77
if(!extension_loaded('enchant')) die('skip, enchant not loader');
8-
if(!is_resource(enchant_broker_init())) {die("skip, resource dont load\n");}
8+
if(!is_object(enchant_broker_init())) {die("skip, resource dont load\n");}
99
if(!is_array(enchant_broker_list_dicts(enchant_broker_init()))) {die("skip, no dictionary installed on this machine! \n");}
1010
?>
1111
--FILE--
@@ -14,7 +14,7 @@ $broker = enchant_broker_init();
1414
$dicts = enchant_broker_list_dicts($broker);
1515
$newWord = array("iLoveJava","iLoveJavascript","iLoveRuby","iLovePerl","iLoveAwk","iLoveC");
1616

17-
if (is_resource($broker)) {
17+
if (is_object($broker)) {
1818
echo("OK\n");
1919
$requestDict = enchant_broker_request_dict($broker, $dicts[0]['lang_tag']);
2020

@@ -27,10 +27,10 @@ if (is_resource($broker)) {
2727
if (NULL === $AddtoPersonalDict) {
2828
var_dump($AddtoPersonalDict);
2929

30-
if (enchant_broker_free_dict($requestDict)) {
30+
if (@enchant_broker_free_dict($requestDict)) {
3131
echo("OK\n");
3232

33-
if (enchant_broker_free($broker)) {
33+
if (@enchant_broker_free($broker)) {
3434
echo("OK\n");
3535

3636
} else {

0 commit comments

Comments
 (0)