From: Tom Yu Date: Fri, 24 Jul 2009 18:21:57 +0000 (+0000) Subject: C++ compatibility for Windows compilation X-Git-Tag: krb5-1.7.1-beta1~45 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a6aaa3813d2646a4e59fccb7c3d7c47ab4a8d079;p=krb5.git C++ compatibility for Windows compilation pull up r21902, r21917, r21918, r21919 to improve C++ compatibility and to enable Windows compilation. ------------------------------------------------------------------------ r21919 | raeburn | 2009-02-09 11:36:09 -0500 (Mon, 09 Feb 2009) | 3 lines Check C++ compatibility for some internal headers that may (now or in the future) be used in C++ code on Windows. ------------------------------------------------------------------------ r21918 | raeburn | 2009-02-09 11:35:01 -0500 (Mon, 09 Feb 2009) | 3 lines More C++ compatibility: Don't use "typedef struct tag *tag"; rename the tag and keep the same typedefname. ------------------------------------------------------------------------ r21917 | raeburn | 2009-02-09 11:28:29 -0500 (Mon, 09 Feb 2009) | 3 lines C++ compatibility fix -- g++ says "types may not be defined in casts", so do the gcc unaligned-struct trick only for C, not C++. ------------------------------------------------------------------------ r21902 | raeburn | 2009-02-05 16:56:21 -0500 (Thu, 05 Feb 2009) | 2 lines use casts, for c++ compilation on windows ticket: 6536 version_fixed: 1.7.1 target_version: 1.7.1 tags: pullup git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-7@22455 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/include/k5-int.h b/src/include/k5-int.h index eb4e2faec..2002f42a8 100644 --- a/src/include/k5-int.h +++ b/src/include/k5-int.h @@ -2230,11 +2230,11 @@ struct _krb5_ccache { /* * Per-type ccache cursor. */ -struct krb5_cc_ptcursor { +struct krb5_cc_ptcursor_s { const struct _krb5_cc_ops *ops; krb5_pointer data; }; -typedef struct krb5_cc_ptcursor *krb5_cc_ptcursor; +typedef struct krb5_cc_ptcursor_s *krb5_cc_ptcursor; struct _krb5_cc_ops { krb5_magic magic; diff --git a/src/include/k5-ipc_stream.h b/src/include/k5-ipc_stream.h index edbf5a4ad..71bbaa1e7 100644 --- a/src/include/k5-ipc_stream.h +++ b/src/include/k5-ipc_stream.h @@ -29,8 +29,8 @@ #include "k5-platform.h" -struct k5_ipc_stream; -typedef struct k5_ipc_stream *k5_ipc_stream; +struct k5_ipc_stream_s; +typedef struct k5_ipc_stream_s *k5_ipc_stream; int32_t k5_ipc_stream_new (k5_ipc_stream *out_stream); diff --git a/src/include/k5-platform.h b/src/include/k5-platform.h index 1734e42c1..1485a1dec 100644 --- a/src/include/k5-platform.h +++ b/src/include/k5-platform.h @@ -533,13 +533,15 @@ static inline unsigned int k5_swap16 (unsigned int x) { # define SWAP64 OSSwapInt64 #endif +/* Note that on Windows at least this file can be included from C++ + source, so casts *from* void* are required. */ static inline void store_16_be (unsigned int val, void *vp) { - unsigned char *p = vp; -#if defined(__GNUC__) && defined(K5_BE) + unsigned char *p = (unsigned char *) vp; +#if defined(__GNUC__) && defined(K5_BE) && !defined(__cplusplus) PUT(16,p,val); -#elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP16) +#elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP16) && !defined(__cplusplus) PUTSWAPPED(16,p,val); #else p[0] = (val >> 8) & 0xff; @@ -549,10 +551,10 @@ store_16_be (unsigned int val, void *vp) static inline void store_32_be (unsigned int val, void *vp) { - unsigned char *p = vp; -#if defined(__GNUC__) && defined(K5_BE) + unsigned char *p = (unsigned char *) vp; +#if defined(__GNUC__) && defined(K5_BE) && !defined(__cplusplus) PUT(32,p,val); -#elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP32) +#elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP32) && !defined(__cplusplus) PUTSWAPPED(32,p,val); #else p[0] = (val >> 24) & 0xff; @@ -564,10 +566,10 @@ store_32_be (unsigned int val, void *vp) static inline void store_64_be (UINT64_TYPE val, void *vp) { - unsigned char *p = vp; -#if defined(__GNUC__) && defined(K5_BE) + unsigned char *p = (unsigned char *) vp; +#if defined(__GNUC__) && defined(K5_BE) && !defined(__cplusplus) PUT(64,p,val); -#elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP64) +#elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP64) && !defined(__cplusplus) PUTSWAPPED(64,p,val); #else p[0] = (unsigned char)((val >> 56) & 0xff); @@ -583,10 +585,10 @@ store_64_be (UINT64_TYPE val, void *vp) static inline unsigned short load_16_be (const void *cvp) { - const unsigned char *p = cvp; -#if defined(__GNUC__) && defined(K5_BE) + const unsigned char *p = (const unsigned char *) cvp; +#if defined(__GNUC__) && defined(K5_BE) && !defined(__cplusplus) return GET(16,p); -#elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP16) +#elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP16) && !defined(__cplusplus) return GETSWAPPED(16,p); #else return (p[1] | (p[0] << 8)); @@ -595,10 +597,10 @@ load_16_be (const void *cvp) static inline unsigned int load_32_be (const void *cvp) { - const unsigned char *p = cvp; -#if defined(__GNUC__) && defined(K5_BE) + const unsigned char *p = (const unsigned char *) cvp; +#if defined(__GNUC__) && defined(K5_BE) && !defined(__cplusplus) return GET(32,p); -#elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP32) +#elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP32) && !defined(__cplusplus) return GETSWAPPED(32,p); #else return (p[3] | (p[2] << 8) @@ -609,10 +611,10 @@ load_32_be (const void *cvp) static inline UINT64_TYPE load_64_be (const void *cvp) { - const unsigned char *p = cvp; -#if defined(__GNUC__) && defined(K5_BE) + const unsigned char *p = (const unsigned char *) cvp; +#if defined(__GNUC__) && defined(K5_BE) && !defined(__cplusplus) return GET(64,p); -#elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP64) +#elif defined(__GNUC__) && defined(K5_LE) && defined(SWAP64) && !defined(__cplusplus) return GETSWAPPED(64,p); #else return ((UINT64_TYPE)load_32_be(p) << 32) | load_32_be(p+4); @@ -621,10 +623,10 @@ load_64_be (const void *cvp) static inline void store_16_le (unsigned int val, void *vp) { - unsigned char *p = vp; -#if defined(__GNUC__) && defined(K5_LE) + unsigned char *p = (unsigned char *) vp; +#if defined(__GNUC__) && defined(K5_LE) && !defined(__cplusplus) PUT(16,p,val); -#elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP16) +#elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP16) && !defined(__cplusplus) PUTSWAPPED(16,p,val); #else p[1] = (val >> 8) & 0xff; @@ -634,10 +636,10 @@ store_16_le (unsigned int val, void *vp) static inline void store_32_le (unsigned int val, void *vp) { - unsigned char *p = vp; -#if defined(__GNUC__) && defined(K5_LE) + unsigned char *p = (unsigned char *) vp; +#if defined(__GNUC__) && defined(K5_LE) && !defined(__cplusplus) PUT(32,p,val); -#elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP32) +#elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP32) && !defined(__cplusplus) PUTSWAPPED(32,p,val); #else p[3] = (val >> 24) & 0xff; @@ -649,10 +651,10 @@ store_32_le (unsigned int val, void *vp) static inline void store_64_le (UINT64_TYPE val, void *vp) { - unsigned char *p = vp; -#if defined(__GNUC__) && defined(K5_LE) + unsigned char *p = (unsigned char *) vp; +#if defined(__GNUC__) && defined(K5_LE) && !defined(__cplusplus) PUT(64,p,val); -#elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP64) +#elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP64) && !defined(__cplusplus) PUTSWAPPED(64,p,val); #else p[7] = (unsigned char)((val >> 56) & 0xff); @@ -668,10 +670,10 @@ store_64_le (UINT64_TYPE val, void *vp) static inline unsigned short load_16_le (const void *cvp) { - const unsigned char *p = cvp; -#if defined(__GNUC__) && defined(K5_LE) + const unsigned char *p = (const unsigned char *) cvp; +#if defined(__GNUC__) && defined(K5_LE) && !defined(__cplusplus) return GET(16,p); -#elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP16) +#elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP16) && !defined(__cplusplus) return GETSWAPPED(16,p); #else return (p[0] | (p[1] << 8)); @@ -680,10 +682,10 @@ load_16_le (const void *cvp) static inline unsigned int load_32_le (const void *cvp) { - const unsigned char *p = cvp; -#if defined(__GNUC__) && defined(K5_LE) + const unsigned char *p = (const unsigned char *) cvp; +#if defined(__GNUC__) && defined(K5_LE) && !defined(__cplusplus) return GET(32,p); -#elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP32) +#elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP32) && !defined(__cplusplus) return GETSWAPPED(32,p); #else return (p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24)); @@ -692,10 +694,10 @@ load_32_le (const void *cvp) static inline UINT64_TYPE load_64_le (const void *cvp) { - const unsigned char *p = cvp; -#if defined(__GNUC__) && defined(K5_LE) + const unsigned char *p = (const unsigned char *) cvp; +#if defined(__GNUC__) && defined(K5_LE) && !defined(__cplusplus) return GET(64,p); -#elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP64) +#elif defined(__GNUC__) && defined(K5_BE) && defined(SWAP64) && !defined(__cplusplus) return GETSWAPPED(64,p); #else return ((UINT64_TYPE)load_32_le(p+4) << 32) | load_32_le(p); diff --git a/src/tests/misc/Makefile.in b/src/tests/misc/Makefile.in index 98cd02be9..45c43f44a 100644 --- a/src/tests/misc/Makefile.in +++ b/src/tests/misc/Makefile.in @@ -11,15 +11,17 @@ SRCS=\ $(srcdir)/test_getpw.c \ $(srcdir)/test_getsockname.c \ $(srcdir)/test_cxx_krb5.cpp \ + $(srcdir)/test_cxx_k5int.cpp \ $(srcdir)/test_cxx_gss.cpp \ $(srcdir)/test_cxx_rpc.cpp \ $(srcdir)/test_cxx_kadm5.cpp all:: test_getpw -check:: test_getpw test_cxx_krb5 test_cxx_gss test_cxx_rpc test_cxx_kadm5 +check:: test_getpw test_cxx_krb5 test_cxx_gss test_cxx_rpc test_cxx_k5int test_cxx_kadm5 $(RUN_SETUP) $(VALGRIND) ./test_getpw $(RUN_SETUP) $(VALGRIND) ./test_cxx_krb5 + $(RUN_SETUP) $(VALGRIND) ./test_cxx_k5int $(RUN_SETUP) $(VALGRIND) ./test_cxx_gss $(RUN_SETUP) $(VALGRIND) ./test_cxx_rpc $(RUN_SETUP) $(VALGRIND) ./test_cxx_kadm5 @@ -32,6 +34,8 @@ test_getsockname: $(OUTPRE)test_getsockname.$(OBJEXT) test_cxx_krb5: $(OUTPRE)test_cxx_krb5.$(OBJEXT) $(KRB5_DEPLIB) $(CXX_LINK) $(ALL_CXXFLAGS) -o test_cxx_krb5 $(OUTPRE)test_cxx_krb5.$(OBJEXT) $(KRB5_BASE_LIBS) $(LIBS) +test_cxx_k5int: $(OUTPRE)test_cxx_k5int.$(OBJEXT) $(KRB5_DEPLIB) + $(CXX_LINK) $(ALL_CXXFLAGS) -o test_cxx_k5int $(OUTPRE)test_cxx_k5int.$(OBJEXT) $(KRB5_BASE_LIBS) $(LIBS) test_cxx_gss: $(OUTPRE)test_cxx_gss.$(OBJEXT) $(CXX_LINK) $(ALL_CXXFLAGS) -o test_cxx_gss $(OUTPRE)test_cxx_gss.$(OBJEXT) $(LIBS) test_cxx_rpc: $(OUTPRE)test_cxx_rpc.$(OBJEXT) $(GSSRPC_DEPLIBS) diff --git a/src/tests/misc/test_cxx_k5int.cpp b/src/tests/misc/test_cxx_k5int.cpp new file mode 100644 index 000000000..602fe94bf --- /dev/null +++ b/src/tests/misc/test_cxx_k5int.cpp @@ -0,0 +1,19 @@ +// Test that the krb5 internal headers are compatible with C++ code. +// (Some Windows-specific code is in C++ in this source tree.) + +#include +#include "k5-int.h" +#include "k5-ipc_stream.h" +#include "k5-utf8.h" + +int main (int argc, char *argv[]) +{ + krb5_context ctx; + + if (krb5_init_context(&ctx) != 0) { + printf("krb5_init_context returned an error\n"); + return 1; + } + printf("hello, world\n"); + return 0; +} diff --git a/src/util/support/ipc_stream.c b/src/util/support/ipc_stream.c index 4037fe87d..28c6614f9 100644 --- a/src/util/support/ipc_stream.c +++ b/src/util/support/ipc_stream.c @@ -1,7 +1,7 @@ /* * $Header$ * - * Copyright 2006, 2007 Massachusetts Institute of Technology. + * Copyright 2006, 2007, 2009 Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -37,13 +37,13 @@ /* Add debugging later */ #define k5_check_error(x) (x) -struct k5_ipc_stream { +struct k5_ipc_stream_s { char *data; uint64_t size; uint64_t max_size; }; -const struct k5_ipc_stream k5_ipc_stream_initializer = { NULL, 0, 0 }; +const struct k5_ipc_stream_s k5_ipc_stream_initializer = { NULL, 0, 0 }; #define K5_IPC_STREAM_SIZE_INCREMENT 128