summaryrefslogtreecommitdiff
path: root/src/lisp.h
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2013-11-03 22:09:03 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2013-11-03 22:09:03 -0800
commit91f2d272895257f23596075a0cc42e6e5f4e490f (patch)
tree5bcf0c44acc54bd56eef8394e50ff7d4cc24d5b3 /src/lisp.h
parent0a749fa0e64fc88bcd1772253774d7e44ecfe8ce (diff)
downloademacs-91f2d272895257f23596075a0cc42e6e5f4e490f.tar.gz
Port to stricter C99 platforms.
Especially, C99 prohibits nesting a struct X inside struct Y if struct X has a flexible array member. Also, merge from gnulib, incorporating: 2013-11-03 intprops: port to Oracle Studio c99 * lib/intprops.h: Update from gnulib. * src/alloc.c (struct sdata): New type. (sdata): Implement in terms of struct sdata. Remove u member; all uses replaced by next_vector, set_next_vector. (SDATA_SELECTOR, SDATA_DATA, SDATA_DATA_OFFSET): Adjust to sdata change. (SDATA_DATA_OFFSET): Now a constant, not a macro. (struct sblock): Rename first_data member to data, which is now a flexible array member. All uses changed. (next_vector, set_next_vector, large_vector_vec): New functions. (vector_alignment): New constant. (roundup_size): Make it a multiple of ALIGNOF_STRUCT_LISP_VECTOR, too. (struct large-vector): Now merely a NEXT member, since the old approach ran afoul of stricter C99. All uses changed to use large_vector_vec or large_vector_offset. (large_vector_offset): New constant. * src/dispnew.c: Include tparam.h, for tgetent. Do not include term.h; no longer needed. * src/gnutls.c (Fgnutls_boot): Don't continue after calling a _Noreturn. * src/lisp.h (ENUM_BF) [__SUNPRO_C && __STDC__]: Use unsigned int. (struct Lisp_Vector): Use a flexible array member for contents, instead of a union with a member that is an array of size 1. All uses changed. (ALIGNOF_STRUCT_LISP_VECTOR): New constant, to make up for the fact that the struct no longer contains a union. (struct Lisp_Misc_Any, struct Lisp_Marker, struct Lisp_Overlay) (struct Lisp_Save_Value, struct Lisp_Free): Use unsigned, not int, for spacers, to avoid c99 warning. (union specbinding): Use unsigned, not bool, for bitfield, as bool is not portable to pre-C99 hosts.
Diffstat (limited to 'src/lisp.h')
-rw-r--r--src/lisp.h48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/lisp.h b/src/lisp.h
index c8b9497a314..f538cec5ed1 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -406,8 +406,10 @@ enum enum_USE_LSB_TAG { USE_LSB_TAG = 0 };
#define case_Lisp_Int case Lisp_Int0: case Lisp_Int1
/* Idea stolen from GDB. Pedantic GCC complains about enum bitfields,
- MSVC doesn't support them, and xlc complains vociferously about them. */
-#if defined __STRICT_ANSI__ || defined _MSC_VER || defined __IBMC__
+ MSVC doesn't support them, and xlc and Oracle Studio c99 complain
+ vociferously about them. */
+#if (defined __STRICT_ANSI__ || defined _MSC_VER || defined __IBMC__ \
+ || (defined __SUNPRO_C && __STDC__))
#define ENUM_BF(TYPE) unsigned int
#else
#define ENUM_BF(TYPE) enum TYPE
@@ -1175,22 +1177,22 @@ struct vectorlike_header
ptrdiff_t size;
};
-/* Regular vector is just a header plus array of Lisp_Objects... */
+/* A regular vector is just a header plus an array of Lisp_Objects. */
struct Lisp_Vector
{
struct vectorlike_header header;
- union {
- /* ...but sometimes there is also a pointer internally used in
- vector allocation code. Usually you don't want to touch this. */
- struct Lisp_Vector *next;
+ Lisp_Object contents[FLEXIBLE_ARRAY_MEMBER];
+ };
- /* We can't use FLEXIBLE_ARRAY_MEMBER here. */
- Lisp_Object contents[1];
- } u;
+/* C11 prohibits alignof (struct Lisp_Vector), so compute it manually. */
+enum
+ {
+ ALIGNOF_STRUCT_LISP_VECTOR
+ = alignof (union { struct vectorlike_header a; Lisp_Object b; })
};
-/* A boolvector is a kind of vectorlike, with contents are like a string. */
+/* A boolvector is a kind of vectorlike, with contents like a string. */
struct Lisp_Bool_Vector
{
@@ -1216,7 +1218,7 @@ bool_vector_size (Lisp_Object a)
enum
{
- header_size = offsetof (struct Lisp_Vector, u.contents),
+ header_size = offsetof (struct Lisp_Vector, contents),
bool_header_size = offsetof (struct Lisp_Bool_Vector, data),
word_size = sizeof (Lisp_Object)
};
@@ -1226,13 +1228,13 @@ enum
INLINE Lisp_Object
AREF (Lisp_Object array, ptrdiff_t idx)
{
- return XVECTOR (array)->u.contents[idx];
+ return XVECTOR (array)->contents[idx];
}
INLINE Lisp_Object *
aref_addr (Lisp_Object array, ptrdiff_t idx)
{
- return & XVECTOR (array)->u.contents[idx];
+ return & XVECTOR (array)->contents[idx];
}
INLINE ptrdiff_t
@@ -1245,7 +1247,7 @@ INLINE void
ASET (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
{
eassert (0 <= idx && idx < ASIZE (array));
- XVECTOR (array)->u.contents[idx] = val;
+ XVECTOR (array)->contents[idx] = val;
}
INLINE void
@@ -1254,7 +1256,7 @@ gc_aset (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
/* Like ASET, but also can be used in the garbage collector:
sweep_weak_table calls set_hash_key etc. while the table is marked. */
eassert (0 <= idx && idx < (ASIZE (array) & ~ARRAY_MARK_FLAG));
- XVECTOR (array)->u.contents[idx] = val;
+ XVECTOR (array)->contents[idx] = val;
}
/* If a struct is made to look like a vector, this macro returns the length
@@ -1758,14 +1760,14 @@ struct Lisp_Misc_Any /* Supertype of all Misc types. */
{
ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_??? */
unsigned gcmarkbit : 1;
- int spacer : 15;
+ unsigned spacer : 15;
};
struct Lisp_Marker
{
ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Marker */
unsigned gcmarkbit : 1;
- int spacer : 13;
+ unsigned spacer : 13;
/* This flag is temporarily used in the functions
decode/encode_coding_object to record that the marker position
must be adjusted after the conversion. */
@@ -1819,7 +1821,7 @@ struct Lisp_Overlay
{
ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Overlay */
unsigned gcmarkbit : 1;
- int spacer : 15;
+ unsigned spacer : 15;
struct Lisp_Overlay *next;
Lisp_Object start;
Lisp_Object end;
@@ -1897,7 +1899,7 @@ struct Lisp_Save_Value
{
ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Save_Value */
unsigned gcmarkbit : 1;
- int spacer : 32 - (16 + 1 + SAVE_TYPE_BITS);
+ unsigned spacer : 32 - (16 + 1 + SAVE_TYPE_BITS);
/* V->data may hold up to SAVE_VALUE_SLOTS entries. The type of
V's data entries are determined by V->save_type. E.g., if
@@ -1973,7 +1975,7 @@ struct Lisp_Free
{
ENUM_BF (Lisp_Misc_Type) type : 16; /* = Lisp_Misc_Free */
unsigned gcmarkbit : 1;
- int spacer : 15;
+ unsigned spacer : 15;
union Lisp_Misc *chain;
};
@@ -2737,7 +2739,7 @@ union specbinding
} let;
struct {
ENUM_BF (specbind_tag) kind : CHAR_BIT;
- bool debug_on_exit : 1;
+ unsigned debug_on_exit : 1;
Lisp_Object function;
Lisp_Object *args;
ptrdiff_t nargs;
@@ -3089,7 +3091,7 @@ INLINE void
vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object *args, ptrdiff_t count)
{
eassert (0 <= offset && 0 <= count && offset + count <= ASIZE (v));
- memcpy (XVECTOR (v)->u.contents + offset, args, count * sizeof *args);
+ memcpy (XVECTOR (v)->contents + offset, args, count * sizeof *args);
}
/* Functions to modify hash tables. */