Skip to content

Commit e28dda6

Browse files
committed
More statics and limit exports to Java methods at link
1 parent dab1777 commit e28dda6

File tree

4 files changed

+99
-95
lines changed

4 files changed

+99
-95
lines changed

genbindings.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ def map_trait(struct_name, field_var_lines, trait_fn_lines):
524524
} allocation;
525525
static allocation* allocation_ll = NULL;
526526
527-
void* MALLOC(size_t len, const char* struct_name) {
527+
static void* MALLOC(size_t len, const char* struct_name) {
528528
void* res = malloc(len);
529529
allocation* new_alloc = malloc(sizeof(allocation));
530530
new_alloc->ptr = res;
@@ -536,7 +536,7 @@ def map_trait(struct_name, field_var_lines, trait_fn_lines):
536536
return res;
537537
}
538538
539-
void FREE(void* ptr) {
539+
static void FREE(void* ptr) {
540540
allocation* p = NULL;
541541
DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
542542
allocation* it = allocation_ll;
@@ -582,9 +582,9 @@ def map_trait(struct_name, field_var_lines, trait_fn_lines):
582582
583583
""")
584584
out_c.write("""
585-
jmethodID ordinal_meth = NULL;
586-
jmethodID slicedef_meth = NULL;
587-
jclass slicedef_cls = NULL;
585+
static jmethodID ordinal_meth = NULL;
586+
static jmethodID slicedef_meth = NULL;
587+
static jclass slicedef_cls = NULL;
588588
JNIEXPORT void Java_org_ldk_impl_bindings_init(JNIEnv * env, jclass _b, jclass enum_class, jclass slicedef_class) {
589589
ordinal_meth = (*env)->GetMethodID(env, enum_class, "ordinal", "()I");
590590
DO_ASSERT(ordinal_meth != NULL);
@@ -782,8 +782,8 @@ def map_trait(struct_name, field_var_lines, trait_fn_lines):
782782
else:
783783
var_name = struct_line.strip(' ,')[len(struct_name) + 1:]
784784
out_java.write("\t\tpublic final static class " + var_name + " extends " + struct_name + " {\n")
785-
out_c.write("jclass " + struct_name + "_" + var_name + "_class = NULL;\n")
786-
out_c.write("jmethodID " + struct_name + "_" + var_name + "_meth = NULL;\n")
785+
out_c.write("static jclass " + struct_name + "_" + var_name + "_class = NULL;\n")
786+
out_c.write("static jmethodID " + struct_name + "_" + var_name + "_meth = NULL;\n")
787787
init_meth_jty_str = ""
788788
init_meth_params = ""
789789
init_meth_body = ""

genbindings.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ rm -f src/main/java/org/ldk/enums/*.java
1414
./genbindings.py "$1/lightning-c-bindings/include/lightning.h" src/main/java/org/ldk/impl/bindings.java src/main/java/org/ldk/enums src/main/jni/bindings.c $3
1515
javac -h src/main/jni src/main/java/org/ldk/enums/*.java src/main/java/org/ldk/impl/bindings.java
1616
rm src/main/java/org/ldk/enums/*.class src/main/java/org/ldk/impl/bindings*.class
17-
COMPILE="clang -std=c11 -Wall -Wno-unused-function -Wl,--no-undefined -pthread -ldl -o liblightningjni.so -shared -fPIC -Wno-pointer-sign -Isrc/main/jni"
17+
COMPILE="clang -std=c11 -Wall -Wno-unused-function -Wl,--no-undefined -pthread -ldl -o liblightningjni.so -shared -fPIC -Wno-pointer-sign -Isrc/main/jni -Wl,--version-script=libcode.version"
1818
if [ "$3" = "true" ]; then
1919
$COMPILE -g -fsanitize=address -shared-libasan -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/debug/libldk.a
2020
else

libcode.version

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
global: Java_org_ldk_*;
3+
local: *;
4+
};

src/main/jni/bindings.c

+87-87
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ typedef struct allocation {
2020
} allocation;
2121
static allocation* allocation_ll = NULL;
2222

23-
void* MALLOC(size_t len, const char* struct_name) {
23+
static void* MALLOC(size_t len, const char* struct_name) {
2424
void* res = malloc(len);
2525
allocation* new_alloc = malloc(sizeof(allocation));
2626
new_alloc->ptr = res;
@@ -32,7 +32,7 @@ void* MALLOC(size_t len, const char* struct_name) {
3232
return res;
3333
}
3434

35-
void FREE(void* ptr) {
35+
static void FREE(void* ptr) {
3636
allocation* p = NULL;
3737
DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
3838
allocation* it = allocation_ll;
@@ -49,9 +49,9 @@ void __attribute__((destructor)) check_leaks() {
4949
DO_ASSERT(allocation_ll == NULL);
5050
}
5151

52-
jmethodID ordinal_meth = NULL;
53-
jmethodID slicedef_meth = NULL;
54-
jclass slicedef_cls = NULL;
52+
static jmethodID ordinal_meth = NULL;
53+
static jmethodID slicedef_meth = NULL;
54+
static jclass slicedef_cls = NULL;
5555
JNIEXPORT void Java_org_ldk_impl_bindings_init(JNIEnv * env, jclass _b, jclass enum_class, jclass slicedef_class) {
5656
ordinal_meth = (*env)->GetMethodID(env, enum_class, "ordinal", "()I");
5757
DO_ASSERT(ordinal_meth != NULL);
@@ -436,16 +436,16 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZN
436436
return (long)((LDKCResult_CVec_SignatureZNoneZ*)arg)->contents.err;
437437
}
438438
}
439-
jclass LDKAPIError_APIMisuseError_class = NULL;
440-
jmethodID LDKAPIError_APIMisuseError_meth = NULL;
441-
jclass LDKAPIError_FeeRateTooHigh_class = NULL;
442-
jmethodID LDKAPIError_FeeRateTooHigh_meth = NULL;
443-
jclass LDKAPIError_RouteError_class = NULL;
444-
jmethodID LDKAPIError_RouteError_meth = NULL;
445-
jclass LDKAPIError_ChannelUnavailable_class = NULL;
446-
jmethodID LDKAPIError_ChannelUnavailable_meth = NULL;
447-
jclass LDKAPIError_MonitorUpdateFailed_class = NULL;
448-
jmethodID LDKAPIError_MonitorUpdateFailed_meth = NULL;
439+
static jclass LDKAPIError_APIMisuseError_class = NULL;
440+
static jmethodID LDKAPIError_APIMisuseError_meth = NULL;
441+
static jclass LDKAPIError_FeeRateTooHigh_class = NULL;
442+
static jmethodID LDKAPIError_FeeRateTooHigh_meth = NULL;
443+
static jclass LDKAPIError_RouteError_class = NULL;
444+
static jmethodID LDKAPIError_RouteError_meth = NULL;
445+
static jclass LDKAPIError_ChannelUnavailable_class = NULL;
446+
static jmethodID LDKAPIError_ChannelUnavailable_meth = NULL;
447+
static jclass LDKAPIError_MonitorUpdateFailed_class = NULL;
448+
static jmethodID LDKAPIError_MonitorUpdateFailed_meth = NULL;
449449
JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKAPIError_init (JNIEnv * env, jclass _a) {
450450
LDKAPIError_APIMisuseError_class =
451451
(*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$APIMisuseError;"));
@@ -552,12 +552,12 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKHTLCOutputInCommitment_1op
552552
ret->inner = NULL;
553553
return (long)ret;
554554
}
555-
jclass LDKSpendableOutputDescriptor_StaticOutput_class = NULL;
556-
jmethodID LDKSpendableOutputDescriptor_StaticOutput_meth = NULL;
557-
jclass LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class = NULL;
558-
jmethodID LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = NULL;
559-
jclass LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class = NULL;
560-
jmethodID LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = NULL;
555+
static jclass LDKSpendableOutputDescriptor_StaticOutput_class = NULL;
556+
static jmethodID LDKSpendableOutputDescriptor_StaticOutput_meth = NULL;
557+
static jclass LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class = NULL;
558+
static jmethodID LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = NULL;
559+
static jclass LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class = NULL;
560+
static jmethodID LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = NULL;
561561
JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKSpendableOutputDescriptor_init (JNIEnv * env, jclass _a) {
562562
LDKSpendableOutputDescriptor_StaticOutput_class =
563563
(*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutput;"));
@@ -597,20 +597,20 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1SpendableOutp
597597
LDKCVecTempl_SpendableOutputDescriptor *vec = (LDKCVecTempl_SpendableOutputDescriptor*)ptr;
598598
return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKSpendableOutputDescriptor));
599599
}
600-
jclass LDKEvent_FundingGenerationReady_class = NULL;
601-
jmethodID LDKEvent_FundingGenerationReady_meth = NULL;
602-
jclass LDKEvent_FundingBroadcastSafe_class = NULL;
603-
jmethodID LDKEvent_FundingBroadcastSafe_meth = NULL;
604-
jclass LDKEvent_PaymentReceived_class = NULL;
605-
jmethodID LDKEvent_PaymentReceived_meth = NULL;
606-
jclass LDKEvent_PaymentSent_class = NULL;
607-
jmethodID LDKEvent_PaymentSent_meth = NULL;
608-
jclass LDKEvent_PaymentFailed_class = NULL;
609-
jmethodID LDKEvent_PaymentFailed_meth = NULL;
610-
jclass LDKEvent_PendingHTLCsForwardable_class = NULL;
611-
jmethodID LDKEvent_PendingHTLCsForwardable_meth = NULL;
612-
jclass LDKEvent_SpendableOutputs_class = NULL;
613-
jmethodID LDKEvent_SpendableOutputs_meth = NULL;
600+
static jclass LDKEvent_FundingGenerationReady_class = NULL;
601+
static jmethodID LDKEvent_FundingGenerationReady_meth = NULL;
602+
static jclass LDKEvent_FundingBroadcastSafe_class = NULL;
603+
static jmethodID LDKEvent_FundingBroadcastSafe_meth = NULL;
604+
static jclass LDKEvent_PaymentReceived_class = NULL;
605+
static jmethodID LDKEvent_PaymentReceived_meth = NULL;
606+
static jclass LDKEvent_PaymentSent_class = NULL;
607+
static jmethodID LDKEvent_PaymentSent_meth = NULL;
608+
static jclass LDKEvent_PaymentFailed_class = NULL;
609+
static jmethodID LDKEvent_PaymentFailed_meth = NULL;
610+
static jclass LDKEvent_PendingHTLCsForwardable_class = NULL;
611+
static jmethodID LDKEvent_PendingHTLCsForwardable_meth = NULL;
612+
static jclass LDKEvent_SpendableOutputs_class = NULL;
613+
static jmethodID LDKEvent_SpendableOutputs_meth = NULL;
614614
JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKEvent_init (JNIEnv * env, jclass _a) {
615615
LDKEvent_FundingGenerationReady_class =
616616
(*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$FundingGenerationReady;"));
@@ -747,12 +747,12 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKErrorMessage_1optional_1no
747747
ret->inner = NULL;
748748
return (long)ret;
749749
}
750-
jclass LDKErrorAction_DisconnectPeer_class = NULL;
751-
jmethodID LDKErrorAction_DisconnectPeer_meth = NULL;
752-
jclass LDKErrorAction_IgnoreError_class = NULL;
753-
jmethodID LDKErrorAction_IgnoreError_meth = NULL;
754-
jclass LDKErrorAction_SendErrorMessage_class = NULL;
755-
jmethodID LDKErrorAction_SendErrorMessage_meth = NULL;
750+
static jclass LDKErrorAction_DisconnectPeer_class = NULL;
751+
static jmethodID LDKErrorAction_DisconnectPeer_meth = NULL;
752+
static jclass LDKErrorAction_IgnoreError_class = NULL;
753+
static jmethodID LDKErrorAction_IgnoreError_meth = NULL;
754+
static jclass LDKErrorAction_SendErrorMessage_class = NULL;
755+
static jmethodID LDKErrorAction_SendErrorMessage_meth = NULL;
756756
JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKErrorAction_init (JNIEnv * env, jclass _a) {
757757
LDKErrorAction_DisconnectPeer_class =
758758
(*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$DisconnectPeer;"));
@@ -786,12 +786,12 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKErrorAction_1ref_1from_1
786786
default: abort();
787787
}
788788
}
789-
jclass LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class = NULL;
790-
jmethodID LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = NULL;
791-
jclass LDKHTLCFailChannelUpdate_ChannelClosed_class = NULL;
792-
jmethodID LDKHTLCFailChannelUpdate_ChannelClosed_meth = NULL;
793-
jclass LDKHTLCFailChannelUpdate_NodeFailure_class = NULL;
794-
jmethodID LDKHTLCFailChannelUpdate_NodeFailure_meth = NULL;
789+
static jclass LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class = NULL;
790+
static jmethodID LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = NULL;
791+
static jclass LDKHTLCFailChannelUpdate_ChannelClosed_class = NULL;
792+
static jmethodID LDKHTLCFailChannelUpdate_ChannelClosed_meth = NULL;
793+
static jclass LDKHTLCFailChannelUpdate_NodeFailure_class = NULL;
794+
static jmethodID LDKHTLCFailChannelUpdate_NodeFailure_meth = NULL;
795795
JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKHTLCFailChannelUpdate_init (JNIEnv * env, jclass _a) {
796796
LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class =
797797
(*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelUpdateMessage;"));
@@ -827,38 +827,38 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKHTLCFailChannelUpdate_1r
827827
default: abort();
828828
}
829829
}
830-
jclass LDKMessageSendEvent_SendAcceptChannel_class = NULL;
831-
jmethodID LDKMessageSendEvent_SendAcceptChannel_meth = NULL;
832-
jclass LDKMessageSendEvent_SendOpenChannel_class = NULL;
833-
jmethodID LDKMessageSendEvent_SendOpenChannel_meth = NULL;
834-
jclass LDKMessageSendEvent_SendFundingCreated_class = NULL;
835-
jmethodID LDKMessageSendEvent_SendFundingCreated_meth = NULL;
836-
jclass LDKMessageSendEvent_SendFundingSigned_class = NULL;
837-
jmethodID LDKMessageSendEvent_SendFundingSigned_meth = NULL;
838-
jclass LDKMessageSendEvent_SendFundingLocked_class = NULL;
839-
jmethodID LDKMessageSendEvent_SendFundingLocked_meth = NULL;
840-
jclass LDKMessageSendEvent_SendAnnouncementSignatures_class = NULL;
841-
jmethodID LDKMessageSendEvent_SendAnnouncementSignatures_meth = NULL;
842-
jclass LDKMessageSendEvent_UpdateHTLCs_class = NULL;
843-
jmethodID LDKMessageSendEvent_UpdateHTLCs_meth = NULL;
844-
jclass LDKMessageSendEvent_SendRevokeAndACK_class = NULL;
845-
jmethodID LDKMessageSendEvent_SendRevokeAndACK_meth = NULL;
846-
jclass LDKMessageSendEvent_SendClosingSigned_class = NULL;
847-
jmethodID LDKMessageSendEvent_SendClosingSigned_meth = NULL;
848-
jclass LDKMessageSendEvent_SendShutdown_class = NULL;
849-
jmethodID LDKMessageSendEvent_SendShutdown_meth = NULL;
850-
jclass LDKMessageSendEvent_SendChannelReestablish_class = NULL;
851-
jmethodID LDKMessageSendEvent_SendChannelReestablish_meth = NULL;
852-
jclass LDKMessageSendEvent_BroadcastChannelAnnouncement_class = NULL;
853-
jmethodID LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = NULL;
854-
jclass LDKMessageSendEvent_BroadcastNodeAnnouncement_class = NULL;
855-
jmethodID LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = NULL;
856-
jclass LDKMessageSendEvent_BroadcastChannelUpdate_class = NULL;
857-
jmethodID LDKMessageSendEvent_BroadcastChannelUpdate_meth = NULL;
858-
jclass LDKMessageSendEvent_HandleError_class = NULL;
859-
jmethodID LDKMessageSendEvent_HandleError_meth = NULL;
860-
jclass LDKMessageSendEvent_PaymentFailureNetworkUpdate_class = NULL;
861-
jmethodID LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = NULL;
830+
static jclass LDKMessageSendEvent_SendAcceptChannel_class = NULL;
831+
static jmethodID LDKMessageSendEvent_SendAcceptChannel_meth = NULL;
832+
static jclass LDKMessageSendEvent_SendOpenChannel_class = NULL;
833+
static jmethodID LDKMessageSendEvent_SendOpenChannel_meth = NULL;
834+
static jclass LDKMessageSendEvent_SendFundingCreated_class = NULL;
835+
static jmethodID LDKMessageSendEvent_SendFundingCreated_meth = NULL;
836+
static jclass LDKMessageSendEvent_SendFundingSigned_class = NULL;
837+
static jmethodID LDKMessageSendEvent_SendFundingSigned_meth = NULL;
838+
static jclass LDKMessageSendEvent_SendFundingLocked_class = NULL;
839+
static jmethodID LDKMessageSendEvent_SendFundingLocked_meth = NULL;
840+
static jclass LDKMessageSendEvent_SendAnnouncementSignatures_class = NULL;
841+
static jmethodID LDKMessageSendEvent_SendAnnouncementSignatures_meth = NULL;
842+
static jclass LDKMessageSendEvent_UpdateHTLCs_class = NULL;
843+
static jmethodID LDKMessageSendEvent_UpdateHTLCs_meth = NULL;
844+
static jclass LDKMessageSendEvent_SendRevokeAndACK_class = NULL;
845+
static jmethodID LDKMessageSendEvent_SendRevokeAndACK_meth = NULL;
846+
static jclass LDKMessageSendEvent_SendClosingSigned_class = NULL;
847+
static jmethodID LDKMessageSendEvent_SendClosingSigned_meth = NULL;
848+
static jclass LDKMessageSendEvent_SendShutdown_class = NULL;
849+
static jmethodID LDKMessageSendEvent_SendShutdown_meth = NULL;
850+
static jclass LDKMessageSendEvent_SendChannelReestablish_class = NULL;
851+
static jmethodID LDKMessageSendEvent_SendChannelReestablish_meth = NULL;
852+
static jclass LDKMessageSendEvent_BroadcastChannelAnnouncement_class = NULL;
853+
static jmethodID LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = NULL;
854+
static jclass LDKMessageSendEvent_BroadcastNodeAnnouncement_class = NULL;
855+
static jmethodID LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = NULL;
856+
static jclass LDKMessageSendEvent_BroadcastChannelUpdate_class = NULL;
857+
static jmethodID LDKMessageSendEvent_BroadcastChannelUpdate_meth = NULL;
858+
static jclass LDKMessageSendEvent_HandleError_class = NULL;
859+
static jmethodID LDKMessageSendEvent_HandleError_meth = NULL;
860+
static jclass LDKMessageSendEvent_PaymentFailureNetworkUpdate_class = NULL;
861+
static jmethodID LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = NULL;
862862
JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKMessageSendEvent_init (JNIEnv * env, jclass _a) {
863863
LDKMessageSendEvent_SendAcceptChannel_class =
864864
(*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAcceptChannel;"));
@@ -2131,14 +2131,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKRoute_1optional_1none (JNI
21312131
ret->inner = NULL;
21322132
return (long)ret;
21332133
}
2134-
jclass LDKNetAddress_IPv4_class = NULL;
2135-
jmethodID LDKNetAddress_IPv4_meth = NULL;
2136-
jclass LDKNetAddress_IPv6_class = NULL;
2137-
jmethodID LDKNetAddress_IPv6_meth = NULL;
2138-
jclass LDKNetAddress_OnionV2_class = NULL;
2139-
jmethodID LDKNetAddress_OnionV2_meth = NULL;
2140-
jclass LDKNetAddress_OnionV3_class = NULL;
2141-
jmethodID LDKNetAddress_OnionV3_meth = NULL;
2134+
static jclass LDKNetAddress_IPv4_class = NULL;
2135+
static jmethodID LDKNetAddress_IPv4_meth = NULL;
2136+
static jclass LDKNetAddress_IPv6_class = NULL;
2137+
static jmethodID LDKNetAddress_IPv6_meth = NULL;
2138+
static jclass LDKNetAddress_OnionV2_class = NULL;
2139+
static jmethodID LDKNetAddress_OnionV2_meth = NULL;
2140+
static jclass LDKNetAddress_OnionV3_class = NULL;
2141+
static jmethodID LDKNetAddress_OnionV3_meth = NULL;
21422142
JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKNetAddress_init (JNIEnv * env, jclass _a) {
21432143
LDKNetAddress_IPv4_class =
21442144
(*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv4;"));

0 commit comments

Comments
 (0)