]> rtime.felk.cvut.cz Git - orte.git/commitdiff
JORTE: add static asserts on values of platform-specific sizes
authorMartin Vajnar <martin.vajnar@gmail.com>
Sat, 2 May 2015 12:51:10 +0000 (14:51 +0200)
committerMartin Vajnar <martin.vajnar@gmail.com>
Fri, 22 May 2015 11:33:21 +0000 (13:33 +0200)
If the sizes differ, die with error.

orte/libjorte/JORTERecvInfoHelpers.c

index da68b48ddf67cc975c155a89aa5cda0defa61a32..c113d5ff20d9ac0c84f3ed7fdc7ac6356e2a04af 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdint.h>
 #include <inttypes.h>
 #include <stddef.h>
+#include <assert.h>
 
 // library header file's path
 #include "orte_all.h"
 JNIEXPORT void JNICALL Java_org_ocera_orte_types_RecvInfo_c_1helper
   (JNIEnv *env, jclass cls, jobject b_buffer) {
 
+    _Static_assert(sizeof(char*) == 1 || \
+                   sizeof(char*) == 2 || \
+                   sizeof(char*) == 4 || \
+                   sizeof(char*) == 8, \
+                   "char* has incompatible size");
+    _Static_assert(sizeof(ORTERecvStatus) == 1 || \
+                   sizeof(ORTERecvStatus) == 2 || \
+                   sizeof(ORTERecvStatus) == 4 || \
+                   sizeof(ORTERecvStatus) == 8, \
+                   "ORTERecvStatus has incompatible size");
+
     int32_t* buffer = (*env)->GetDirectBufferAddress(env, b_buffer);
     
     buffer[0] = (int32_t)sizeof(ORTERecvInfo);