Skip to content

Generate method entries from stubs for a couple of extensions #5368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ typedef struct _zend_fcall_info_cache {
#define ZEND_RAW_FENTRY(zend_name, name, arg_info, flags) { zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_internal_arg_info)-1), flags },

/* Same as ZEND_NAMED_FE */
#define ZEND_RAW_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)

#define ZEND_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
#define ZEND_FE(name, arg_info) ZEND_RAW_FENTRY(#name, zif_##name, arg_info, 0)
#define ZEND_DEP_FE(name, arg_info) ZEND_RAW_FENTRY(#name, zif_##name, arg_info, ZEND_ACC_DEPRECATED)
#define ZEND_FALIAS(name, alias, arg_info) ZEND_RAW_FENTRY(#name, zif_##alias, arg_info, 0)
#define ZEND_DEP_FALIAS(name, alias, arg_info) ZEND_RAW_FENTRY(#name, zif_##alias, arg_info, ZEND_ACC_DEPRECATED)
#define ZEND_NAMED_ME(zend_name, name, arg_info, flags) ZEND_FENTRY(zend_name, name, arg_info, flags)
#define ZEND_ME(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##name, arg_info, flags)
#define ZEND_DEP_ME(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##name, arg_info, flags | ZEND_ACC_DEPRECATED)
#define ZEND_ABSTRACT_ME(classname, name, arg_info) ZEND_RAW_FENTRY(#name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
#define ZEND_MALIAS(classname, name, alias, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##alias, arg_info, flags)
#define ZEND_ME_MAPPING(name, func_name, arg_info, flags) ZEND_RAW_FENTRY(#name, zif_##func_name, arg_info, flags)
#define ZEND_RAW_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)

#define ZEND_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
#define ZEND_FE(name, arg_info) ZEND_RAW_FENTRY(#name, zif_##name, arg_info, 0)
#define ZEND_DEP_FE(name, arg_info) ZEND_RAW_FENTRY(#name, zif_##name, arg_info, ZEND_ACC_DEPRECATED)
#define ZEND_FALIAS(name, alias, arg_info) ZEND_RAW_FENTRY(#name, zif_##alias, arg_info, 0)
#define ZEND_DEP_FALIAS(name, alias, arg_info) ZEND_RAW_FENTRY(#name, zif_##alias, arg_info, ZEND_ACC_DEPRECATED)
#define ZEND_NAMED_ME(zend_name, name, arg_info, flags) ZEND_FENTRY(zend_name, name, arg_info, flags)
#define ZEND_ME(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##name, arg_info, flags)
#define ZEND_DEP_ME(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##name, arg_info, flags | ZEND_ACC_DEPRECATED)
#define ZEND_ABSTRACT_ME(classname, name, arg_info) ZEND_RAW_FENTRY(#name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
#define ZEND_ABSTRACT_ME_WITH_FLAGS(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, NULL, arg_info, flags)
#define ZEND_MALIAS(classname, name, alias, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##alias, arg_info, flags)
#define ZEND_ME_MAPPING(name, func_name, arg_info, flags) ZEND_RAW_FENTRY(#name, zif_##func_name, arg_info, flags)

#define ZEND_NS_FENTRY(ns, zend_name, name, arg_info, flags) ZEND_RAW_FENTRY(ZEND_NS_NAME(ns, #zend_name), name, arg_info, flags)

