Skip to content

Commit bd76cfc

Browse files
committed
More strict compile time checks.
1 parent e2d5cfc commit bd76cfc

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/lceasy.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,9 +1593,11 @@ void lcurl_easy_initlib(lua_State *L, int nup){
15931593
/* Hack. We ensure that lcurl_easy_t and lcurl_hpost_stream_t
15941594
compatiable for readfunction
15951595
*/
1596-
LCURL_STATIC_ASSERT(offsetof(lcurl_easy_t, magic) == offsetof(lcurl_hpost_stream_t, magic));
1597-
LCURL_STATIC_ASSERT(offsetof(lcurl_easy_t, L) == offsetof(lcurl_hpost_stream_t, L));
1598-
LCURL_STATIC_ASSERT(offsetof(lcurl_easy_t, rd) == offsetof(lcurl_hpost_stream_t, rd));
1596+
LCURL_ASSERT_SAME_OFFSET(lcurl_easy_t, magic, lcurl_hpost_stream_t, magic);
1597+
LCURL_ASSERT_SAME_OFFSET(lcurl_easy_t, L, lcurl_hpost_stream_t, L);
1598+
LCURL_ASSERT_SAME_OFFSET(lcurl_easy_t, rd, lcurl_hpost_stream_t, rd);
1599+
LCURL_ASSERT_SAME_OFFSET(lcurl_easy_t, rbuffer, lcurl_hpost_stream_t, rbuffer);
1600+
LCURL_ASSERT_SAME_FIELD_SIZE(lcurl_easy_t, rbuffer, lcurl_hpost_stream_t, rbuffer);
15991601

16001602
if(!lutil_createmetap(L, LCURL_EASY, lcurl_easy_methods, nup))
16011603
lua_pop(L, nup);

src/lcutils.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@
2828
#define LCURL_MAKE_VERSION(MIN, MAJ, PAT) ((MIN<<16) + (MAJ<<8) + PAT)
2929
#define LCURL_CURL_VER_GE(MIN, MAJ, PAT) (LIBCURL_VERSION_NUM >= LCURL_MAKE_VERSION(MIN, MAJ, PAT))
3030

31-
//! @fixme on mingw32 (gcc 4.8.1) this does not work
32-
#define LCURL_STATIC_ASSERT(A) {(void)(int(*)[(A)?1:0])0;}
31+
//! @todo test on mingw32 (gcc 4.8.1)
32+
#define LCURL_CONCAT_STATIC_ASSERT_IMPL_(x, y) LCURL_CONCAT1_STATIC_ASSERT_IMPL_ (x, y)
33+
#define LCURL_CONCAT1_STATIC_ASSERT_IMPL_(x, y) x##y
34+
#define LCURL_STATIC_ASSERT(expr) typedef char LCURL_CONCAT_STATIC_ASSERT_IMPL_(static_assert_failed_at_line_, __LINE__) [(expr) ? 1 : -1]
35+
36+
#define LCURL_ASSERT_SAME_SIZE(a, b) LCURL_STATIC_ASSERT( sizeof(a) == sizeof(b) )
37+
#define LCURL_ASSERT_SAME_OFFSET(a, am, b, bm) LCURL_STATIC_ASSERT( (offsetof(a,am)) == (offsetof(b,bm)) )
38+
#define LCURL_ASSERT_SAME_FIELD_SIZE(a, am, b, bm) LCURL_ASSERT_SAME_SIZE(((a*)0)->am, ((b*)0)->bm)
3339

3440
typedef struct lcurl_const_tag{
3541
const char *name;

0 commit comments

Comments
 (0)