Skip to content

Commit

Permalink
Merge pull request #14829 from JuliaLang/nl/gcc6
Browse files Browse the repository at this point in the history
[release-0.4, RFC]: Remove 0-size and variable size array members from public headers.
  • Loading branch information
tkelman committed Mar 7, 2016
2 parents 25dde30 + 3d73e18 commit 147d6d0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4938,7 +4938,7 @@ extern "C" DLLEXPORT jl_value_t *jl_new_box(jl_value_t *v)
jl_value_t *box = (jl_value_t*)jl_gc_alloc_1w();
jl_set_typeof(box, jl_box_any_type);
// if (v) jl_gc_wb(box, v); // write block not needed: box was just allocated
box->fieldptr[0] = v;
jl_data_ptr(box)[0] = v;
return box;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,7 @@ static void jl_reinit_item(ios_t *f, jl_value_t *v, int how) {
JL_TRY {
switch (how) {
case 1: { // rehash ObjectIdDict
jl_array_t **a = (jl_array_t**)&v->fieldptr[0];
jl_array_t **a = (jl_array_t**)jl_data_ptr(v);
jl_idtable_rehash(a, jl_array_len(*a));
jl_gc_wb(v, *a);
break;
Expand Down
16 changes: 10 additions & 6 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ extern "C" {

typedef struct _jl_value_t {
JL_DATA_TYPE
#if !defined(__GNUC__) || __GNUC__ < 6
// GCC 6 is not happy about flexible array member in otherwise empty struct.
// Only remove the definition on GCC >= 6 to avoid breaking existing setup.
struct _jl_value_t *fieldptr[];
#endif
} jl_value_t;

typedef struct {
Expand Down Expand Up @@ -690,17 +694,17 @@ STATIC_INLINE jl_value_t *jl_cellset(void *a, size_t i, void *x)
#define jl_tparam1(t) jl_svecref(((jl_datatype_t*)(t))->parameters, 1)
#define jl_tparam(t,i) jl_svecref(((jl_datatype_t*)(t))->parameters, i)

// get a pointer to the data in a datatype
#define jl_data_ptr(v) ((jl_value_t**)v)

#define jl_cell_data(a) ((jl_value_t**)((jl_array_t*)a)->data)
#define jl_string_data(s) ((char*)((jl_array_t*)(s)->fieldptr[0])->data)
#define jl_string_len(s) (jl_array_len(((jl_array_t*)(s)->fieldptr[0])))
#define jl_iostr_data(s) ((char*)((jl_array_t*)(s)->fieldptr[0])->data)
#define jl_string_data(s) ((char*)((jl_array_t*)jl_data_ptr(s)[0])->data)
#define jl_string_len(s) (jl_array_len(((jl_array_t*)jl_data_ptr(s)[0])))
#define jl_iostr_data(s) ((char*)((jl_array_t*)jl_data_ptr(s)[0])->data)

#define jl_gf_mtable(f) ((jl_methtable_t*)((jl_function_t*)(f))->env)
#define jl_gf_name(f) (jl_gf_mtable(f)->name)

// get a pointer to the data in a datatype
#define jl_data_ptr(v) (((jl_value_t*)v)->fieldptr)

// struct type info
#define jl_field_name(st,i) (jl_sym_t*)jl_svecref(((jl_datatype_t*)st)->name->names, (i))
#define jl_field_type(st,i) jl_svecref(((jl_datatype_t*)st)->types, (i))
Expand Down

0 comments on commit 147d6d0

Please sign in to comment.