Skip to content

Improve gen_stub.php #5350

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 2 commits 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
30 changes: 22 additions & 8 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ class FuncInfo {
public $className;
/** @var ?string */
public $alias;
/** @var bool */
public $isDeprecated;
/** @var ArgInfo[] */
public $args;
/** @var ReturnInfo */
Expand All @@ -314,12 +316,13 @@ class FuncInfo {
public $cond;

public function __construct(
string $name, ?string $className, ?string $alias, array $args, ReturnInfo $return,
string $name, ?string $className, ?string $alias, bool $isDeprecated, array $args, ReturnInfo $return,
int $numRequiredArgs, ?string $cond
) {
$this->name = $name;
$this->className = $className;
$this->alias = $alias;
$this->isDeprecated = $isDeprecated;
$this->args = $args;
$this->return = $return;
$this->numRequiredArgs = $numRequiredArgs;
Expand Down Expand Up @@ -419,7 +422,7 @@ function parseDocComment(DocComment $comment): array {
$commentText = substr($comment->getText(), 2, -2);
$tags = [];
foreach (explode("\n", $commentText) as $commentLine) {
$regex = '/^\*\s*@([a-z-]+)(?:\s+(.+))$/';
$regex = '/^\*\s*@([a-z-]+)(?:\s+(.+))?$/';
if (preg_match($regex, trim($commentLine), $matches, PREG_UNMATCHED_AS_NULL)) {
$tags[] = new DocCommentTag($matches[1], $matches[2]);
}
Expand All @@ -434,6 +437,7 @@ function parseFunctionLike(
$comment = $func->getDocComment();
$paramMeta = [];
$alias = null;
$isDeprecated = false;
$haveDocReturnType = false;

if ($comment) {
Expand All @@ -447,6 +451,8 @@ function parseFunctionLike(
$paramMeta[$varName]['preferRef'] = true;
} else if ($tag->name === 'alias') {
$alias = $tag->getValue();
} else if ($tag->name === 'deprecated') {
$isDeprecated = true;
} else if ($tag->name === 'return') {
$haveDocReturnType = true;
}
Expand Down Expand Up @@ -507,7 +513,7 @@ function parseFunctionLike(
$return = new ReturnInfo(
$func->returnsByRef(),
$returnType ? Type::fromNode($returnType) : null);
return new FuncInfo($name, $className, $alias, $args, $return, $numRequiredArgs, $cond);
return new FuncInfo($name, $className, $alias, $isDeprecated, $args, $return, $numRequiredArgs, $cond);
}

function handlePreprocessorConditions(array &$conds, Stmt $stmt): ?string {
Expand Down Expand Up @@ -737,6 +743,7 @@ function generateCodeWithConditions(
}

function generateArgInfoCode(FileInfo $fileInfo): string {
$generatedDeclarations = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable can be moved closer to where it is used.

Copy link
Member Author

@kocsismate kocsismate Apr 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to do this - but I'll fix it soon

$funcInfos = $fileInfo->funcInfos;

$code = "/* This is a generated file, edit the .stub.php file instead. */\n";
Expand All @@ -761,12 +768,15 @@ function(FuncInfo $funcInfo) use(&$generatedFuncInfos) {

if ($fileInfo->generateFunctionEntries) {
$code .= "\n\n";
$code .= generateCodeWithConditions($fileInfo->funcInfos, "", function(FuncInfo $funcInfo) {
if ($funcInfo->alias) {
$code .= generateCodeWithConditions($funcInfos, "", function(FuncInfo $funcInfo) use (&$generatedDeclarations) {
$name = $funcInfo->alias ?? $funcInfo->name;
$key = "$name|$funcInfo->cond";
if (isset($generatedDeclarations[$key])) {
return null;
}

return "ZEND_FUNCTION($funcInfo->name);\n";
$generatedDeclarations[$key] = true;
return "ZEND_FUNCTION($name);\n";
});

$code .= "\n\nstatic const zend_function_entry ext_functions[] = {\n";
Expand All @@ -776,9 +786,13 @@ function(FuncInfo $funcInfo) use(&$generatedFuncInfos) {
"\tZEND_FALIAS(%s, %s, %s)\n",
$funcInfo->name, $funcInfo->alias, $funcInfo->getArgInfoName()
);
} else {
return sprintf("\tZEND_FE(%s, %s)\n", $funcInfo->name, $funcInfo->getArgInfoName());
}

if ($funcInfo->isDeprecated) {
return sprintf("\tZEND_DEP_FE(%s, %s)\n", $funcInfo->name, $funcInfo->getArgInfoName());
}

return sprintf("\tZEND_FE(%s, %s)\n", $funcInfo->name, $funcInfo->getArgInfoName());
});
$code .= "\tZEND_FE_END\n";
$code .= "};\n";
Expand Down
38 changes: 8 additions & 30 deletions ext/bz2/bz2.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#if HAVE_BZ2

/* PHP Includes */
#include "ext/standard/file.h"
#include "ext/standard/info.h"
#include "ext/standard/php_string.h"
#include "main/php_network.h"
Expand All @@ -41,32 +40,11 @@
static PHP_MINIT_FUNCTION(bz2);
static PHP_MSHUTDOWN_FUNCTION(bz2);
static PHP_MINFO_FUNCTION(bz2);
static PHP_FUNCTION(bzopen);
static PHP_FUNCTION(bzread);
static PHP_FUNCTION(bzerrno);
static PHP_FUNCTION(bzerrstr);
static PHP_FUNCTION(bzerror);
static PHP_FUNCTION(bzcompress);
static PHP_FUNCTION(bzdecompress);

static const zend_function_entry bz2_functions[] = {
PHP_FE(bzopen, arginfo_bzopen)
PHP_FE(bzread, arginfo_bzread)
PHP_FALIAS(bzwrite, fwrite, arginfo_bzwrite)
PHP_FALIAS(bzflush, fflush, arginfo_bzflush)
PHP_FALIAS(bzclose, fclose, arginfo_bzclose)
PHP_FE(bzerrno, arginfo_bzerrno)
PHP_FE(bzerrstr, arginfo_bzerrstr)
PHP_FE(bzerror, arginfo_bzerror)
PHP_FE(bzcompress, arginfo_bzcompress)
PHP_FE(bzdecompress, arginfo_bzdecompress)
PHP_FE_END
};

zend_module_entry bz2_module_entry = {
STANDARD_MODULE_HEADER,
"bz2",
bz2_functions,
ext_functions,
PHP_MINIT(bz2),
PHP_MSHUTDOWN(bz2),
NULL,
Expand Down Expand Up @@ -325,7 +303,7 @@ static PHP_MINFO_FUNCTION(bz2)

/* {{{ proto string bzread(resource bz[, int length])
Reads up to length bytes from a BZip2 stream, or 1024 bytes if length is not specified */
static PHP_FUNCTION(bzread)
PHP_FUNCTION(bzread)
{
zval *bz;
zend_long len = 1024;
Expand Down Expand Up @@ -353,7 +331,7 @@ static PHP_FUNCTION(bzread)

/* {{{ proto resource bzopen(string|int file|fp, string mode)
Opens a new BZip2 stream */
static PHP_FUNCTION(bzopen)
PHP_FUNCTION(bzopen)
{
zval *file; /* The file to open */
char *mode; /* The mode to open the stream with */
Expand Down Expand Up @@ -444,31 +422,31 @@ static PHP_FUNCTION(bzopen)

/* {{{ proto int bzerrno(resource bz)
Returns the error number */
static PHP_FUNCTION(bzerrno)
PHP_FUNCTION(bzerrno)
{
php_bz2_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_BZ_ERRNO);
}
/* }}} */

/* {{{ proto string bzerrstr(resource bz)
Returns the error string */
static PHP_FUNCTION(bzerrstr)
PHP_FUNCTION(bzerrstr)
{
php_bz2_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_BZ_ERRSTR);
}
/* }}} */

/* {{{ proto array bzerror(resource bz)
Returns the error number and error string in an associative array */
static PHP_FUNCTION(bzerror)
PHP_FUNCTION(bzerror)
{
php_bz2_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_BZ_ERRBOTH);
}
/* }}} */

/* {{{ proto string bzcompress(string source [, int blocksize100k [, int workfactor]])
Compresses a string into BZip2 encoded data */
static PHP_FUNCTION(bzcompress)
PHP_FUNCTION(bzcompress)
{
char *source; /* Source data to compress */
zend_long zblock_size = 0; /* Optional block size to use */
Expand Down Expand Up @@ -519,7 +497,7 @@ static PHP_FUNCTION(bzcompress)

/* {{{ proto string bzdecompress(string source [, int small])
Decompresses BZip2 compressed data */
static PHP_FUNCTION(bzdecompress)
PHP_FUNCTION(bzdecompress)
{
char *source;
zend_string *dest;
Expand Down
2 changes: 2 additions & 0 deletions ext/bz2/bz2.stub.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

/** @generate-function-entries */

/**
* @param string|resource $file
* @return resource|false
Expand Down
27 changes: 27 additions & 0 deletions ext/bz2/bz2_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,30 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bzdecompress, 0, 1, MAY_BE_STRIN
ZEND_ARG_TYPE_INFO(0, source, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, small, IS_LONG, 0)
ZEND_END_ARG_INFO()


ZEND_FUNCTION(bzopen);
ZEND_FUNCTION(bzread);
ZEND_FUNCTION(fwrite);
ZEND_FUNCTION(fflush);
ZEND_FUNCTION(fclose);
ZEND_FUNCTION(bzerrno);
ZEND_FUNCTION(bzerrstr);
ZEND_FUNCTION(bzerror);
ZEND_FUNCTION(bzcompress);
ZEND_FUNCTION(bzdecompress);


static const zend_function_entry ext_functions[] = {
ZEND_FE(bzopen, arginfo_bzopen)
ZEND_FE(bzread, arginfo_bzread)
ZEND_FALIAS(bzwrite, fwrite, arginfo_bzwrite)
ZEND_FALIAS(bzflush, fflush, arginfo_bzflush)
ZEND_FALIAS(bzclose, fclose, arginfo_bzclose)
ZEND_FE(bzerrno, arginfo_bzerrno)
ZEND_FE(bzerrstr, arginfo_bzerrstr)
ZEND_FE(bzerror, arginfo_bzerror)
ZEND_FE(bzcompress, arginfo_bzcompress)
ZEND_FE(bzdecompress, arginfo_bzdecompress)
ZEND_FE_END
};
108 changes: 1 addition & 107 deletions ext/ldap/ldap.c
Original file line number Diff line number Diff line change
Expand Up @@ -4374,116 +4374,10 @@ PHP_FUNCTION(ldap_exop_refresh)
/* }}} */
#endif

/* }}} */

/*
This is just a small subset of the functionality provided by the LDAP library. All the
operations are synchronous. Referrals are not handled automatically.
*/
/* {{{ ldap_functions[]
*/
static const zend_function_entry ldap_functions[] = {
PHP_FE(ldap_connect, arginfo_ldap_connect)
PHP_FALIAS(ldap_close, ldap_unbind, arginfo_ldap_close)
PHP_FE(ldap_bind, arginfo_ldap_bind)
PHP_FE(ldap_bind_ext, arginfo_ldap_bind_ext)
#ifdef HAVE_LDAP_SASL
PHP_FE(ldap_sasl_bind, arginfo_ldap_sasl_bind)
#endif
PHP_FE(ldap_unbind, arginfo_ldap_unbind)
PHP_FE(ldap_read, arginfo_ldap_read)
PHP_FE(ldap_list, arginfo_ldap_list)
PHP_FE(ldap_search, arginfo_ldap_search)
PHP_FE(ldap_free_result, arginfo_ldap_free_result)
PHP_FE(ldap_count_entries, arginfo_ldap_count_entries)
PHP_FE(ldap_first_entry, arginfo_ldap_first_entry)
PHP_FE(ldap_next_entry, arginfo_ldap_next_entry)
PHP_FE(ldap_get_entries, arginfo_ldap_get_entries)
PHP_FE(ldap_first_attribute, arginfo_ldap_first_attribute)
PHP_FE(ldap_next_attribute, arginfo_ldap_next_attribute)
PHP_FE(ldap_get_attributes, arginfo_ldap_get_attributes)
PHP_FALIAS(ldap_get_values, ldap_get_values_len, arginfo_ldap_get_values)
PHP_FE(ldap_get_values_len, arginfo_ldap_get_values_len)
PHP_FE(ldap_get_dn, arginfo_ldap_get_dn)
PHP_FE(ldap_explode_dn, arginfo_ldap_explode_dn)
PHP_FE(ldap_dn2ufn, arginfo_ldap_dn2ufn)
PHP_FE(ldap_add, arginfo_ldap_add)
PHP_FE(ldap_add_ext, arginfo_ldap_add_ext)
PHP_FE(ldap_delete, arginfo_ldap_delete)
PHP_FE(ldap_delete_ext, arginfo_ldap_delete_ext)
PHP_FE(ldap_modify_batch, arginfo_ldap_modify_batch)
PHP_FALIAS(ldap_modify, ldap_mod_replace, arginfo_ldap_modify)

/* additional functions for attribute based modifications, Gerrit Thomson */
PHP_FE(ldap_mod_add, arginfo_ldap_mod_add)
PHP_FE(ldap_mod_add_ext, arginfo_ldap_mod_add_ext)
PHP_FE(ldap_mod_replace, arginfo_ldap_mod_replace)
PHP_FE(ldap_mod_replace_ext, arginfo_ldap_mod_replace_ext)
PHP_FE(ldap_mod_del, arginfo_ldap_mod_del)
PHP_FE(ldap_mod_del_ext, arginfo_ldap_mod_del_ext)
/* end gjt mod */

PHP_FE(ldap_errno, arginfo_ldap_errno)
PHP_FE(ldap_err2str, arginfo_ldap_err2str)
PHP_FE(ldap_error, arginfo_ldap_error)
PHP_FE(ldap_compare, arginfo_ldap_compare)

#if (LDAP_API_VERSION > 2000) || HAVE_ORALDAP
PHP_FE(ldap_rename, arginfo_ldap_rename)
PHP_FE(ldap_rename_ext, arginfo_ldap_rename_ext)
PHP_FE(ldap_get_option, arginfo_ldap_get_option)
PHP_FE(ldap_set_option, arginfo_ldap_set_option)
PHP_FE(ldap_first_reference, arginfo_ldap_first_reference)
PHP_FE(ldap_next_reference, arginfo_ldap_next_reference)
#ifdef HAVE_LDAP_PARSE_REFERENCE
PHP_FE(ldap_parse_reference, arginfo_ldap_parse_reference)
#endif
#ifdef HAVE_LDAP_PARSE_RESULT
PHP_FE(ldap_parse_result, arginfo_ldap_parse_result)
#endif
#ifdef HAVE_LDAP_START_TLS_S
PHP_FE(ldap_start_tls, arginfo_ldap_start_tls)
#endif
#ifdef HAVE_LDAP_EXTENDED_OPERATION_S
PHP_FE(ldap_exop, arginfo_ldap_exop)
#endif
#ifdef HAVE_LDAP_PASSWD
PHP_FE(ldap_exop_passwd, arginfo_ldap_exop_passwd)
#endif
#ifdef HAVE_LDAP_WHOAMI_S
PHP_FE(ldap_exop_whoami, arginfo_ldap_exop_whoami)
#endif
#ifdef HAVE_LDAP_REFRESH_S
PHP_FE(ldap_exop_refresh, arginfo_ldap_exop_refresh)
#endif
#ifdef HAVE_LDAP_PARSE_EXTENDED_RESULT
PHP_FE(ldap_parse_exop, arginfo_ldap_parse_exop)
#endif
#endif

#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
PHP_FE(ldap_set_rebind_proc, arginfo_ldap_set_rebind_proc)
#endif

PHP_FE(ldap_escape, arginfo_ldap_escape)

#ifdef STR_TRANSLATION
PHP_FE(ldap_t61_to_8859, arginfo_ldap_t61_to_8859)
PHP_FE(ldap_8859_to_t61, arginfo_ldap_8859_to_t61)
#endif

#ifdef LDAP_CONTROL_PAGEDRESULTS
PHP_DEP_FE(ldap_control_paged_result, arginfo_ldap_control_paged_result)
PHP_DEP_FE(ldap_control_paged_result_response, arginfo_ldap_control_paged_result_response)
#endif
PHP_FE_END
};
/* }}} */

zend_module_entry ldap_module_entry = { /* {{{ */
STANDARD_MODULE_HEADER,
"ldap",
ldap_functions,
ext_functions,
PHP_MINIT(ldap),
PHP_MSHUTDOWN(ldap),
NULL,
Expand Down
8 changes: 6 additions & 2 deletions ext/ldap/ldap.stub.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

//TODO: missing arginfo functions defined in C using
/** @generate-function-entries */

#ifdef HAVE_ORALDAP
/** @return resource|false */
Expand Down Expand Up @@ -195,12 +195,16 @@ function ldap_compare($link_identifier, string $dn, string $attribute, string $v


#ifdef LDAP_CONTROL_PAGEDRESULTS
/** @param resource $link */
/**
* @param resource $link
* @deprecated since 7.4
*/
function ldap_control_paged_result($link, int $pagesize, bool $iscritical = false, string $cookie = ''): bool {}

/**
* @param resource $link
* @param resource $result
* @deprecated since 7.4
*/
function ldap_control_paged_result_response($link, $result, &$cookie = null, &$estimated = null): bool {}
#endif
Expand Down
Loading