Skip to content

Commit dfa6d1c

Browse files
committed
Support specifying linkage for generate-function-entries
The linkage can be specified as the argument to the @generate-function-entries tag. Test this on zend_test.
1 parent 924ac2b commit dfa6d1c

File tree

4 files changed

+45
-40
lines changed

4 files changed

+45
-40
lines changed

build/gen_stub.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ class FileInfo {
624624
public $classInfos = [];
625625
/** @var bool */
626626
public $generateFunctionEntries = false;
627+
/** @var string */
628+
public $declarationPrefix = "";
627629

628630
/**
629631
* @return iterable<FuncInfo>
@@ -941,8 +943,12 @@ protected function pName_FullyQualified(Name\FullyQualified $node) {
941943
$fileInfo = new FileInfo;
942944
$fileDocComment = getFileDocComment($stmts);
943945
if ($fileDocComment) {
944-
if (strpos($fileDocComment->getText(), '@generate-function-entries') !== false) {
945-
$fileInfo->generateFunctionEntries = true;
946+
$fileTags = parseDocComment($fileDocComment);
947+
foreach ($fileTags as $tag) {
948+
if ($tag->name === 'generate-function-entries') {
949+
$fileInfo->generateFunctionEntries = true;
950+
$fileInfo->declarationPrefix = $tag->value ? $tag->value . " " : "";
951+
}
946952
}
947953
}
948954

@@ -1110,15 +1116,14 @@ function (FuncInfo $funcInfo) use(&$generatedFuncInfos) {
11101116
$generatedFunctionDeclarations = [];
11111117
$code .= generateCodeWithConditions(
11121118
$fileInfo->getAllFuncInfos(), "",
1113-
function (FuncInfo $funcInfo) use(&$generatedFunctionDeclarations) {
1119+
function (FuncInfo $funcInfo) use($fileInfo, &$generatedFunctionDeclarations) {
11141120
$key = $funcInfo->getDeclarationKey();
11151121
if (isset($generatedFunctionDeclarations[$key])) {
11161122
return null;
11171123
}
11181124

11191125
$generatedFunctionDeclarations[$key] = true;
1120-
1121-
return $funcInfo->getDeclaration();
1126+
return $fileInfo->declarationPrefix . $funcInfo->getDeclaration();
11221127
}
11231128
);
11241129

ext/zend_test/test.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static zend_class_entry *zend_test_trait;
5151
static zend_class_entry *zend_test_attribute;
5252
static zend_object_handlers zend_test_class_handlers;
5353

54-
ZEND_FUNCTION(zend_test_func)
54+
static ZEND_FUNCTION(zend_test_func)
5555
{
5656
RETVAL_STR_COPY(EX(func)->common.function_name);
5757

@@ -62,23 +62,23 @@ ZEND_FUNCTION(zend_test_func)
6262
EX(func) = NULL;
6363
}
6464

65-
ZEND_FUNCTION(zend_test_array_return)
65+
static ZEND_FUNCTION(zend_test_array_return)
6666
{
6767
ZEND_PARSE_PARAMETERS_NONE();
6868
}
6969

70-
ZEND_FUNCTION(zend_test_nullable_array_return)
70+
static ZEND_FUNCTION(zend_test_nullable_array_return)
7171
{
7272
ZEND_PARSE_PARAMETERS_NONE();
7373
}
7474

75-
ZEND_FUNCTION(zend_test_void_return)
75+
static ZEND_FUNCTION(zend_test_void_return)
7676
{
7777
/* dummy */
7878
ZEND_PARSE_PARAMETERS_NONE();
7979
}
8080

