Skip to content

Commit 037da59

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Regenerate FFI parser using HEAD version of LLK
2 parents 8a4a304 + eb7bb58 commit 037da59

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

ext/ffi/ffi.g

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ php llk.php ffi.g
6464
/* forward declarations */
6565
static void yy_error(const char *msg);
6666
static void yy_error_sym(const char *msg, int sym);
67+
static void yy_error_str(const char *msg, const char *str);
6768

6869
%}
6970

@@ -918,3 +919,7 @@ static void yy_error(const char *msg) {
918919
static void yy_error_sym(const char *msg, int sym) {
919920
zend_ffi_parser_error("%s '%s' at line %d", msg, sym_name[sym], yy_line);
920921
}
922+
923+
static void yy_error_str(const char *msg, const char *str) {
924+
zend_ffi_parser_error("%s '%s' at line %d\n", msg, str, yy_line);
925+
}

ext/ffi/ffi_parser.c

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
/* forward declarations */
3535
static void yy_error(const char *msg);
3636
static void yy_error_sym(const char *msg, int sym);
37+
static void yy_error_str(const char *msg, const char *str);
3738

3839
#define YYPOS cpos
3940
#define YYEND cend
@@ -246,6 +247,63 @@ static const char * sym_name[] = {
246247
#define YY_IN_SET(sym, set, bitset) \
247248
(bitset[sym>>3] & (1 << (sym & 0x7)))
248249

250+
size_t yy_escape(char *buf, unsigned char ch)
251+
{
252+
switch (ch) {
253+
case '\\': buf[0] = '\\'; buf[1] = '\\'; return 2;
254+
case '\'': buf[0] = '\\'; buf[1] = '\''; return 2;
255+
case '\"': buf[0] = '\\'; buf[1] = '\"'; return 2;
256+
case '\a': buf[0] = '\\'; buf[1] = '\a'; return 2;
257+
case '\b': buf[0] = '\\'; buf[1] = '\b'; return 2;
258+
case 27: buf[0] = '\\'; buf[1] = '\e'; return 2;
259+
case '\f': buf[0] = '\\'; buf[1] = '\f'; return 2;
260+
case '\n': buf[0] = '\\'; buf[1] = '\n'; return 2;
261+
case '\r': buf[0] = '\\'; buf[1] = '\r'; return 2;
262+
case '\t': buf[0] = '\\'; buf[1] = '\t'; return 2;
263+
case '\v': buf[0] = '\\'; buf[1] = '\v'; return 2;
264+
case '\?': buf[0] = '\\'; buf[1] = 0x3f; return 2;
265+
default: break;
266+
}
267+
if (ch < 32 || ch >= 127) {
268+
buf[0] = '\\';
269+
buf[1] = '0' + ((ch >> 6) % 8);
270+
buf[2] = '0' + ((ch >> 3) % 8);
271+
buf[3] = '0' + (ch % 8);
272+
return 4;
273+
} else {
274+
buf[0] = ch;
275+
return 1;
276+
}
277+
}
278+
279+
const char *yy_escape_char(char *buf, unsigned char ch)
280+
{
281+
size_t len = yy_escape(buf, ch);
282+
buf[len] = 0;
283+
return buf;
284+
}
285+
286+
const char *yy_escape_string(char *buf, size_t size, const unsigned char *str, size_t n)
287+
{
288+
size_t i = 0;
289+
size_t pos = 0;
290+
size_t len;
291+
292+
while (i < n) {
293+
if (pos + 8 > size) {
294+
buf[pos++] = '.';
295+
buf[pos++] = '.';
296+
buf[pos++] = '.';
297+
break;
298+
}
299+
len = yy_escape(buf + pos, str[i]);
300+
i++;
301+
pos += len;
302+
}
303+
buf[pos] = 0;
304+
return buf;
305+
}
306+
249307
static int skip_EOL(int sym);
250308
static int skip_WS(int sym);
251309
static int skip_ONE_LINE_COMMENT(int sym);
@@ -310,6 +368,7 @@ static int synpred_5(int sym);
310368
static int synpred_6(int sym);
311369

312370
static int get_skip_sym(void) {
371+
char buf[64];
313372
int ch;
314373
int ret;
315374
int accept = -1;
@@ -1667,9 +1726,9 @@ static int get_skip_sym(void) {
16671726
if (YYPOS >= YYEND) {
16681727
yy_error("unexpected <EOF>");
16691728
} else if (YYPOS == yy_text) {
1670-
yy_error("unexpected character 'escape_char(ch)'");
1729+
yy_error_str("unexpected character", yy_escape_char(buf, ch));
16711730
} else {
1672-
yy_error("unexpected sequence 'escape_string(yy_text, 1 + YYPOS - yy_text))'");
1731+
yy_error_str("unexpected sequence", yy_escape_string(buf, sizeof(buf), yy_text, 1 + YYPOS - yy_text));
16731732
}
16741733
YYPOS++;
16751734
goto _yy_state_start;
@@ -3592,3 +3651,7 @@ static void yy_error(const char *msg) {
35923651
static void yy_error_sym(const char *msg, int sym) {
35933652
zend_ffi_parser_error("%s '%s' at line %d", msg, sym_name[sym], yy_line);
35943653
}
3654+
3655+
static void yy_error_str(const char *msg, const char *str) {
3656+
zend_ffi_parser_error("%s '%s' at line %d\n", msg, str, yy_line);
3657+
}

0 commit comments

Comments
 (0)