Skip to content

Commit f3429b6

Browse files
Matt CoralloTheBlueMatt
authored andcommitted
Treat pointers up to 4096 as null, matching our test values in ldk-c-bindings
1 parent 886f490 commit f3429b6

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

java_strings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(self, DEBUG: bool, target: Target, **kwargs):
115115
class CommonBase {
116116
long ptr;
117117
LinkedList<Object> ptrs_to = new LinkedList();
118-
protected CommonBase(long ptr) { assert ptr < 0 || ptr > 1024; this.ptr = ptr; }
118+
protected CommonBase(long ptr) { assert ptr < 0 || ptr > 4096; this.ptr = ptr; }
119119
}
120120
"""
121121

@@ -161,7 +161,7 @@ class CommonBase {
161161

162162
if not DEBUG or sys.platform == "darwin":
163163
self.c_file_pfx = self.c_file_pfx + """#define MALLOC(a, _) malloc(a)
164-
#define FREE(p) if ((uint64_t)(p) > 1024) { free(p); }
164+
#define FREE(p) if ((uint64_t)(p) > 4096) { free(p); }
165165
#define CHECK_ACCESS(p)
166166
"""
167167
if not DEBUG:
@@ -298,7 +298,7 @@ class CommonBase {
298298
__real_free(it);
299299
}
300300
static void FREE(void* ptr) {
301-
if ((uint64_t)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
301+
if ((uint64_t)ptr <= 4096) return; // Rust loves to create pointers to the NULL page for dummys
302302
alloc_freed(ptr);
303303
__real_free(ptr);
304304
}
@@ -1277,7 +1277,7 @@ def map_function(self, argument_types, c_call_string, method_name, meth_n, retur
12771277
out_java_struct += (info.arg_name)
12781278
out_java_struct += (");\n")
12791279
if return_type_info.java_ty == "long" and return_type_info.java_hu_ty != "long":
1280-
out_java_struct += "\t\tif (ret >= 0 && ret < 1024) { return null; }\n"
1280+
out_java_struct += "\t\tif (ret >= 0 && ret <= 4096) { return null; }\n"
12811281

12821282
if return_type_info.to_hu_conv is not None:
12831283
if not takes_self:

typescript_strings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __init__(self, DEBUG: bool, target: Target, **kwargs):
120120
void free(void *ptr);
121121
122122
#define MALLOC(a, _) malloc(a)
123-
#define FREE(p) if ((unsigned long)(p) > 1024) { free(p); }
123+
#define FREE(p) if ((unsigned long)(p) > 4096) { free(p); }
124124
#define DO_ASSERT(a) (void)(a)
125125
#define CHECK(a)
126126
#define CHECK_ACCESS(p)
@@ -175,7 +175,7 @@ def __init__(self, DEBUG: bool, target: Target, **kwargs):
175175
__real_free(it);
176176
}
177177
static void FREE(void* ptr) {
178-
if ((unsigned long)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
178+
if ((unsigned long)ptr <= 4096) return; // Rust loves to create pointers to the NULL page for dummys
179179
alloc_freed(ptr);
180180
__real_free(ptr);
181181
}

0 commit comments

Comments
 (0)