aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2011-01-27 16:28:24 +0100
committerMike Pall <mike>2011-01-27 16:28:24 +0100
commitcd9b8f90e2241c3f6c540844eedc04bc6bc28faf (patch)
tree9dd2ae400a3be1d525e1325e381530c9269e9515 /src
parent279b6ec22e266dd366ab5bbb0265dc5b437b1b89 (diff)
downloadluajit-cd9b8f90e2241c3f6c540844eedc04bc6bc28faf.tar.gz
luajit-cd9b8f90e2241c3f6c540844eedc04bc6bc28faf.tar.bz2
luajit-cd9b8f90e2241c3f6c540844eedc04bc6bc28faf.zip
FFI: Fix various issues with C type table reallocations.
Diffstat (limited to 'src')
-rw-r--r--src/lj_cparse.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/lj_cparse.c b/src/lj_cparse.c
index b2d0ecf7..7da4d12d 100644
--- a/src/lj_cparse.c
+++ b/src/lj_cparse.c
@@ -821,6 +821,7 @@ static CTypeID cp_decl_intern(CPState *cp, CPDecl *decl)
821 } else if (ctype_isfunc(info)) { /* Intern function. */ 821 } else if (ctype_isfunc(info)) { /* Intern function. */
822 CType *fct; 822 CType *fct;
823 CTypeID fid; 823 CTypeID fid;
824 CTypeID sib;
824 if (id) { 825 if (id) {
825 CType *refct = ctype_raw(cp->cts, id); 826 CType *refct = ctype_raw(cp->cts, id);
826 /* Reject function or refarray return types. */ 827 /* Reject function or refarray return types. */
@@ -833,11 +834,12 @@ static CTypeID cp_decl_intern(CPState *cp, CPDecl *decl)
833 if (!ctype_isattrib(ctn->info)) break; 834 if (!ctype_isattrib(ctn->info)) break;
834 idx = ctn->next; /* Skip attribute. */ 835 idx = ctn->next; /* Skip attribute. */
835 } 836 }
837 sib = ct->sib; /* Next line may reallocate the C type table. */
836 fid = lj_ctype_new(cp->cts, &fct); 838 fid = lj_ctype_new(cp->cts, &fct);
837 csize = CTSIZE_INVALID; 839 csize = CTSIZE_INVALID;
838 fct->info = cinfo = info + id; 840 fct->info = cinfo = info + id;
839 fct->size = ct->size; 841 fct->size = size;
840 fct->sib = ct->sib; 842 fct->sib = sib;
841 id = fid; 843 id = fid;
842 } else if (ctype_isattrib(info)) { 844 } else if (ctype_isattrib(info)) {
843 if (ctype_isxattrib(info, CTA_QUAL)) 845 if (ctype_isxattrib(info, CTA_QUAL))
@@ -932,23 +934,27 @@ static void cp_decl_reset(CPDecl *decl)
932static CTypeID cp_decl_constinit(CPState *cp, CType **ctp, CTypeID typeid) 934static CTypeID cp_decl_constinit(CPState *cp, CType **ctp, CTypeID typeid)
933{ 935{
934 CType *ctt = ctype_get(cp->cts, typeid); 936 CType *ctt = ctype_get(cp->cts, typeid);
937 CTInfo info;
938 CTSize size;
935 CPValue k; 939 CPValue k;
936 CTypeID constid; 940 CTypeID constid;
937 while (ctype_isattrib(ctt->info)) { /* Skip attributes. */ 941 while (ctype_isattrib(ctt->info)) { /* Skip attributes. */
938 typeid = ctype_cid(ctt->info); /* Update ID, too. */ 942 typeid = ctype_cid(ctt->info); /* Update ID, too. */
939 ctt = ctype_get(cp->cts, typeid); 943 ctt = ctype_get(cp->cts, typeid);
940 } 944 }
941 if (!ctype_isinteger(ctt->info) || !(ctt->info & CTF_CONST) || ctt->size > 4) 945 info = ctt->info;
946 size = ctt->size;
947 if (!ctype_isinteger(info) || !(info & CTF_CONST) || size > 4)
942 cp_err(cp, LJ_ERR_FFI_INVTYPE); 948 cp_err(cp, LJ_ERR_FFI_INVTYPE);
943 cp_check(cp, '='); 949 cp_check(cp, '=');
944 cp_expr_sub(cp, &k, 0); 950 cp_expr_sub(cp, &k, 0);
945 constid = lj_ctype_new(cp->cts, ctp); 951 constid = lj_ctype_new(cp->cts, ctp);
946 (*ctp)->info = CTINFO(CT_CONSTVAL, CTF_CONST|typeid); 952 (*ctp)->info = CTINFO(CT_CONSTVAL, CTF_CONST|typeid);
947 k.u32 <<= 8*(4-ctt->size); 953 k.u32 <<= 8*(4-size);
948 if ((ctt->info & CTF_UNSIGNED)) 954 if ((info & CTF_UNSIGNED))
949 k.u32 >>= 8*(4-ctt->size); 955 k.u32 >>= 8*(4-size);
950 else 956 else
951 k.u32 = (uint32_t)((int32_t)k.u32 >> 8*(4-ctt->size)); 957 k.u32 = (uint32_t)((int32_t)k.u32 >> 8*(4-size));
952 (*ctp)->size = k.u32; 958 (*ctp)->size = k.u32;
953 return constid; 959 return constid;
954} 960}
@@ -1307,7 +1313,6 @@ static CTypeID cp_decl_struct(CPState *cp, CPDecl *sdecl, CTInfo sinfo)
1307 CPARSE_MODE_DIRECT|CPARSE_MODE_ABSTRACT|CPARSE_MODE_FIELD; 1313 CPARSE_MODE_DIRECT|CPARSE_MODE_ABSTRACT|CPARSE_MODE_FIELD;
1308 1314
1309 for (;;) { 1315 for (;;) {
1310 CType *fct;
1311 CTypeID typeid; 1316 CTypeID typeid;
1312 1317
1313 if (lastdecl) cp_err_token(cp, '}'); 1318 if (lastdecl) cp_err_token(cp, '}');
@@ -1316,7 +1321,6 @@ static CTypeID cp_decl_struct(CPState *cp, CPDecl *sdecl, CTInfo sinfo)
1316 decl.bits = CTSIZE_INVALID; 1321 decl.bits = CTSIZE_INVALID;
1317 cp_declarator(cp, &decl); 1322 cp_declarator(cp, &decl);
1318 typeid = cp_decl_intern(cp, &decl); 1323 typeid = cp_decl_intern(cp, &decl);
1319 fct = ctype_raw(cp->cts, typeid);
1320 1324
1321 if ((scl & CDF_STATIC)) { /* Static constant in struct namespace. */ 1325 if ((scl & CDF_STATIC)) { /* Static constant in struct namespace. */
1322 CType *ct; 1326 CType *ct;