Skip to content

Commit 610815c

Browse files
committed
Improve gen_stub.php
Closes GH-5350 Add support for generating deprecated function entries, as well as forward declaration of function aliases.
1 parent 7c30787 commit 610815c

File tree

10 files changed

+303
-160
lines changed

10 files changed

+303
-160
lines changed

build/gen_stub.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ class FuncInfo {
304304
public $className;
305305
/** @var ?string */
306306
public $alias;
307+
/** @var bool */
308+
public $isDeprecated;
307309
/** @var ArgInfo[] */
308310
public $args;
309311
/** @var ReturnInfo */
@@ -314,12 +316,13 @@ class FuncInfo {
314316
public $cond;
315317

316318
public function __construct(
317-
string $name, ?string $className, ?string $alias, array $args, ReturnInfo $return,
319+
string $name, ?string $className, ?string $alias, bool $isDeprecated, array $args, ReturnInfo $return,
318320
int $numRequiredArgs, ?string $cond
319321
) {
320322
$this->name = $name;
321323
$this->className = $className;
322324
$this->alias = $alias;
325+
$this->isDeprecated = $isDeprecated;
323326
$this->args = $args;
324327
$this->return = $return;
325328
$this->numRequiredArgs = $numRequiredArgs;
@@ -419,7 +422,7 @@ function parseDocComment(DocComment $comment): array {
419422
$commentText = substr($comment->getText(), 2, -2);
420423
$tags = [];
421424
foreach (explode("\n", $commentText) as $commentLine) {
422-
$regex = '/^\*\s*@([a-z-]+)(?:\s+(.+))$/';
425+
$regex = '/^\*\s*@([a-z-]+)(?:\s+(.+))?$/';
423426
if (preg_match($regex, trim($commentLine), $matches, PREG_UNMATCHED_AS_NULL)) {
424427
$tags[] = new DocCommentTag($matches[1], $matches[2]);
425428
}
@@ -434,6 +437,7 @@ function parseFunctionLike(
434437
$comment = $func->getDocComment();
435438
$paramMeta = [];
436439
$alias = null;
440+
$isDeprecated = false;
437441
$haveDocReturnType = false;
438442

439443
if ($comment) {
@@ -447,6 +451,8 @@ function parseFunctionLike(
447451
$paramMeta[$varName]['preferRef'] = true;
448452
} else if ($tag->name === 'alias') {
449453
$alias = $tag->getValue();
454+
} else if ($tag->name === 'deprecated') {
455+
$isDeprecated = true;
450456
} else if ($tag->name === 'return') {
451457
$haveDocReturnType = true;
452458
}
@@ -507,7 +513,7 @@ function parseFunctionLike(
507513
$return = new ReturnInfo(
508514
$func->returnsByRef(),
509515
$returnType ? Type::fromNode($returnType) : null);
510-
return new FuncInfo($name, $className, $alias, $args, $return, $numRequiredArgs, $cond);
516+
return new FuncInfo($name, $className, $alias, $isDeprecated, $args, $return, $numRequiredArgs, $cond);
511517
}
512518

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

739745
function generateArgInfoCode(FileInfo $fileInfo): string {
746+
$generatedDeclarations = [];
740747
$funcInfos = $fileInfo->funcInfos;
741748

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

762769
if ($fileInfo->generateFunctionEntries) {
763770
$code .= "\n\n";
764-
$code .= generateCodeWithConditions($fileInfo->funcInfos, "", function(FuncInfo $funcInfo) {
765-
if ($funcInfo->alias) {
771+
$code .= generateCodeWithConditions($funcInfos, "", function(FuncInfo $funcInfo) use (&$generatedDeclarations) {
772+
$name = $funcInfo->alias ?? $funcInfo->name;
773+
$key = "$name|$funcInfo->cond";
774+
if (isset($generatedDeclarations[$key])) {
766775
return null;
767776
}
768777

769-
return "ZEND_FUNCTION($funcInfo->name);\n";
778+
$generatedDeclarations[$key] = true;
779+
return "ZEND_FUNCTION($name);\n";
770780
});
771781

772782
$code .= "\n\nstatic const zend_function_entry ext_functions[] = {\n";
@@ -776,9 +786,13 @@ function(FuncInfo $funcInfo) use(&$generatedFuncInfos) {
776786
"\tZEND_FALIAS(%s, %s, %s)\n",
777787
$funcInfo->name, $funcInfo->alias, $funcInfo->getArgInfoName()
778788
);
779-
} else {
780-
return sprintf("\tZEND_FE(%s, %s)\n", $funcInfo->name, $funcInfo->getArgInfoName());
781789
}
790+
791+
if ($funcInfo->isDeprecated) {
792+
return sprintf("\tZEND_DEP_FE(%s, %s)\n", $funcInfo->name, $funcInfo->getArgInfoName());
793+
}
794+
795+
return sprintf("\tZEND_FE(%s, %s)\n", $funcInfo->name, $funcInfo->getArgInfoName());
782796
});
783797
$code .= "\tZEND_FE_END\n";
784798
$code .= "};\n";

ext/bz2/bz2.c

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#if HAVE_BZ2
2626

2727
/* PHP Includes */
28-
#include "ext/standard/file.h"
2928
#include "ext/standard/info.h"
3029
#include "ext/standard/php_string.h"
3130
#include "main/php_network.h"
@@ -41,32 +40,11 @@
4140
static PHP_MINIT_FUNCTION(bz2);
4241
static PHP_MSHUTDOWN_FUNCTION(bz2);
4342
static PHP_MINFO_FUNCTION(bz2);
44-
static PHP_FUNCTION(bzopen);
45-
static PHP_FUNCTION(bzread);
46-
static PHP_FUNCTION(bzerrno);
47-
static PHP_FUNCTION(bzerrstr);
48-
static PHP_FUNCTION(bzerror);
49-
static PHP_FUNCTION(bzcompress);
50-
static PHP_FUNCTION(bzdecompress);
51-
52-
static const zend_function_entry bz2_functions[] = {
53-
PHP_FE(bzopen, arginfo_bzopen)
54-
PHP_FE(bzread, arginfo_bzread)
55-
PHP_FALIAS(bzwrite, fwrite, arginfo_bzwrite)
56-
PHP_FALIAS(bzflush, fflush, arginfo_bzflush)
57-
PHP_FALIAS(bzclose, fclose, arginfo_bzclose)
58-
PHP_FE(bzerrno, arginfo_bzerrno)
59-
PHP_FE(bzerrstr, arginfo_bzerrstr)
60-
PHP_FE(bzerror, arginfo_bzerror)
61-
PHP_FE(bzcompress, arginfo_bzcompress)
62-
PHP_FE(bzdecompress, arginfo_bzdecompress)
63-
PHP_FE_END
64-
};
6543

6644
zend_module_entry bz2_module_entry = {
6745
STANDARD_MODULE_HEADER,
6846
"bz2",
69-
bz2_functions,
47+
ext_functions,
7048
PHP_MINIT(bz2),
7149
PHP_MSHUTDOWN(bz2),
7250
NULL,
@@ -325,7 +303,7 @@ static PHP_MINFO_FUNCTION(bz2)
325303

326304
/* {{{ proto string bzread(resource bz[, int length])
327305
Reads up to length bytes from a BZip2 stream, or 1024 bytes if length is not specified */
328-
static PHP_FUNCTION(bzread)
306+
PHP_FUNCTION(bzread)
329307
{
330308
zval *bz;
331309
zend_long len = 1024;
@@ -353,7 +331,7 @@ static PHP_FUNCTION(bzread)
353331

354332
/* {{{ proto resource bzopen(string|int file|fp, string mode)
355333
Opens a new BZip2 stream */
356-
static PHP_FUNCTION(bzopen)
334+
PHP_FUNCTION(bzopen)
357335
{
358336
zval *file; /* The file to open */
359337
char *mode; /* The mode to open the stream with */
@@ -444,31 +422,31 @@ static PHP_FUNCTION(bzopen)
444422

445423
/* {{{ proto int bzerrno(resource bz)
446424
Returns the error number */
447-
static PHP_FUNCTION(bzerrno)
425+
PHP_FUNCTION(bzerrno)
448426
{
449427
php_bz2_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_BZ_ERRNO);
450428
}
451429
/* }}} */
452430

453431
/* {{{ proto string bzerrstr(resource bz)
454432
Returns the error string */
455-
static PHP_FUNCTION(bzerrstr)
433+
PHP_FUNCTION(bzerrstr)
456434
{
457435
php_bz2_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_BZ_ERRSTR);
458436
}
459437
/* }}} */
460438

461439
/* {{{ proto array bzerror(resource bz)
462440
Returns the error number and error string in an associative array */
463-
static PHP_FUNCTION(bzerror)
441+
PHP_FUNCTION(bzerror)
464442
{
465443
php_bz2_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_BZ_ERRBOTH);
466444
}
467445
/* }}} */
468446

469447
/* {{{ proto string bzcompress(string source [, int blocksize100k [, int workfactor]])
470448
Compresses a string into BZip2 encoded data */
471-
static PHP_FUNCTION(bzcompress)
449+
PHP_FUNCTION(bzcompress)
472450
{
473451
char *source; /* Source data to compress */
474452
zend_long zblock_size = 0; /* Optional block size to use */
@@ -519,7 +497,7 @@ static PHP_FUNCTION(bzcompress)
519497

520498
/* {{{ proto string bzdecompress(string source [, int small])
521499
Decompresses BZip2 compressed data */
522-
static PHP_FUNCTION(bzdecompress)
500+
PHP_FUNCTION(bzdecompress)
523501
{
524502
char *source;
525503
zend_string *dest;

ext/bz2/bz2.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
/** @generate-function-entries */
4+
35
/**
46
* @param string|resource $file
57
* @return resource|false

ext/bz2/bz2_arginfo.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,30 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bzdecompress, 0, 1, MAY_BE_STRIN
4444
ZEND_ARG_TYPE_INFO(0, source, IS_STRING, 0)
4545
ZEND_ARG_TYPE_INFO(0, small, IS_LONG, 0)
4646
ZEND_END_ARG_INFO()
47+
48+
49+
ZEND_FUNCTION(bzopen);
50+
ZEND_FUNCTION(bzread);
51+
ZEND_FUNCTION(fwrite);
52+
ZEND_FUNCTION(fflush);
53+
ZEND_FUNCTION(fclose);
54+
ZEND_FUNCTION(bzerrno);
55+
ZEND_FUNCTION(bzerrstr);
56+
ZEND_FUNCTION(bzerror);
57+
ZEND_FUNCTION(bzcompress);
58+
ZEND_FUNCTION(bzdecompress);
59+
60+
61+
static const zend_function_entry ext_functions[] = {
62+
ZEND_FE(bzopen, arginfo_bzopen)
63+
ZEND_FE(bzread, arginfo_bzread)
64+
ZEND_FALIAS(bzwrite, fwrite, arginfo_bzwrite)
65+
ZEND_FALIAS(bzflush, fflush, arginfo_bzflush)
66+
ZEND_FALIAS(bzclose, fclose, arginfo_bzclose)
67+
ZEND_FE(bzerrno, arginfo_bzerrno)
68+
ZEND_FE(bzerrstr, arginfo_bzerrstr)
69+
ZEND_FE(bzerror, arginfo_bzerror)
70+
ZEND_FE(bzcompress, arginfo_bzcompress)
71+
ZEND_FE(bzdecompress, arginfo_bzdecompress)
72+
ZEND_FE_END
73+
};

ext/ldap/ldap.c

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -4374,116 +4374,10 @@ PHP_FUNCTION(ldap_exop_refresh)
43744374
/* }}} */
43754375
#endif
43764376

4377-
/* }}} */
4378-
4379-
/*
4380-
This is just a small subset of the functionality provided by the LDAP library. All the
4381-
operations are synchronous. Referrals are not handled automatically.
4382-
*/
4383-
/* {{{ ldap_functions[]
4384-
*/
4385-
static const zend_function_entry ldap_functions[] = {
4386-
PHP_FE(ldap_connect, arginfo_ldap_connect)
4387-
PHP_FALIAS(ldap_close, ldap_unbind, arginfo_ldap_close)
4388-
PHP_FE(ldap_bind, arginfo_ldap_bind)
4389-
PHP_FE(ldap_bind_ext, arginfo_ldap_bind_ext)
4390-
#ifdef HAVE_LDAP_SASL
4391-
PHP_FE(ldap_sasl_bind, arginfo_ldap_sasl_bind)
4392-
#endif
4393-
PHP_FE(ldap_unbind, arginfo_ldap_unbind)
4394-
PHP_FE(ldap_read, arginfo_ldap_read)
4395-
PHP_FE(ldap_list, arginfo_ldap_list)
4396-
PHP_FE(ldap_search, arginfo_ldap_search)
4397-
PHP_FE(ldap_free_result, arginfo_ldap_free_result)
4398-
PHP_FE(ldap_count_entries, arginfo_ldap_count_entries)
4399-
PHP_FE(ldap_first_entry, arginfo_ldap_first_entry)
4400-
PHP_FE(ldap_next_entry, arginfo_ldap_next_entry)
4401-
PHP_FE(ldap_get_entries, arginfo_ldap_get_entries)
4402-
PHP_FE(ldap_first_attribute, arginfo_ldap_first_attribute)
4403-
PHP_FE(ldap_next_attribute, arginfo_ldap_next_attribute)
4404-
PHP_FE(ldap_get_attributes, arginfo_ldap_get_attributes)
4405-
PHP_FALIAS(ldap_get_values, ldap_get_values_len, arginfo_ldap_get_values)
4406-
PHP_FE(ldap_get_values_len, arginfo_ldap_get_values_len)
4407-
PHP_FE(ldap_get_dn, arginfo_ldap_get_dn)
4408-
PHP_FE(ldap_explode_dn, arginfo_ldap_explode_dn)
4409-
PHP_FE(ldap_dn2ufn, arginfo_ldap_dn2ufn)
4410-
PHP_FE(ldap_add, arginfo_ldap_add)
4411-
PHP_FE(ldap_add_ext, arginfo_ldap_add_ext)
4412-
PHP_FE(ldap_delete, arginfo_ldap_delete)
4413-
PHP_FE(ldap_delete_ext, arginfo_ldap_delete_ext)
4414-
PHP_FE(ldap_modify_batch, arginfo_ldap_modify_batch)
4415-
PHP_FALIAS(ldap_modify, ldap_mod_replace, arginfo_ldap_modify)
4416-
4417-
/* additional functions for attribute based modifications, Gerrit Thomson */
4418-
PHP_FE(ldap_mod_add, arginfo_ldap_mod_add)
4419-
PHP_FE(ldap_mod_add_ext, arginfo_ldap_mod_add_ext)
4420-
PHP_FE(ldap_mod_replace, arginfo_ldap_mod_replace)
4421-
PHP_FE(ldap_mod_replace_ext, arginfo_ldap_mod_replace_ext)
4422-
PHP_FE(ldap_mod_del, arginfo_ldap_mod_del)
4423-
PHP_FE(ldap_mod_del_ext, arginfo_ldap_mod_del_ext)
4424-
/* end gjt mod */
4425-
4426-
PHP_FE(ldap_errno, arginfo_ldap_errno)
4427-
PHP_FE(ldap_err2str, arginfo_ldap_err2str)
4428-
PHP_FE(ldap_error, arginfo_ldap_error)
4429-
PHP_FE(ldap_compare, arginfo_ldap_compare)
4430-
4431-
#if (LDAP_API_VERSION > 2000) || HAVE_ORALDAP
4432-
PHP_FE(ldap_rename, arginfo_ldap_rename)
4433-
PHP_FE(ldap_rename_ext, arginfo_ldap_rename_ext)
4434-
PHP_FE(ldap_get_option, arginfo_ldap_get_option)
4435-
PHP_FE(ldap_set_option, arginfo_ldap_set_option)
4436-
PHP_FE(ldap_first_reference, arginfo_ldap_first_reference)
4437-
PHP_FE(ldap_next_reference, arginfo_ldap_next_reference)
4438-
#ifdef HAVE_LDAP_PARSE_REFERENCE
4439-
PHP_FE(ldap_parse_reference, arginfo_ldap_parse_reference)
4440-
#endif
4441-
#ifdef HAVE_LDAP_PARSE_RESULT
4442-
PHP_FE(ldap_parse_result, arginfo_ldap_parse_result)
4443-
#endif
4444-
#ifdef HAVE_LDAP_START_TLS_S
4445-
PHP_FE(ldap_start_tls, arginfo_ldap_start_tls)
4446-
#endif
4447-
#ifdef HAVE_LDAP_EXTENDED_OPERATION_S
4448-
PHP_FE(ldap_exop, arginfo_ldap_exop)
4449-
#endif
4450-
#ifdef HAVE_LDAP_PASSWD
4451-
PHP_FE(ldap_exop_passwd, arginfo_ldap_exop_passwd)
4452-
#endif
4453-
#ifdef HAVE_LDAP_WHOAMI_S
4454-
PHP_FE(ldap_exop_whoami, arginfo_ldap_exop_whoami)
4455-
#endif
4456-
#ifdef HAVE_LDAP_REFRESH_S
4457-
PHP_FE(ldap_exop_refresh, arginfo_ldap_exop_refresh)
4458-
#endif
4459-
#ifdef HAVE_LDAP_PARSE_EXTENDED_RESULT
4460-
PHP_FE(ldap_parse_exop, arginfo_ldap_parse_exop)
4461-
#endif
4462-
#endif
4463-
4464-
#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
4465-
PHP_FE(ldap_set_rebind_proc, arginfo_ldap_set_rebind_proc)
4466-
#endif
4467-
4468-
PHP_FE(ldap_escape, arginfo_ldap_escape)
4469-
4470-
#ifdef STR_TRANSLATION
4471-
PHP_FE(ldap_t61_to_8859, arginfo_ldap_t61_to_8859)
4472-
PHP_FE(ldap_8859_to_t61, arginfo_ldap_8859_to_t61)
4473-
#endif
4474-
4475-
#ifdef LDAP_CONTROL_PAGEDRESULTS
4476-
PHP_DEP_FE(ldap_control_paged_result, arginfo_ldap_control_paged_result)
4477-
PHP_DEP_FE(ldap_control_paged_result_response, arginfo_ldap_control_paged_result_response)
4478-
#endif
4479-
PHP_FE_END
4480-
};
4481-
/* }}} */
4482-
44834377
zend_module_entry ldap_module_entry = { /* {{{ */
44844378
STANDARD_MODULE_HEADER,
44854379
"ldap",
4486-
ldap_functions,
4380+
ext_functions,
44874381
PHP_MINIT(ldap),
44884382
PHP_MSHUTDOWN(ldap),
44894383
NULL,

ext/ldap/ldap.stub.php

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

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

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

196196

197197
#ifdef LDAP_CONTROL_PAGEDRESULTS
198-
/** @param resource $link */
198+
/**
199+
* @param resource $link
200+
* @deprecated since 7.4
201+
*/
199202
function ldap_control_paged_result($link, int $pagesize, bool $iscritical = false, string $cookie = ''): bool {}
200203

201204
/**
202205
* @param resource $link
203206
* @param resource $result
207+
* @deprecated since 7.4
204208
*/
205209
function ldap_control_paged_result_response($link, $result, &$cookie = null, &$estimated = null): bool {}
206210
#endif

0 commit comments

Comments
 (0)