Skip to content

Commit 3fe49d8

Browse files
committed
Generate method entries from stubs for a couple of extensions
Closes GH-5368
1 parent ca006e5 commit 3fe49d8

20 files changed

+117
-102
lines changed

Zend/zend_API.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ typedef struct _zend_fcall_info_cache {
8484
#define ZEND_ME(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##name, arg_info, flags)
8585
#define ZEND_DEP_ME(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##name, arg_info, flags | ZEND_ACC_DEPRECATED)
8686
#define ZEND_ABSTRACT_ME(classname, name, arg_info) ZEND_RAW_FENTRY(#name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
87+
#define ZEND_ABSTRACT_ME_WITH_FLAGS(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, NULL, arg_info, flags)
8788
#define ZEND_MALIAS(classname, name, alias, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##alias, arg_info, flags)
8889
#define ZEND_ME_MAPPING(name, func_name, arg_info, flags) ZEND_RAW_FENTRY(#name, zif_##func_name, arg_info, flags)
8990

build/gen_stub.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ public function getFunctionEntry(): string {
447447
} else {
448448
if ($this->flags & Class_::MODIFIER_ABSTRACT) {
449449
return sprintf(
450-
"\tZEND_ABSTRACT_ME(%s, %s, %s)\n",
451-
$this->name->className, $this->name->name, $this->getArgInfoName()
450+
"\tZEND_ABSTRACT_ME_WITH_FLAGS(%s, %s, %s, %s)\n",
451+
$this->name->className, $this->name->name, $this->getArgInfoName(), $this->getFlagsAsString()
452452
);
453453
}
454454

@@ -797,8 +797,8 @@ function parseStubFile(string $fileName): FileInfo {
797797
$flags |= Class_::MODIFIER_ABSTRACT;
798798
}
799799

800-
if ($flags & Class_::MODIFIER_ABSTRACT && !($flags & Class_::MODIFIER_PUBLIC)) {
801-
throw new Exception("Abstract non-public methods are not supported");
800+
if (!($flags & Class_::VISIBILITY_MODIFIER_MASK)) {
801+
throw new Exception("Method visibility modifier is required");
802802
}
803803

804804
$methodInfos[] = parseFunctionLike(
@@ -984,9 +984,9 @@ function (FuncInfo $funcInfo) use(&$generatedFunctionDeclarations) {
984984
}
985985
);
986986

987-
$code .= "\n\n";
988-
989-
$code .= generateFunctionEntries(null, $fileInfo->funcInfos);
987+
if (!empty($fileInfo->funcInfos)) {
988+
$code .= generateFunctionEntries(null, $fileInfo->funcInfos);
989+
}
990990

991991
foreach ($fileInfo->classInfos as $classInfo) {
992992
$code .= generateFunctionEntries($classInfo->name, $classInfo->funcInfos);

ext/com_dotnet/com_extension.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,6 @@ zend_class_entry
3737
*php_com_exception_class_entry,
3838
*php_com_saproxy_class_entry;
3939

40-
static const zend_function_entry com_variant_funcs[] = {
41-
PHP_ME(variant, __construct, arginfo_class_variant___construct, ZEND_ACC_PUBLIC)
42-
PHP_FE_END
43-
};
44-
45-
static const zend_function_entry com_com_funcs[] = {
46-
PHP_ME(com, __construct, arginfo_class_com___construct, ZEND_ACC_PUBLIC)
47-
PHP_FE_END
48-
};
49-
50-
static const zend_function_entry com_dotnet_funcs[] = {
51-
PHP_ME(dotnet, __construct, arginfo_class_dotnet___construct, ZEND_ACC_PUBLIC)
52-
PHP_FE_END
53-
};
54-
5540
/* {{{ com_dotnet_module_entry
5641
*/
5742
zend_module_entry com_dotnet_module_entry = {
@@ -196,22 +181,22 @@ PHP_MINIT_FUNCTION(com_dotnet)
196181
/* php_com_saproxy_class_entry->constructor->common.fn_flags |= ZEND_ACC_PROTECTED; */
197182
php_com_saproxy_class_entry->get_iterator = php_com_saproxy_iter_get;
198183

199-
INIT_CLASS_ENTRY(ce, "variant", com_variant_funcs);
184+
INIT_CLASS_ENTRY(ce, "variant", class_variant_methods);
200185
ce.create_object = php_com_object_new;
201186
php_com_variant_class_entry = zend_register_internal_class(&ce);
202187
php_com_variant_class_entry->get_iterator = php_com_iter_get;
203188
php_com_variant_class_entry->serialize = zend_class_serialize_deny;
204189
php_com_variant_class_entry->unserialize = zend_class_unserialize_deny;
205190

206-
INIT_CLASS_ENTRY(ce, "com", com_com_funcs);
191+
INIT_CLASS_ENTRY(ce, "com", class_com_methods);
207192
ce.create_object = php_com_object_new;
208193
tmp = zend_register_internal_class_ex(&ce, php_com_variant_class_entry);
209194
tmp->get_iterator = php_com_iter_get;
210195
tmp->serialize = zend_class_serialize_deny;
211196
tmp->unserialize = zend_class_unserialize_deny;
212197

213198
#if HAVE_MSCOREE_H
214-
INIT_CLASS_ENTRY(ce, "dotnet", com_dotnet_funcs);
199+
INIT_CLASS_ENTRY(ce, "dotnet", class_dotnet_methods);
215200
ce.create_object = php_com_object_new;
216201
tmp = zend_register_internal_class_ex(&ce, php_com_variant_class_entry);
217202
tmp->get_iterator = php_com_iter_get;

ext/com_dotnet/com_extension_arginfo.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ ZEND_FUNCTION(com_event_sink);
163163
ZEND_FUNCTION(com_print_typeinfo);
164164
ZEND_FUNCTION(com_message_pump);
165165
ZEND_FUNCTION(com_load_typelib);
166+
ZEND_METHOD(variant, __construct);
167+
ZEND_METHOD(com, __construct);
168+
#if HAVE_MSCOREE_H
169+
ZEND_METHOD(dotnet, __construct);
170+
#endif
166171

167172

168173
static const zend_function_entry ext_functions[] = {
@@ -200,3 +205,23 @@ static const zend_function_entry ext_functions[] = {
200205
ZEND_FE(com_load_typelib, arginfo_com_load_typelib)
201206
ZEND_FE_END
202207
};
208+
209+
210+
static const zend_function_entry class_variant_methods[] = {
211+
ZEND_ME(variant, __construct, arginfo_class_variant___construct, ZEND_ACC_PUBLIC)
212+
ZEND_FE_END
213+
};
214+
215+
216+
static const zend_function_entry class_com_methods[] = {
217+
ZEND_ME(com, __construct, arginfo_class_com___construct, ZEND_ACC_PUBLIC)
218+
ZEND_FE_END
219+
};
220+
221+
222+
static const zend_function_entry class_dotnet_methods[] = {
223+
#if HAVE_MSCOREE_H
224+
ZEND_ME(dotnet, __construct, arginfo_class_dotnet___construct, ZEND_ACC_PUBLIC)
225+
#endif
226+
ZEND_FE_END
227+
};

ext/com_dotnet/com_persist.stub.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
<?php
22

3-
final class COMPersistHelper {
4-
public function __construct(?VARIANT $com_object);
53

6-
public function GetCurFileName(): string|false;
4+
final class COMPersistHelper
5+
{
6+
public function __construct(?VARIANT $com_object) {}
77

8-
public function SaveToFile(?string $filename, bool $remember = true): bool;
8+
public function GetCurFileName(): string|false {}
99

10-
public function LoadFromFile(string $path, int $flags = 0): bool;
10+
public function SaveToFile(?string $filename, bool $remember = true): bool {}
1111

12-
public function GetMaxStreamSize(): int;
12+
public function LoadFromFile(string $path, int $flags = 0): bool {}
1313

14-
public function InitNew(): bool;
14+
public function GetMaxStreamSize(): int {}
15+
16+
public function InitNew(): bool {}
1517

1618
/** @param resource $stream */
17-
public function LoadFromStream($stream): bool;
19+
public function LoadFromStream($stream): bool {}
1820

1921
/** @param resource $stream */
20-
public function SaveToStream($stream): bool;
22+
public function SaveToStream($stream): bool {}
2123
}

ext/date/php_date_arginfo.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,6 @@ ZEND_METHOD(DatePeriod, __wakeup);
504504
ZEND_METHOD(DatePeriod, __set_state);
505505

506506

507-
508-
509507
static const zend_function_entry ext_functions[] = {
510508
ZEND_FE(strtotime, arginfo_strtotime)
511509
ZEND_FE(date, arginfo_date)
@@ -560,12 +558,12 @@ static const zend_function_entry ext_functions[] = {
560558

561559

562560
static const zend_function_entry class_DateTimeInterface_methods[] = {
563-
ZEND_ABSTRACT_ME(DateTimeInterface, format, arginfo_class_DateTimeInterface_format)
564-
ZEND_ABSTRACT_ME(DateTimeInterface, getTimezone, arginfo_class_DateTimeInterface_getTimezone)
565-
ZEND_ABSTRACT_ME(DateTimeInterface, getOffset, arginfo_class_DateTimeInterface_getOffset)
566-
ZEND_ABSTRACT_ME(DateTimeInterface, getTimestamp, arginfo_class_DateTimeInterface_getTimestamp)
567-
ZEND_ABSTRACT_ME(DateTimeInterface, diff, arginfo_class_DateTimeInterface_diff)
568-
ZEND_ABSTRACT_ME(DateTimeInterface, __wakeup, arginfo_class_DateTimeInterface___wakeup)
561+
ZEND_ABSTRACT_ME_WITH_FLAGS(DateTimeInterface, format, arginfo_class_DateTimeInterface_format, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
562+
ZEND_ABSTRACT_ME_WITH_FLAGS(DateTimeInterface, getTimezone, arginfo_class_DateTimeInterface_getTimezone, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
563+
ZEND_ABSTRACT_ME_WITH_FLAGS(DateTimeInterface, getOffset, arginfo_class_DateTimeInterface_getOffset, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
564+
ZEND_ABSTRACT_ME_WITH_FLAGS(DateTimeInterface, getTimestamp, arginfo_class_DateTimeInterface_getTimestamp, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
565+
ZEND_ABSTRACT_ME_WITH_FLAGS(DateTimeInterface, diff, arginfo_class_DateTimeInterface_diff, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
566+
ZEND_ABSTRACT_ME_WITH_FLAGS(DateTimeInterface, __wakeup, arginfo_class_DateTimeInterface___wakeup, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
569567
ZEND_FE_END
570568
};
571569

ext/dom/documenttype.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,6 @@
2323
#if HAVE_LIBXML && HAVE_DOM
2424
#include "php_dom.h"
2525

26-
/*
27-
* class DOMDocumentType extends DOMNode
28-
*
29-
* URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-412266927
30-
* Since:
31-
*/
32-
33-
const zend_function_entry php_dom_documenttype_class_functions[] = {
34-
PHP_FE_END
35-
};
36-
3726
/* {{{ name string
3827
readonly=yes
3928
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1844763134

ext/dom/dom_arginfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ static const zend_function_entry ext_functions[] = {
1212
ZEND_FE(dom_import_simplexml, arginfo_dom_import_simplexml)
1313
ZEND_FE_END
1414
};
15+
16+
17+
static const zend_function_entry class_DOMDocumentType_methods[] = {
18+
ZEND_FE_END
19+
};

ext/dom/dom_fe.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ extern const zend_function_entry php_dom_element_class_functions[];
3333
extern const zend_function_entry php_dom_text_class_functions[];
3434
extern const zend_function_entry php_dom_comment_class_functions[];
3535
extern const zend_function_entry php_dom_cdatasection_class_functions[];
36-
extern const zend_function_entry php_dom_documenttype_class_functions[];
3736
extern const zend_function_entry php_dom_notation_class_functions[];
3837
extern const zend_function_entry php_dom_entity_class_functions[];
3938
extern const zend_function_entry php_dom_entityreference_class_functions[];

ext/dom/php_dom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ PHP_MINIT_FUNCTION(dom)
737737
REGISTER_DOM_CLASS(ce, "DOMCdataSection", dom_text_class_entry, php_dom_cdatasection_class_functions, dom_cdatasection_class_entry);
738738
zend_hash_add_ptr(&classes, ce.name, &dom_text_prop_handlers);
739739

740-
REGISTER_DOM_CLASS(ce, "DOMDocumentType", dom_node_class_entry, php_dom_documenttype_class_functions, dom_documenttype_class_entry);
740+
REGISTER_DOM_CLASS(ce, "DOMDocumentType", dom_node_class_entry, class_DOMDocumentType_methods, dom_documenttype_class_entry);
741741

742742
zend_hash_init(&dom_documenttype_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
743743
dom_register_prop_handler(&dom_documenttype_prop_handlers, "name", sizeof("name")-1, dom_documenttype_name_read, NULL);

ext/fileinfo/fileinfo.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,6 @@ PHP_FILEINFO_API zend_object *finfo_objects_new(zend_class_entry *class_type)
107107
}
108108
/* }}} */
109109

110-
/* {{{ finfo_class_functions
111-
*/
112-
static const zend_function_entry finfo_class_functions[] = {
113-
ZEND_ME_MAPPING(__construct, finfo_open, arginfo_class_finfo___construct, ZEND_ACC_PUBLIC)
114-
ZEND_ME_MAPPING(set_flags, finfo_set_flags,arginfo_class_finfo_set_flags, ZEND_ACC_PUBLIC)
115-
ZEND_ME_MAPPING(file, finfo_file, arginfo_class_finfo_file, ZEND_ACC_PUBLIC)
116-
ZEND_ME_MAPPING(buffer, finfo_buffer, arginfo_class_finfo_buffer, ZEND_ACC_PUBLIC)
117-
PHP_FE_END
118-
};
119-
/* }}} */
120-
121110
#define FINFO_SET_OPTION(magic, options) \
122111
if (magic_setflags(magic, options) == -1) { \
123112
php_error_docref(NULL, E_WARNING, "Failed to set option '" ZEND_LONG_FMT "' %d:%s", \
@@ -145,7 +134,7 @@ void finfo_resource_destructor(zend_resource *rsrc) /* {{{ */
145134
PHP_MINIT_FUNCTION(finfo)
146135
{
147136
zend_class_entry _finfo_class_entry;
148-
INIT_CLASS_ENTRY(_finfo_class_entry, "finfo", finfo_class_functions);
137+
INIT_CLASS_ENTRY(_finfo_class_entry, "finfo", class_finfo_methods);
149138
_finfo_class_entry.create_object = finfo_objects_new;
150139
finfo_class_entry = zend_register_internal_class(&_finfo_class_entry);
151140

ext/fileinfo/fileinfo.stub.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,27 @@
44

55
class finfo
66
{
7+
/** @alias finfo_open */
78
public function __construct(int $options = FILEINFO_NONE, string $arg = "") {}
89

910
/**
1011
* @param ?resource $context
1112
* @return string|false
13+
* @alias finfo_file
1214
*/
1315
public function file(string $file_name, int $options = FILEINFO_NONE, $context = null) {}
1416

1517
/**
1618
* @param ?resource $context
1719
* @return string|false
20+
* @alias finfo_buffer
1821
*/
1922
public function buffer(string $string, int $options = FILEINFO_NONE, $context = null) {}
2023

21-
/** @return bool */
24+
/**
25+
* @return bool
26+
* @alias finfo_set_flags
27+
*/
2228
public function set_flags(int $options) {}
2329
}
2430

ext/fileinfo/fileinfo_arginfo.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ static const zend_function_entry ext_functions[] = {
6868
ZEND_FE(mime_content_type, arginfo_mime_content_type)
6969
ZEND_FE_END
7070
};
71+
72+
73+
static const zend_function_entry class_finfo_methods[] = {
74+
ZEND_ME_MAPPING(__construct, finfo_open, arginfo_class_finfo___construct, ZEND_ACC_PUBLIC)
75+
ZEND_ME_MAPPING(file, finfo_file, arginfo_class_finfo_file, ZEND_ACC_PUBLIC)
76+
ZEND_ME_MAPPING(buffer, finfo_buffer, arginfo_class_finfo_buffer, ZEND_ACC_PUBLIC)
77+
ZEND_ME_MAPPING(set_flags, finfo_set_flags, arginfo_class_finfo_set_flags, ZEND_ACC_PUBLIC)
78+
ZEND_FE_END
79+
};

ext/hash/hash.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -887,17 +887,12 @@ PHP_FUNCTION(hash_equals)
887887
/* }}} */
888888

889889
/* {{{ proto HashContext::__construct() */
890-
static PHP_METHOD(HashContext, __construct) {
890+
PHP_METHOD(HashContext, __construct) {
891891
/* Normally unreachable as private/final */
892892
zend_throw_exception(zend_ce_error, "Illegal call to private/final constructor", 0);
893893
}
894894
/* }}} */
895895

896-
static const zend_function_entry php_hashcontext_methods[] = {
897-
PHP_ME(HashContext, __construct, arginfo_class_HashContext___construct, ZEND_ACC_PRIVATE)
898-
PHP_FE_END
899-
};
900-
901896
/* Module Housekeeping */
902897

903898
#define PHP_HASH_HAVAL_REGISTER(p,b) php_hash_register_algo("haval" #b "," #p , &php_hash_##p##haval##b##_ops);
@@ -1242,7 +1237,7 @@ PHP_MINIT_FUNCTION(hash)
12421237

12431238
REGISTER_LONG_CONSTANT("HASH_HMAC", PHP_HASH_HMAC, CONST_CS | CONST_PERSISTENT);
12441239

1245-
INIT_CLASS_ENTRY(ce, "HashContext", php_hashcontext_methods);
1240+
INIT_CLASS_ENTRY(ce, "HashContext", class_HashContext_methods);
12461241
php_hashcontext_ce = zend_register_internal_class(&ce);
12471242
php_hashcontext_ce->ce_flags |= ZEND_ACC_FINAL;
12481243
php_hashcontext_ce->create_object = php_hashcontext_create;

ext/hash/hash_arginfo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ ZEND_FUNCTION(mhash_count);
148148
#if defined(PHP_MHASH_BC)
149149
ZEND_FUNCTION(mhash);
150150
#endif
151+
ZEND_METHOD(HashContext, __construct);
151152

152153

153154
static const zend_function_entry ext_functions[] = {
@@ -183,3 +184,9 @@ static const zend_function_entry ext_functions[] = {
183184
#endif
184185
ZEND_FE_END
185186
};
187+
188+
189+
static const zend_function_entry class_HashContext_methods[] = {
190+
ZEND_ME(HashContext, __construct, arginfo_class_HashContext___construct, ZEND_ACC_PRIVATE)
191+
ZEND_FE_END
192+
};

ext/json/json.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ PHP_JSON_API zend_class_entry *php_json_exception_ce;
3737

3838
PHP_JSON_API ZEND_DECLARE_MODULE_GLOBALS(json)
3939

40-
/* {{{ JsonSerializable methods */
41-
static const zend_function_entry json_serializable_interface[] = {
42-
PHP_ABSTRACT_ME(JsonSerializable, jsonSerialize, arginfo_class_JsonSerializable_jsonSerialize)
43-
PHP_FE_END
44-
};
45-
/* }}} */
46-
4740
/* Register constant for options and errors */
4841
#define PHP_JSON_REGISTER_CONSTANT(_name, _value) \
4942
REGISTER_LONG_CONSTANT(_name, _value, CONST_CS | CONST_PERSISTENT);
@@ -53,7 +46,7 @@ static PHP_MINIT_FUNCTION(json)
5346
{
5447
zend_class_entry ce;
5548

56-
INIT_CLASS_ENTRY(ce, "JsonSerializable", json_serializable_interface);
49+
INIT_CLASS_ENTRY(ce, "JsonSerializable", class_JsonSerializable_methods);
5750
php_json_serializable_ce = zend_register_internal_interface(&ce);
5851

5952
INIT_CLASS_ENTRY(ce, "JsonException", NULL);

ext/json/json_arginfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ static const zend_function_entry ext_functions[] = {
3636
ZEND_FE(json_last_error_msg, arginfo_json_last_error_msg)
3737
ZEND_FE_END
3838
};
39+
40+
41+
static const zend_function_entry class_JsonSerializable_methods[] = {
42+
ZEND_ABSTRACT_ME_WITH_FLAGS(JsonSerializable, jsonSerialize, arginfo_class_JsonSerializable_jsonSerialize, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
43+
ZEND_FE_END
44+
};

0 commit comments

Comments
 (0)