Expand Down
14 changes: 7 additions & 7 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ public function getFunctionEntry(): string {
} else {
if ($this->flags & Class_::MODIFIER_ABSTRACT) {
return sprintf(
"\tZEND_ABSTRACT_ME(%s, %s, %s)\n",
$this->name->className, $this->name->name, $this->getArgInfoName()
"\tZEND_ABSTRACT_ME_WITH_FLAGS(%s, %s, %s, %s)\n",
$this->name->className, $this->name->name, $this->getArgInfoName(), $this->getFlagsAsString()
);
}

Expand Down Expand Up @@ -797,8 +797,8 @@ function parseStubFile(string $fileName): FileInfo {
$flags |= Class_::MODIFIER_ABSTRACT;
}

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

$methodInfos[] = parseFunctionLike(
Expand Down Expand Up @@ -984,9 +984,9 @@ function (FuncInfo $funcInfo) use(&$generatedFunctionDeclarations) {
}
);

$code .= "\n\n";

$code .= generateFunctionEntries(null, $fileInfo->funcInfos);
if (empty($fileInfo->funcInfos) === false) {
$code .= generateFunctionEntries(null, $fileInfo->funcInfos);
}

foreach ($fileInfo->classInfos as $classInfo) {
$code .= generateFunctionEntries($classInfo->name, $classInfo->funcInfos);
Expand Down
21 changes: 3 additions & 18 deletions ext/com_dotnet/com_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,6 @@ zend_class_entry
*php_com_exception_class_entry,
*php_com_saproxy_class_entry;

static const zend_function_entry com_variant_funcs[] = {
PHP_ME(variant, __construct, arginfo_class_variant___construct, ZEND_ACC_PUBLIC)
PHP_FE_END
};

static const zend_function_entry com_com_funcs[] = {
PHP_ME(com, __construct, arginfo_class_com___construct, ZEND_ACC_PUBLIC)
PHP_FE_END
};

static const zend_function_entry com_dotnet_funcs[] = {
PHP_ME(dotnet, __construct, arginfo_class_dotnet___construct, ZEND_ACC_PUBLIC)
PHP_FE_END
};

/* {{{ com_dotnet_module_entry
*/
zend_module_entry com_dotnet_module_entry = {
Expand Down Expand Up @@ -196,22 +181,22 @@ PHP_MINIT_FUNCTION(com_dotnet)
/* php_com_saproxy_class_entry->constructor->common.fn_flags |= ZEND_ACC_PROTECTED; */
php_com_saproxy_class_entry->get_iterator = php_com_saproxy_iter_get;

INIT_CLASS_ENTRY(ce, "variant", com_variant_funcs);
INIT_CLASS_ENTRY(ce, "variant", class_variant_methods);
ce.create_object = php_com_object_new;
php_com_variant_class_entry = zend_register_internal_class(&ce);
php_com_variant_class_entry->get_iterator = php_com_iter_get;
php_com_variant_class_entry->serialize = zend_class_serialize_deny;
php_com_variant_class_entry->unserialize = zend_class_unserialize_deny;

INIT_CLASS_ENTRY(ce, "com", com_com_funcs);
INIT_CLASS_ENTRY(ce, "com", class_com_methods);
ce.create_object = php_com_object_new;
tmp = zend_register_internal_class_ex(&ce, php_com_variant_class_entry);
tmp->get_iterator = php_com_iter_get;
tmp->serialize = zend_class_serialize_deny;
tmp->unserialize = zend_class_unserialize_deny;

#if HAVE_MSCOREE_H
INIT_CLASS_ENTRY(ce, "dotnet", com_dotnet_funcs);
INIT_CLASS_ENTRY(ce, "dotnet", class_dotnet_methods);
ce.create_object = php_com_object_new;
tmp = zend_register_internal_class_ex(&ce, php_com_variant_class_entry);
tmp->get_iterator = php_com_iter_get;
Expand Down
25 changes: 25 additions & 0 deletions ext/com_dotnet/com_extension_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ ZEND_FUNCTION(com_event_sink);
ZEND_FUNCTION(com_print_typeinfo);
ZEND_FUNCTION(com_message_pump);
ZEND_FUNCTION(com_load_typelib);
ZEND_METHOD(variant, __construct);
ZEND_METHOD(com, __construct);
#if HAVE_MSCOREE_H
ZEND_METHOD(dotnet, __construct);
#endif


static const zend_function_entry ext_functions[] = {
Expand Down Expand Up @@ -200,3 +205,23 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(com_load_typelib, arginfo_com_load_typelib)
ZEND_FE_END
};


static const zend_function_entry class_variant_methods[] = {
ZEND_ME(variant, __construct, arginfo_class_variant___construct, ZEND_ACC_PUBLIC)
ZEND_FE_END
};


static const zend_function_entry class_com_methods[] = {
ZEND_ME(com, __construct, arginfo_class_com___construct, ZEND_ACC_PUBLIC)
ZEND_FE_END
};


static const zend_function_entry class_dotnet_methods[] = {
#if HAVE_MSCOREE_H
ZEND_ME(dotnet, __construct, arginfo_class_dotnet___construct, ZEND_ACC_PUBLIC)
#endif
ZEND_FE_END
};
20 changes: 11 additions & 9 deletions ext/com_dotnet/com_persist.stub.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<?php

final class COMPersistHelper {
public function __construct(?VARIANT $com_object);

public function GetCurFileName(): string|false;
final class COMPersistHelper
{
public function __construct(?VARIANT $com_object) {}

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

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

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

public function InitNew(): bool;
public function GetMaxStreamSize(): int {}

public function InitNew(): bool {}

/** @param resource $stream */
public function LoadFromStream($stream): bool;
public function LoadFromStream($stream): bool {}

/** @param resource $stream */
public function SaveToStream($stream): bool;
public function SaveToStream($stream): bool {}
}
14 changes: 6 additions & 8 deletions ext/date/php_date_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,6 @@ ZEND_METHOD(DatePeriod, __wakeup);
ZEND_METHOD(DatePeriod, __set_state);




static const zend_function_entry ext_functions[] = {
ZEND_FE(strtotime, arginfo_strtotime)
ZEND_FE(date, arginfo_date)
Expand Down Expand Up @@ -560,12 +558,12 @@ static const zend_function_entry ext_functions[] = {


static const zend_function_entry class_DateTimeInterface_methods[] = {
ZEND_ABSTRACT_ME(DateTimeInterface, format, arginfo_class_DateTimeInterface_format)
ZEND_ABSTRACT_ME(DateTimeInterface, getTimezone, arginfo_class_DateTimeInterface_getTimezone)
ZEND_ABSTRACT_ME(DateTimeInterface, getOffset, arginfo_class_DateTimeInterface_getOffset)
ZEND_ABSTRACT_ME(DateTimeInterface, getTimestamp, arginfo_class_DateTimeInterface_getTimestamp)
ZEND_ABSTRACT_ME(DateTimeInterface, diff, arginfo_class_DateTimeInterface_diff)
ZEND_ABSTRACT_ME(DateTimeInterface, __wakeup, arginfo_class_DateTimeInterface___wakeup)
ZEND_ABSTRACT_ME_WITH_FLAGS(DateTimeInterface, format, arginfo_class_DateTimeInterface_format, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
ZEND_ABSTRACT_ME_WITH_FLAGS(DateTimeInterface, getTimezone, arginfo_class_DateTimeInterface_getTimezone, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
ZEND_ABSTRACT_ME_WITH_FLAGS(DateTimeInterface, getOffset, arginfo_class_DateTimeInterface_getOffset, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
ZEND_ABSTRACT_ME_WITH_FLAGS(DateTimeInterface, getTimestamp, arginfo_class_DateTimeInterface_getTimestamp, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
ZEND_ABSTRACT_ME_WITH_FLAGS(DateTimeInterface, diff, arginfo_class_DateTimeInterface_diff, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
ZEND_ABSTRACT_ME_WITH_FLAGS(DateTimeInterface, __wakeup, arginfo_class_DateTimeInterface___wakeup, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
ZEND_FE_END
};

Expand Down
11 changes: 0 additions & 11 deletions ext/dom/documenttype.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@
#if HAVE_LIBXML && HAVE_DOM
#include "php_dom.h"

/*
* class DOMDocumentType extends DOMNode
*
* URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-412266927
* Since:
*/

const zend_function_entry php_dom_documenttype_class_functions[] = {
PHP_FE_END
};

/* {{{ name string
readonly=yes
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1844763134
Expand Down
5 changes: 5 additions & 0 deletions ext/dom/dom_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(dom_import_simplexml, arginfo_dom_import_simplexml)
ZEND_FE_END
};


static const zend_function_entry class_DOMDocumentType_methods[] = {
ZEND_FE_END
};
1 change: 0 additions & 1 deletion ext/dom/dom_fe.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ extern const zend_function_entry php_dom_element_class_functions[];
extern const zend_function_entry php_dom_text_class_functions[];
extern const zend_function_entry php_dom_comment_class_functions[];
extern const zend_function_entry php_dom_cdatasection_class_functions[];
extern const zend_function_entry php_dom_documenttype_class_functions[];
extern const zend_function_entry php_dom_notation_class_functions[];
extern const zend_function_entry php_dom_entity_class_functions[];
extern const zend_function_entry php_dom_entityreference_class_functions[];
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ PHP_MINIT_FUNCTION(dom)
REGISTER_DOM_CLASS(ce, "DOMCdataSection", dom_text_class_entry, php_dom_cdatasection_class_functions, dom_cdatasection_class_entry);
zend_hash_add_ptr(&classes, ce.name, &dom_text_prop_handlers);

REGISTER_DOM_CLASS(ce, "DOMDocumentType", dom_node_class_entry, php_dom_documenttype_class_functions, dom_documenttype_class_entry);
REGISTER_DOM_CLASS(ce, "DOMDocumentType", dom_node_class_entry, class_DOMDocumentType_methods, dom_documenttype_class_entry);

zend_hash_init(&dom_documenttype_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
dom_register_prop_handler(&dom_documenttype_prop_handlers, "name", sizeof("name")-1, dom_documenttype_name_read, NULL);
Expand Down
13 changes: 1 addition & 12 deletions ext/fileinfo/fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,6 @@ PHP_FILEINFO_API zend_object *finfo_objects_new(zend_class_entry *class_type)
}
/* }}} */

/* {{{ finfo_class_functions
*/
static const zend_function_entry finfo_class_functions[] = {
ZEND_ME_MAPPING(__construct, finfo_open, arginfo_class_finfo___construct, ZEND_ACC_PUBLIC)
ZEND_ME_MAPPING(set_flags, finfo_set_flags,arginfo_class_finfo_set_flags, ZEND_ACC_PUBLIC)
ZEND_ME_MAPPING(file, finfo_file, arginfo_class_finfo_file, ZEND_ACC_PUBLIC)
ZEND_ME_MAPPING(buffer, finfo_buffer, arginfo_class_finfo_buffer, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */

#define FINFO_SET_OPTION(magic, options) \
if (magic_setflags(magic, options) == -1) { \
php_error_docref(NULL, E_WARNING, "Failed to set option '" ZEND_LONG_FMT "' %d:%s", \
Expand Down Expand Up @@ -145,7 +134,7 @@ void finfo_resource_destructor(zend_resource *rsrc) /* {{{ */
PHP_MINIT_FUNCTION(finfo)
{
zend_class_entry _finfo_class_entry;
INIT_CLASS_ENTRY(_finfo_class_entry, "finfo", finfo_class_functions);
INIT_CLASS_ENTRY(_finfo_class_entry, "finfo", class_finfo_methods);
_finfo_class_entry.create_object = finfo_objects_new;
finfo_class_entry = zend_register_internal_class(&_finfo_class_entry);

Expand Down
8 changes: 7 additions & 1 deletion ext/fileinfo/fileinfo.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@

class finfo
{
/** @alias finfo_open */
public function __construct(int $options = FILEINFO_NONE, string $arg = "") {}

/**
* @param ?resource $context
* @return string|false
* @alias finfo_file
*/
public function file(string $file_name, int $options = FILEINFO_NONE, $context = null) {}

/**
* @param ?resource $context
* @return string|false
* @alias finfo_buffer
*/
public function buffer(string $string, int $options = FILEINFO_NONE, $context = null) {}

/** @return bool */
/**
* @return bool
* @alias finfo_set_flags
*/
public function set_flags(int $options) {}
}

Expand Down
9 changes: 9 additions & 0 deletions ext/fileinfo/fileinfo_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(mime_content_type, arginfo_mime_content_type)
ZEND_FE_END
};


static const zend_function_entry class_finfo_methods[] = {
ZEND_ME_MAPPING(__construct, finfo_open, arginfo_class_finfo___construct, ZEND_ACC_PUBLIC)
ZEND_ME_MAPPING(file, finfo_file, arginfo_class_finfo_file, ZEND_ACC_PUBLIC)
ZEND_ME_MAPPING(buffer, finfo_buffer, arginfo_class_finfo_buffer, ZEND_ACC_PUBLIC)
ZEND_ME_MAPPING(set_flags, finfo_set_flags, arginfo_class_finfo_set_flags, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
9 changes: 2 additions & 7 deletions ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,17 +887,12 @@ PHP_FUNCTION(hash_equals)
/* }}} */

/* {{{ proto HashContext::__construct() */
static PHP_METHOD(HashContext, __construct) {
PHP_METHOD(HashContext, __construct) {
/* Normally unreachable as private/final */
zend_throw_exception(zend_ce_error, "Illegal call to private/final constructor", 0);
}
/* }}} */

static const zend_function_entry php_hashcontext_methods[] = {
PHP_ME(HashContext, __construct, arginfo_class_HashContext___construct, ZEND_ACC_PRIVATE)
PHP_FE_END
};

/* Module Housekeeping */

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

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

INIT_CLASS_ENTRY(ce, "HashContext", php_hashcontext_methods);
INIT_CLASS_ENTRY(ce, "HashContext", class_HashContext_methods);
php_hashcontext_ce = zend_register_internal_class(&ce);
php_hashcontext_ce->ce_flags |= ZEND_ACC_FINAL;
php_hashcontext_ce->create_object = php_hashcontext_create;
Expand Down
7 changes: 7 additions & 0 deletions ext/hash/hash_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ ZEND_FUNCTION(mhash_count);
#if defined(PHP_MHASH_BC)
ZEND_FUNCTION(mhash);
#endif
ZEND_METHOD(HashContext, __construct);


static const zend_function_entry ext_functions[] = {
Expand Down Expand Up @@ -183,3 +184,9 @@ static const zend_function_entry ext_functions[] = {
#endif
ZEND_FE_END
};


static const zend_function_entry class_HashContext_methods[] = {
ZEND_ME(HashContext, __construct, arginfo_class_HashContext___construct, ZEND_ACC_PRIVATE)
ZEND_FE_END
};
9 changes: 1 addition & 8 deletions ext/json/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ PHP_JSON_API zend_class_entry *php_json_exception_ce;

PHP_JSON_API ZEND_DECLARE_MODULE_GLOBALS(json)

/* {{{ JsonSerializable methods */
static const zend_function_entry json_serializable_interface[] = {
PHP_ABSTRACT_ME(JsonSerializable, jsonSerialize, arginfo_class_JsonSerializable_jsonSerialize)
PHP_FE_END
};
/* }}} */

/* Register constant for options and errors */
#define PHP_JSON_REGISTER_CONSTANT(_name, _value) \
REGISTER_LONG_CONSTANT(_name, _value, CONST_CS | CONST_PERSISTENT);
Expand All @@ -53,7 +46,7 @@ static PHP_MINIT_FUNCTION(json)
{
zend_class_entry ce;

INIT_CLASS_ENTRY(ce, "JsonSerializable", json_serializable_interface);
INIT_CLASS_ENTRY(ce, "JsonSerializable", class_JsonSerializable_methods);
php_json_serializable_ce = zend_register_internal_interface(&ce);

INIT_CLASS_ENTRY(ce, "JsonException", NULL);
Expand Down
Loading