eliben / pycparser

:snake: Complete C99 parser in pure Python
Other
3.21k stars 612 forks source link

AssertionError #520

Open HLSSLenda opened 10 months ago

HLSSLenda commented 10 months ago

sys.version: 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] pycparser version: 2.21 Non-minimal reproducible code (I don't know how and where to start reducing this to a minimal reproducible example, so I pasted the entire header I'm trying to parse):

>>> import pycparser
>>> parser = pycparser.CParser()
>>> parser.parse("""typedef long unsigned int size_t;
typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;
typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;
typedef signed long int __int64_t;
typedef unsigned long int __uint64_t;
typedef __int8_t __int_least8_t;
typedef __uint8_t __uint_least8_t;
typedef __int16_t __int_least16_t;
typedef __uint16_t __uint_least16_t;
typedef __int32_t __int_least32_t;
typedef __uint32_t __uint_least32_t;
typedef __int64_t __int_least64_t;
typedef __uint64_t __uint_least64_t;
typedef long int __quad_t;
typedef unsigned long int __u_quad_t;
typedef long int __intmax_t;
typedef unsigned long int __uintmax_t;
typedef unsigned long int __dev_t;
typedef unsigned int __uid_t;
typedef unsigned int __gid_t;
typedef unsigned long int __ino_t;
typedef unsigned long int __ino64_t;
typedef unsigned int __mode_t;
typedef unsigned long int __nlink_t;
typedef long int __off_t;
typedef long int __off64_t;
typedef int __pid_t;
typedef struct 
{
  int __val[2];
} __fsid_t;
typedef long int __clock_t;
typedef unsigned long int __rlim_t;
typedef unsigned long int __rlim64_t;
typedef unsigned int __id_t;
typedef long int __time_t;
typedef unsigned int __useconds_t;
typedef long int __suseconds_t;
typedef long int __suseconds64_t;
typedef int __daddr_t;
typedef int __key_t;
typedef int __clockid_t;
typedef void *__timer_t;
typedef long int __blksize_t;
typedef long int __blkcnt_t;
typedef long int __blkcnt64_t;
typedef unsigned long int __fsblkcnt_t;
typedef unsigned long int __fsblkcnt64_t;
typedef unsigned long int __fsfilcnt_t;
typedef unsigned long int __fsfilcnt64_t;
typedef long int __fsword_t;
typedef long int __ssize_t;
typedef long int __syscall_slong_t;
typedef unsigned long int __syscall_ulong_t;
typedef __off64_t __loff_t;
typedef char *__caddr_t;
typedef long int __intptr_t;
typedef unsigned int __socklen_t;
typedef int __sig_atomic_t;
  int __count;
  union 
  {
    unsigned int __wch;
    char __wchb[4];
  } __value;
} __mbstate_t;
typedef struct _G_fpos_t
  __off_t __pos;
  __mbstate_t __state;
} __fpos_t;
typedef struct _G_fpos64_t
  __off64_t __pos;
} __fpos64_t;
struct _IO_FILE;
typedef struct _IO_FILE __FILE;
typedef struct _IO_FILE FILE;
struct _IO_marker;
struct _IO_codecvt;
struct _IO_wide_data;
typedef void _IO_lock_t;
typedef __off_t off_t;
typedef __ssize_t ssize_t;
typedef __fpos_t fpos_t;
extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;
extern int remove(const char *__filename);
extern int rename(const char *__old, const char *__new);
extern int renameat(int __oldfd, const char *__old, int __newfd, const char *__new);
extern int fclose(FILE *__stream);
extern FILE *tmpfile(void);
extern char *tmpnam(char [20]);
extern char *tmpnam_r(char __s[20]);
extern char *tempnam(const char *__dir, const char *__pfx);
extern int fflush(FILE *__stream);
extern int fflush_unlocked(FILE *__stream);
extern FILE *fopen(const char *__filename, const char *__modes);
extern FILE *freopen(const char *__filename, const char *__modes, FILE *__stream);
extern FILE *fdopen(int __fd, const char *__modes);
extern FILE *fmemopen(void *__s, size_t __len, const char *__modes);
extern FILE *open_memstream(char **__bufloc, size_t *__sizeloc);
extern void setbuf(FILE *__stream, char *__buf);
extern int setvbuf(FILE *__stream, char *__buf, int __modes, size_t __n);
extern void setbuffer(FILE *__stream, char *__buf, size_t __size);
extern void setlinebuf(FILE *__stream);
extern int fprintf(FILE *__stream, const char *__format, ...);
extern int printf(const char *__format, ...);
extern int sprintf(char *__s, const char *__format, ...);
extern int snprintf(char *__s, size_t __maxlen, const char *__format, ...);
extern int dprintf(int __fd, const char *__fmt, ...);
extern int fscanf(FILE *__stream, const char *__format, ...);
extern int scanf(const char *__format, ...);
extern int sscanf(const char *__s, const char *__format, ...);
extern int fgetc(FILE *__stream);
extern int getc(FILE *__stream);
extern int getchar(void);
extern int getc_unlocked(FILE *__stream);
extern int getchar_unlocked(void);
extern int fgetc_unlocked(FILE *__stream);
extern int fputc(int __c, FILE *__stream);
extern int putc(int __c, FILE *__stream);
extern int putchar(int __c);
extern int fputc_unlocked(int __c, FILE *__stream);
extern int putc_unlocked(int __c, FILE *__stream);
extern int putchar_unlocked(int __c);
extern int getw(FILE *__stream);
extern int putw(int __w, FILE *__stream);
extern char *fgets(char *__s, int __n, FILE *__stream);
extern __ssize_t __getdelim(char ** __lineptr, size_t *__n, int __delimiter, FILE *__stream);
extern __ssize_t getdelim(char ** __lineptr, size_t *__n, int __delimiter, FILE *__stream);
extern __ssize_t getline(char ** __lineptr, size_t *__n, FILE *__stream);
extern int fputs(const char *__s, FILE *__stream);
extern int puts(const char *__s);
extern int ungetc(int __c, FILE *__stream);
extern size_t fread(void *__ptr, size_t __size, size_t __n, FILE *__stream);
extern size_t fwrite(const void *__ptr, size_t __size, size_t __n, FILE *__s);
extern size_t fread_unlocked(void *__ptr, size_t __size, size_t __n, FILE *__stream);
extern size_t fwrite_unlocked(const void *__ptr, size_t __size, size_t __n, FILE *__stream);
extern int fseek(FILE *__stream, long int __off, int __whence);
extern long int ftell(FILE *__stream);
extern void rewind(FILE *__stream);
extern int fseeko(FILE *__stream, __off_t __off, int __whence);
extern __off_t ftello(FILE *__stream);
extern int fgetpos(FILE *__stream, fpos_t *__pos);
extern int fsetpos(FILE *__stream, const fpos_t *__pos);
extern void clearerr(FILE *__stream);
extern int feof(FILE *__stream);
extern int ferror(FILE *__stream);
extern void clearerr_unlocked(FILE *__stream);
extern int feof_unlocked(FILE *__stream);
extern int ferror_unlocked(FILE *__stream);
extern void perror(const char *__s);
extern int fileno(FILE *__stream);
extern int fileno_unlocked(FILE *__stream);
extern int pclose(FILE *__stream);
extern FILE *popen(const char *__command, const char *__modes);
extern char *ctermid(char *__s);
extern void flockfile(FILE *__stream);
extern int ftrylockfile(FILE *__stream);
extern void funlockfile(FILE *__stream);
extern int __uflow(FILE *);
extern int __overflow(FILE *, int);""")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jorge/.local/lib/python3.11/site-packages/pycparser/c_parser.py", line 147, in parse
    return self.cparser.parse(
           ^^^^^^^^^^^^^^^^^^^
  File "/home/jorge/.local/lib/python3.11/site-packages/pycparser/ply/yacc.py", line 331, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jorge/.local/lib/python3.11/site-packages/pycparser/ply/yacc.py", line 1061, in parseopt_notrack
    lookahead = get_token()     # Get the next token
                ^^^^^^^^^^^
  File "/home/jorge/.local/lib/python3.11/site-packages/pycparser/c_lexer.py", line 76, in token
    self.last_token = self.lexer.token()
                      ^^^^^^^^^^^^^^^^^^
  File "/home/jorge/.local/lib/python3.11/site-packages/pycparser/ply/lex.py", line 350, in token
    newtok = func(tok)
             ^^^^^^^^^
  File "/home/jorge/.local/lib/python3.11/site-packages/pycparser/c_lexer.py", line 446, in t_RBRACE
    self.on_rbrace_func()
  File "/home/jorge/.local/lib/python3.11/site-packages/pycparser/c_parser.py", line 197, in _lex_on_rbrace_func
    self._pop_scope()
  File "/home/jorge/.local/lib/python3.11/site-packages/pycparser/c_parser.py", line 158, in _pop_scope
    assert len(self._scope_stack) > 1
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
>>>