81-
ZEND_FUNCTION(zend_test_deprecated)
81+
static ZEND_FUNCTION(zend_test_deprecated)
8282
{
8383
zval *arg1;
8484

@@ -88,7 +88,7 @@ ZEND_FUNCTION(zend_test_deprecated)
8888
/* Create a string without terminating null byte. Must be terminated with
8989
* zend_terminate_string() before destruction, otherwise a warning is issued
9090
* in debug builds. */
91-
ZEND_FUNCTION(zend_create_unterminated_string)
91+
static ZEND_FUNCTION(zend_create_unterminated_string)
9292
{
9393
zend_string *str, *res;
9494

@@ -104,7 +104,7 @@ ZEND_FUNCTION(zend_create_unterminated_string)
104104
}
105105

106106
/* Enforce terminate null byte on string. This avoids a warning in debug builds. */
107-
ZEND_FUNCTION(zend_terminate_string)
107+
static ZEND_FUNCTION(zend_terminate_string)
108108
{
109109
zend_string *str;
110110

@@ -116,7 +116,7 @@ ZEND_FUNCTION(zend_terminate_string)
116116
}
117117

118118
/* {{{ Cause an intentional memory leak, for testing/debugging purposes */
119-
ZEND_FUNCTION(zend_leak_bytes)
119+
static ZEND_FUNCTION(zend_leak_bytes)
120120
{
121121
zend_long leakbytes = 3;
122122

@@ -129,7 +129,7 @@ ZEND_FUNCTION(zend_leak_bytes)
129129
/* }}} */
130130

131131
/* {{{ Leak a refcounted variable */
132-
ZEND_FUNCTION(zend_leak_variable)
132+
static ZEND_FUNCTION(zend_leak_variable)
133133
{
134134
zval *zv;
135135

@@ -147,7 +147,7 @@ ZEND_FUNCTION(zend_leak_variable)
147147
/* }}} */
148148

149149
/* Tests Z_PARAM_OBJ_OR_STR */
150-
ZEND_FUNCTION(zend_string_or_object)
150+
static ZEND_FUNCTION(zend_string_or_object)
151151
{
152152
zend_string *str;
153153
zend_object *object;
@@ -165,7 +165,7 @@ ZEND_FUNCTION(zend_string_or_object)
165165
/* }}} */
166166

167167
/* Tests Z_PARAM_OBJ_OR_STR_OR_NULL */
168-
ZEND_FUNCTION(zend_string_or_object_or_null)
168+
static ZEND_FUNCTION(zend_string_or_object_or_null)
169169
{
170170
zend_string *str;
171171
zend_object *object;
@@ -185,7 +185,7 @@ ZEND_FUNCTION(zend_string_or_object_or_null)
185185
/* }}} */
186186

187187
/* Tests Z_PARAM_OBJ_OF_CLASS_OR_STR */
188-
ZEND_FUNCTION(zend_string_or_stdclass)
188+
static ZEND_FUNCTION(zend_string_or_stdclass)
189189
{
190190
zend_string *str;
191191
zend_object *object;
@@ -203,7 +203,7 @@ ZEND_FUNCTION(zend_string_or_stdclass)
203203
/* }}} */
204204

205205
/* Tests Z_PARAM_OBJ_OF_CLASS_OR_STR_OR_NULL */
206-
ZEND_FUNCTION(zend_string_or_stdclass_or_null)
206+
static ZEND_FUNCTION(zend_string_or_stdclass_or_null)
207207
{
208208
zend_string *str;
209209
zend_object *object;
@@ -223,7 +223,7 @@ ZEND_FUNCTION(zend_string_or_stdclass_or_null)
223223
/* }}} */
224224

225225
/* TESTS Z_PARAM_ITERABLE and Z_PARAM_ITERABLE_OR_NULL */
226-
ZEND_FUNCTION(zend_iterable)
226+
static ZEND_FUNCTION(zend_iterable)
227227
{
228228
zval *arg1, *arg2;
229229

@@ -292,18 +292,18 @@ void zend_attribute_validate_zendtestattribute(zend_attribute *attr, uint32_t ta
292292
}
293293
}
294294

295-
ZEND_METHOD(_ZendTestClass, __toString) /* {{{ */ {
295+
static ZEND_METHOD(_ZendTestClass, __toString) /* {{{ */ {
296296
RETURN_EMPTY_STRING();
297297
}
298298
/* }}} */
299299

300300
/* Internal function returns bool, we return int. */
301-
ZEND_METHOD(_ZendTestClass, is_object) /* {{{ */ {
301+
static ZEND_METHOD(_ZendTestClass, is_object) /* {{{ */ {
302302
RETURN_LONG(42);
303303
}
304304
/* }}} */
305305

306-
ZEND_METHOD(_ZendTestTrait, testMethod) /* {{{ */ {
306+
static ZEND_METHOD(_ZendTestTrait, testMethod) /* {{{ */ {
307307
RETURN_TRUE;
308308
}
309309
/* }}} */

ext/zend_test/test.stub.php

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

3-
/** @generate-function-entries */
3+
/** @generate-function-entries static */
44

55
class _ZendTestClass {
66
public static function is_object(): int {}

ext/zend_test/test_arginfo.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 87c9d71b08c538c28b4f9bad01d7a7a3a3b191ef */
2+
* Stub hash: 1aa8e876ff9efb99c61603216eed267b0d225221 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
55
ZEND_END_ARG_INFO()
@@ -61,22 +61,22 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestTrait_testMethod,
6161
ZEND_END_ARG_INFO()
6262

6363

64-
ZEND_FUNCTION(zend_test_array_return);
65-
ZEND_FUNCTION(zend_test_nullable_array_return);
66-
ZEND_FUNCTION(zend_test_void_return);
67-
ZEND_FUNCTION(zend_test_deprecated);
68-
ZEND_FUNCTION(zend_create_unterminated_string);
69-
ZEND_FUNCTION(zend_terminate_string);
70-
ZEND_FUNCTION(zend_leak_variable);
71-
ZEND_FUNCTION(zend_leak_bytes);
72-
ZEND_FUNCTION(zend_string_or_object);
73-
ZEND_FUNCTION(zend_string_or_object_or_null);
74-
ZEND_FUNCTION(zend_string_or_stdclass);
75-
ZEND_FUNCTION(zend_string_or_stdclass_or_null);
76-
ZEND_FUNCTION(zend_iterable);
77-
ZEND_METHOD(_ZendTestClass, is_object);
78-
ZEND_METHOD(_ZendTestClass, __toString);
79-
ZEND_METHOD(_ZendTestTrait, testMethod);
64+
static ZEND_FUNCTION(zend_test_array_return);
65+
static ZEND_FUNCTION(zend_test_nullable_array_return);
66+
static ZEND_FUNCTION(zend_test_void_return);
67+
static ZEND_FUNCTION(zend_test_deprecated);
68+
static ZEND_FUNCTION(zend_create_unterminated_string);
69+
static ZEND_FUNCTION(zend_terminate_string);
70+
static ZEND_FUNCTION(zend_leak_variable);
71+
static ZEND_FUNCTION(zend_leak_bytes);
72+
static ZEND_FUNCTION(zend_string_or_object);
73+
static ZEND_FUNCTION(zend_string_or_object_or_null);
74+
static ZEND_FUNCTION(zend_string_or_stdclass);
75+
static ZEND_FUNCTION(zend_string_or_stdclass_or_null);
76+
static ZEND_FUNCTION(zend_iterable);
77+
static ZEND_METHOD(_ZendTestClass, is_object);
78+
static ZEND_METHOD(_ZendTestClass, __toString);
79+
static ZEND_METHOD(_ZendTestTrait, testMethod);
8080

8181

8282
static const zend_function_entry ext_functions[] = {

0 commit comments

Comments
 (0)