svn rev #22455: branches/krb5-1-7/src/ include/ tests/misc/ util/support/

tlyu@MIT.EDU tlyu at MIT.EDU
Fri Jul 24 14:22:00 EDT 2009


http://src.mit.edu/fisheye/changelog/krb5/?cs=22455
Commit By: tlyu
Log Message:
ticket: 6536
version_fixed: 1.7.1
target_version: 1.7.1
tags: pullup
subject: 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


Changed Files:
U   branches/krb5-1-7/src/include/k5-int.h
U   branches/krb5-1-7/src/include/k5-ipc_stream.h
U   branches/krb5-1-7/src/include/k5-platform.h
U   branches/krb5-1-7/src/tests/misc/Makefile.in
A   branches/krb5-1-7/src/tests/misc/test_cxx_k5int.cpp
U   branches/krb5-1-7/src/util/support/ipc_stream.c
Modified: branches/krb5-1-7/src/include/k5-int.h
===================================================================
--- branches/krb5-1-7/src/include/k5-int.h	2009-07-23 18:48:13 UTC (rev 22454)
+++ branches/krb5-1-7/src/include/k5-int.h	2009-07-24 18:21:57 UTC (rev 22455)
@@ -2230,11 +2230,11 @@
 /*
  * 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;

Modified: branches/krb5-1-7/src/include/k5-ipc_stream.h
===================================================================
--- branches/krb5-1-7/src/include/k5-ipc_stream.h	2009-07-23 18:48:13 UTC (rev 22454)
+++ branches/krb5-1-7/src/include/k5-ipc_stream.h	2009-07-24 18:21:57 UTC (rev 22455)
@@ -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);

Modified: branches/krb5-1-7/src/include/k5-platform.h
===================================================================
--- branches/krb5-1-7/src/include/k5-platform.h	2009-07-23 18:48:13 UTC (rev 22454)
+++ branches/krb5-1-7/src/include/k5-platform.h	2009-07-24 18:21:57 UTC (rev 22455)
@@ -533,13 +533,15 @@
 # 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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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 @@
 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);

Modified: branches/krb5-1-7/src/tests/misc/Makefile.in
===================================================================
--- branches/krb5-1-7/src/tests/misc/Makefile.in	2009-07-23 18:48:13 UTC (rev 22454)
+++ branches/krb5-1-7/src/tests/misc/Makefile.in	2009-07-24 18:21:57 UTC (rev 22455)
@@ -11,15 +11,17 @@
 	$(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_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)

Added: branches/krb5-1-7/src/tests/misc/test_cxx_k5int.cpp
===================================================================
--- branches/krb5-1-7/src/tests/misc/test_cxx_k5int.cpp	2009-07-23 18:48:13 UTC (rev 22454)
+++ branches/krb5-1-7/src/tests/misc/test_cxx_k5int.cpp	2009-07-24 18:21:57 UTC (rev 22455)
@@ -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 <stdio.h>
+#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;
+}

Modified: branches/krb5-1-7/src/util/support/ipc_stream.c
===================================================================
--- branches/krb5-1-7/src/util/support/ipc_stream.c	2009-07-23 18:48:13 UTC (rev 22454)
+++ branches/krb5-1-7/src/util/support/ipc_stream.c	2009-07-24 18:21:57 UTC (rev 22455)
@@ -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
 




More information about the cvs-krb5 mailing list