Make slice-vec-len generic
authorMatt Corallo <git@bluematt.me>
Tue, 6 Oct 2020 22:42:38 +0000 (18:42 -0400)
committerMatt Corallo <git@bluematt.me>
Tue, 6 Oct 2020 22:43:50 +0000 (18:43 -0400)
genbindings.py
src/main/java/org/ldk/impl/bindings.java
src/main/jni/bindings.c
src/main/jni/org_ldk_impl_bindings.h

index a5e9ec41e38c62742b561606341f301aa0bd3b0c..9c647a6362c82b3ca9f095be9b8d65a841607881 100755 (executable)
@@ -544,7 +544,7 @@ void __attribute__((destructor)) check_leaks() {
        public static native void free_heap_ptr(long ptr);
        public static native byte[] get_u8_slice_bytes(long slice_ptr);
        public static native long bytes_to_u8_vec(byte[] bytes);
-       public static native long u8_vec_len(long vec);
+       public static native long vec_slice_len(long vec);
 
 """)
     out_c.write("""
@@ -576,7 +576,12 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec (JNIEnv * _
        (*_env)->GetByteArrayRegion (_env, bytes, 0, vec->datalen, vec->data);
        return (long)vec;
 }
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_u8_1vec_1len (JNIEnv * env, jclass _a, jlong ptr) {
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) {
+        // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically");
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically");
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically");
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_C2Tuple_usizeTransactionZZ, datalen), "Vec<*> needs to be mapped identically");
        LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
        return (long)vec->datalen;
 }
index b9d228b0fe3e414b1a9e5fbbc491698115f9af86..f4eef6ba636c879e421b7ac42ed0c8fedb7905e4 100644 (file)
@@ -13,7 +13,7 @@ public class bindings {
        public static native void free_heap_ptr(long ptr);
        public static native byte[] get_u8_slice_bytes(long slice_ptr);
        public static native long bytes_to_u8_vec(byte[] bytes);
-       public static native long u8_vec_len(long vec);
+       public static native long vec_slice_len(long vec);
 
        public static native long LDKSecretKey_new();
 
index 732c134c54f320b0ccc714f3d43dc11114446128..d8f24ee2e9f734cdf47484fa2fa92fc3328de748 100644 (file)
@@ -77,7 +77,12 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec (JNIEnv * _
        (*_env)->GetByteArrayRegion (_env, bytes, 0, vec->datalen, vec->data);
        return (long)vec;
 }
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_u8_1vec_1len (JNIEnv * env, jclass _a, jlong ptr) {
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) {
+        // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically");
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically");
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically");
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_C2Tuple_usizeTransactionZZ, datalen), "Vec<*> needs to be mapped identically");
        LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
        return (long)vec->datalen;
 }
index 44fec81e443300856d3707948c40cde91f59832e..557d544318d7015d5bcf69e8ba3efec4ef89f192 100644 (file)
@@ -57,10 +57,10 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec
 
 /*
  * Class:     org_ldk_impl_bindings
- * Method:    u8_vec_len
+ * Method:    vec_slice_len
  * Signature: (J)J
  */
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_u8_1vec_1len
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len
   (JNIEnv *, jclass, jlong);
 
 /*