Skip to content

Commit 23a3581

Browse files
committed
Improve gen_stub.php
Add support for generating deprecated function entries, as well as forward declaration of function aliases.
1 parent 7c30787 commit 23a3581

File tree

10 files changed

+311
-158
lines changed

10 files changed

+311
-158
lines changed

build/gen_stub.php

Lines changed: 27 additions & 7 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;
@@ -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 {
@@ -761,12 +767,22 @@ function(FuncInfo $funcInfo) use(&$generatedFuncInfos) {
761767

762768
if ($fileInfo->generateFunctionEntries) {
763769
$code .= "\n\n";
764-
$code .= generateCodeWithConditions($fileInfo->funcInfos, "", function(FuncInfo $funcInfo) {
770+
$code .= generateCodeWithConditions($funcInfos, "", function(FuncInfo $funcInfo) use ($funcInfos) {
771+
$result = "";
772+
765773
if ($funcInfo->alias) {
766-
return null;
774+
foreach ($funcInfos as $info) {
775+
if ($info->name === $funcInfo->alias) {
776+
return null;
777+
}
778+
}
779+
780+
$result .= "ZEND_FUNCTION($funcInfo->alias);\n";
767781
}
768782

769-
return "ZEND_FUNCTION($funcInfo->name);\n";
783+
$result .= "ZEND_FUNCTION($funcInfo->name);\n";
784+
785+
return $result;
770786
});
771787

772788
$code .= "\n\nstatic const zend_function_entry ext_functions[] = {\n";
@@ -776,9 +792,13 @@ function(FuncInfo $funcInfo) use(&$generatedFuncInfos) {
776792
"\tZEND_FALIAS(%s, %s, %s)\n",
777793
$funcInfo->name, $funcInfo->alias, $funcInfo->getArgInfoName()
778794
);
779-
} else {
780-
return sprintf("\tZEND_FE(%s, %s)\n", $funcInfo->name, $funcInfo->getArgInfoName());
781795
}
796+
797+
if ($funcInfo->isDeprecated) {
798+
return sprintf("\tZEND_DEP_FE(%s, %s)\n", $funcInfo->name, $funcInfo->getArgInfoName());
799+
}
800+
801+
return sprintf("\tZEND_FE(%s, %s)\n", $funcInfo->name, $funcInfo->getArgInfoName());
782802
});
783803
$code .= "\tZEND_FE_END\n";
784804
$code .= "};\n";

ext/bz2/bz2.c

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,11 @@
4141
static PHP_MINIT_FUNCTION(bz2);
4242
static PHP_MSHUTDOWN_FUNCTION(bz2);
4343
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-
};
6544

6645
zend_module_entry bz2_module_entry = {
6746
STANDARD_MODULE_HEADER,
6847
"bz2",
69-
bz2_functions,
48+
ext_functions,
7049
PHP_MINIT(bz2),
7150
PHP_MSHUTDOWN(bz2),
7251
NULL,
@@ -325,7 +304,7 @@ static PHP_MINFO_FUNCTION(bz2)
325304

326305
/* {{{ proto string bzread(resource bz[, int length])
327306
Reads up to length bytes from a BZip2 stream, or 1024 bytes if length is not specified */
328-
static PHP_FUNCTION(bzread)
307+
PHP_FUNCTION(bzread)
329308
{
330309
zval *bz;
331310
zend_long len = 1024;
@@ -353,7 +332,7 @@ static PHP_FUNCTION(bzread)
353332

354333
/* {{{ proto resource bzopen(string|int file|fp, string mode)
355334
Opens a new BZip2 stream */
356-
static PHP_FUNCTION(bzopen)
335+
PHP_FUNCTION(bzopen)
357336
{
358337
zval *file; /* The file to open */
359338
char *mode; /* The mode to open the stream with */
@@ -444,31 +423,31 @@ static PHP_FUNCTION(bzopen)
444423

445424
/* {{{ proto int bzerrno(resource bz)
446425
Returns the error number */
447-
static PHP_FUNCTION(bzerrno)
426+
PHP_FUNCTION(bzerrno)
448427
{
449428
php_bz2_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_BZ_ERRNO);
450429
}
451430
/* }}} */
452431

453432
/* {{{ proto string bzerrstr(resource bz)
454433
Returns the error string */
455-
static PHP_FUNCTION(bzerrstr)
434+
PHP_FUNCTION(bzerrstr)
456435
{
457436
php_bz2_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_BZ_ERRSTR);
458437
}
459438
/* }}} */
460439

461440
/* {{{ proto array bzerror(resource bz)
462441
Returns the error number and error string in an associative array */
463-
static PHP_FUNCTION(bzerror)
442+
PHP_FUNCTION(bzerror)
464443
{
465444
php_bz2_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_BZ_ERRBOTH);
466445
}
467446
/* }}} */
468447

469448
/* {{{ proto string bzcompress(string source [, int blocksize100k [, int workfactor]])
470449
Compresses a string into BZip2 encoded data */
471-
static PHP_FUNCTION(bzcompress)
450+
PHP_FUNCTION(bzcompress)
472451
{
473452
char *source; /* Source data to compress */
474453
zend_long zblock_size = 0; /* Optional block size to use */
@@ -519,7 +498,7 @@ static PHP_FUNCTION(bzcompress)
519498

520499
/* {{{ proto string bzdecompress(string source [, int small])
521500
Decompresses BZip2 compressed data */
522-
static PHP_FUNCTION(bzdecompress)
501+
PHP_FUNCTION(bzdecompress)
523502
{
524503
char *source;
525504
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,33 @@ 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(bzwrite);
53+
ZEND_FUNCTION(fflush);
54+
ZEND_FUNCTION(bzflush);
55+
ZEND_FUNCTION(fclose);
56+
ZEND_FUNCTION(bzclose);
57+
ZEND_FUNCTION(bzerrno);
58+
ZEND_FUNCTION(bzerrstr);
59+
ZEND_FUNCTION(bzerror);
60+
ZEND_FUNCTION(bzcompress);
61+
ZEND_FUNCTION(bzdecompress);
62+
63+
64+
static const zend_function_entry ext_functions[] = {
65+
ZEND_FE(bzopen, arginfo_bzopen)
66+
ZEND_FE(bzread, arginfo_bzread)
67+
ZEND_FALIAS(bzwrite, fwrite, arginfo_bzwrite)
68+
ZEND_FALIAS(bzflush, fflush, arginfo_bzflush)
69+
ZEND_FALIAS(bzclose, fclose, arginfo_bzclose)
70+
ZEND_FE(bzerrno, arginfo_bzerrno)
71+
ZEND_FE(bzerrstr, arginfo_bzerrstr)
72+
ZEND_FE(bzerror, arginfo_bzerror)
73+
ZEND_FE(bzcompress, arginfo_bzcompress)
74+
ZEND_FE(bzdecompress, arginfo_bzdecompress)
75+
ZEND_FE_END
76+
};

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)