diff options
Diffstat (limited to 'src/lj_cparse.c')
-rw-r--r-- | src/lj_cparse.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/lj_cparse.c b/src/lj_cparse.c index a393965e..78628bba 100644 --- a/src/lj_cparse.c +++ b/src/lj_cparse.c | |||
@@ -28,6 +28,12 @@ | |||
28 | ** If in doubt, please check the input against your favorite C compiler. | 28 | ** If in doubt, please check the input against your favorite C compiler. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifdef LUA_USE_ASSERT | ||
32 | #define lj_assertCP(c, ...) (lj_assertG_(G(cp->L), (c), __VA_ARGS__)) | ||
33 | #else | ||
34 | #define lj_assertCP(c, ...) ((void)cp) | ||
35 | #endif | ||
36 | |||
31 | /* -- Miscellaneous ------------------------------------------------------- */ | 37 | /* -- Miscellaneous ------------------------------------------------------- */ |
32 | 38 | ||
33 | /* Match string against a C literal. */ | 39 | /* Match string against a C literal. */ |
@@ -61,7 +67,7 @@ LJ_NORET static void cp_err(CPState *cp, ErrMsg em); | |||
61 | 67 | ||
62 | static const char *cp_tok2str(CPState *cp, CPToken tok) | 68 | static const char *cp_tok2str(CPState *cp, CPToken tok) |
63 | { | 69 | { |
64 | lua_assert(tok < CTOK_FIRSTDECL); | 70 | lj_assertCP(tok < CTOK_FIRSTDECL, "bad CPToken %d", tok); |
65 | if (tok > CTOK_OFS) | 71 | if (tok > CTOK_OFS) |
66 | return ctoknames[tok-CTOK_OFS-1]; | 72 | return ctoknames[tok-CTOK_OFS-1]; |
67 | else if (!lj_char_iscntrl(tok)) | 73 | else if (!lj_char_iscntrl(tok)) |
@@ -392,7 +398,7 @@ static void cp_init(CPState *cp) | |||
392 | cp->curpack = 0; | 398 | cp->curpack = 0; |
393 | cp->packstack[0] = 255; | 399 | cp->packstack[0] = 255; |
394 | lj_buf_init(cp->L, &cp->sb); | 400 | lj_buf_init(cp->L, &cp->sb); |
395 | lua_assert(cp->p != NULL); | 401 | lj_assertCP(cp->p != NULL, "uninitialized cp->p"); |
396 | cp_get(cp); /* Read-ahead first char. */ | 402 | cp_get(cp); /* Read-ahead first char. */ |
397 | cp->tok = 0; | 403 | cp->tok = 0; |
398 | cp->tmask = CPNS_DEFAULT; | 404 | cp->tmask = CPNS_DEFAULT; |
@@ -853,12 +859,13 @@ static CTypeID cp_decl_intern(CPState *cp, CPDecl *decl) | |||
853 | /* The cid is already part of info for copies of pointers/functions. */ | 859 | /* The cid is already part of info for copies of pointers/functions. */ |
854 | idx = ct->next; | 860 | idx = ct->next; |
855 | if (ctype_istypedef(info)) { | 861 | if (ctype_istypedef(info)) { |
856 | lua_assert(id == 0); | 862 | lj_assertCP(id == 0, "typedef not at toplevel"); |
857 | id = ctype_cid(info); | 863 | id = ctype_cid(info); |
858 | /* Always refetch info/size, since struct/enum may have been completed. */ | 864 | /* Always refetch info/size, since struct/enum may have been completed. */ |
859 | cinfo = ctype_get(cp->cts, id)->info; | 865 | cinfo = ctype_get(cp->cts, id)->info; |
860 | csize = ctype_get(cp->cts, id)->size; | 866 | csize = ctype_get(cp->cts, id)->size; |
861 | lua_assert(ctype_isstruct(cinfo) || ctype_isenum(cinfo)); | 867 | lj_assertCP(ctype_isstruct(cinfo) || ctype_isenum(cinfo), |
868 | "typedef of bad type"); | ||
862 | } else if (ctype_isfunc(info)) { /* Intern function. */ | 869 | } else if (ctype_isfunc(info)) { /* Intern function. */ |
863 | CType *fct; | 870 | CType *fct; |
864 | CTypeID fid; | 871 | CTypeID fid; |
@@ -891,7 +898,7 @@ static CTypeID cp_decl_intern(CPState *cp, CPDecl *decl) | |||
891 | /* Inherit csize/cinfo from original type. */ | 898 | /* Inherit csize/cinfo from original type. */ |
892 | } else { | 899 | } else { |
893 | if (ctype_isnum(info)) { /* Handle mode/vector-size attributes. */ | 900 | if (ctype_isnum(info)) { /* Handle mode/vector-size attributes. */ |
894 | lua_assert(id == 0); | 901 | lj_assertCP(id == 0, "number not at toplevel"); |
895 | if (!(info & CTF_BOOL)) { | 902 | if (!(info & CTF_BOOL)) { |
896 | CTSize msize = ctype_msizeP(decl->attr); | 903 | CTSize msize = ctype_msizeP(decl->attr); |
897 | CTSize vsize = ctype_vsizeP(decl->attr); | 904 | CTSize vsize = ctype_vsizeP(decl->attr); |
@@ -946,7 +953,7 @@ static CTypeID cp_decl_intern(CPState *cp, CPDecl *decl) | |||
946 | info = (info & ~CTF_ALIGN) | (cinfo & CTF_ALIGN); | 953 | info = (info & ~CTF_ALIGN) | (cinfo & CTF_ALIGN); |
947 | info |= (cinfo & CTF_QUAL); /* Inherit qual. */ | 954 | info |= (cinfo & CTF_QUAL); /* Inherit qual. */ |
948 | } else { | 955 | } else { |
949 | lua_assert(ctype_isvoid(info)); | 956 | lj_assertCP(ctype_isvoid(info), "bad ctype %08x", info); |
950 | } | 957 | } |
951 | csize = size; | 958 | csize = size; |
952 | cinfo = info+id; | 959 | cinfo = info+id; |
@@ -1585,7 +1592,7 @@ end_decl: | |||
1585 | cp_errmsg(cp, cp->tok, LJ_ERR_FFI_DECLSPEC); | 1592 | cp_errmsg(cp, cp->tok, LJ_ERR_FFI_DECLSPEC); |
1586 | sz = sizeof(int); | 1593 | sz = sizeof(int); |
1587 | } | 1594 | } |
1588 | lua_assert(sz != 0); | 1595 | lj_assertCP(sz != 0, "basic ctype with zero size"); |
1589 | info += CTALIGN(lj_fls(sz)); /* Use natural alignment. */ | 1596 | info += CTALIGN(lj_fls(sz)); /* Use natural alignment. */ |
1590 | info += (decl->attr & CTF_QUAL); /* Merge qualifiers. */ | 1597 | info += (decl->attr & CTF_QUAL); /* Merge qualifiers. */ |
1591 | cp_push(decl, info, sz); | 1598 | cp_push(decl, info, sz); |
@@ -1845,7 +1852,7 @@ static void cp_decl_multi(CPState *cp) | |||
1845 | /* Treat both static and extern function declarations as extern. */ | 1852 | /* Treat both static and extern function declarations as extern. */ |
1846 | ct = ctype_get(cp->cts, ctypeid); | 1853 | ct = ctype_get(cp->cts, ctypeid); |
1847 | /* We always get new anonymous functions (typedefs are copied). */ | 1854 | /* We always get new anonymous functions (typedefs are copied). */ |
1848 | lua_assert(gcref(ct->name) == NULL); | 1855 | lj_assertCP(gcref(ct->name) == NULL, "unexpected named function"); |
1849 | id = ctypeid; /* Just name it. */ | 1856 | id = ctypeid; /* Just name it. */ |
1850 | } else if ((scl & CDF_STATIC)) { /* Accept static constants. */ | 1857 | } else if ((scl & CDF_STATIC)) { /* Accept static constants. */ |
1851 | id = cp_decl_constinit(cp, &ct, ctypeid); | 1858 | id = cp_decl_constinit(cp, &ct, ctypeid); |
@@ -1902,7 +1909,7 @@ static TValue *cpcparser(lua_State *L, lua_CFunction dummy, void *ud) | |||
1902 | cp_decl_single(cp); | 1909 | cp_decl_single(cp); |
1903 | if (cp->param && cp->param != cp->L->top) | 1910 | if (cp->param && cp->param != cp->L->top) |
1904 | cp_err(cp, LJ_ERR_FFI_NUMPARAM); | 1911 | cp_err(cp, LJ_ERR_FFI_NUMPARAM); |
1905 | lua_assert(cp->depth == 0); | 1912 | lj_assertCP(cp->depth == 0, "unbalanced cparser declaration depth"); |
1906 | return NULL; | 1913 | return NULL; |
1907 | } | 1914 | } |
1908 | 1915 | ||