Skip to content

Commit 7863d61

Browse files
committed
fix struct types for Xcode
1 parent ec4d7db commit 7863d61

10 files changed

+659
-365
lines changed

input/minimal_ping.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
typedef struct MUST_USE_STRUCT LDKPing {
7+
/**
8+
* A pointer to the opaque Rust object.
9+
* Nearly everywhere, inner must be non-null, however in places where
10+
* the Rust equivalent takes an Option, it may be set to null to indicate None.
11+
*/
12+
LDKnativePing *inner;
13+
/**
14+
* Indicates that this is the only struct which contains the same pointer.
15+
* Rust functions which take ownership of an object provided via an argument require
16+
* this to be true and invalidate the object pointed to by inner.
17+
*/
18+
bool is_owned;
19+
} LDKPing;
20+
21+
/**
22+
* Frees any resources used by the Ping, if is_owned is set and inner is non-NULL.
23+
*/
24+
void Ping_free(struct LDKPing this_obj);
25+
26+
/**
27+
* The desired response length
28+
*/
29+
uint16_t Ping_get_ponglen(const struct LDKPing *NONNULL_PTR this_ptr);
30+
31+
/**
32+
* The desired response length
33+
*/
34+
void Ping_set_ponglen(struct LDKPing *NONNULL_PTR this_ptr, uint16_t val);
35+
36+
/**
37+
* The ping packet size.
38+
* This field is not sent on the wire. byteslen zeros are sent.
39+
*/
40+
uint16_t Ping_get_byteslen(const struct LDKPing *NONNULL_PTR this_ptr);
41+
42+
/**
43+
* The ping packet size.
44+
* This field is not sent on the wire. byteslen zeros are sent.
45+
*/
46+
void Ping_set_byteslen(struct LDKPing *NONNULL_PTR this_ptr, uint16_t val);
47+
48+
/**
49+
* Constructs a new Ping given each field
50+
*/
51+
MUST_USE_RES struct LDKPing Ping_new(uint16_t ponglen_arg, uint16_t byteslen_arg);
52+
53+
/**
54+
* Creates a copy of the Ping
55+
*/
56+
struct LDKPing Ping_clone(const struct LDKPing *NONNULL_PTR orig);

input/minimal_tuple.h

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
typedef struct LDKThirtyTwoBytes {
2-
uint8_t data[32];
3-
} LDKThirtyTwoBytes;
1+
//typedef struct LDKThirtyTwoBytes {
2+
// uint8_t data[32];
3+
//} LDKThirtyTwoBytes;
4+
//
5+
//typedef struct LDKC2Tuple_u64u64Z {
6+
// uint64_t a;
7+
// uint64_t b;
8+
//} LDKC2Tuple_u64u64Z;
9+
//
10+
//struct LDKC2Tuple_u64u64Z C2Tuple_u64u64Z_clone(const struct LDKC2Tuple_u64u64Z *NONNULL_PTR orig);
11+
//
12+
//void C2Tuple_u64u64Z_free(struct LDKC2Tuple_u64u64Z _res);
13+
//
14+
//struct LDKC2Tuple_u64u64Z C2Tuple_u64u64Z_new(uint64_t a, uint64_t b);
415

5-
typedef struct LDKC2Tuple_u64u64Z {
6-
uint64_t a;
7-
uint64_t b;
8-
} LDKC2Tuple_u64u64Z;
16+
typedef struct LDKCVec_u8Z {
17+
uint8_t *data;
18+
uintptr_t datalen;
19+
} LDKCVec_u8Z;
920

10-
struct LDKC2Tuple_u64u64Z C2Tuple_u64u64Z_clone(const struct LDKC2Tuple_u64u64Z *NONNULL_PTR orig);
21+
typedef struct LDKC2Tuple_u32ScriptZ {
22+
uint32_t a;
23+
struct LDKCVec_u8Z b;
24+
} LDKC2Tuple_u32ScriptZ;
1125

12-
void C2Tuple_u64u64Z_free(struct LDKC2Tuple_u64u64Z _res);
13-
14-
struct LDKC2Tuple_u64u64Z C2Tuple_u64u64Z_new(uint64_t a, uint64_t b);
26+
void CVec_u8Z_free(struct LDKCVec_u8Z _res);

src/binding_types.py

Lines changed: 75 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,84 @@
11
class TypeInfo:
2-
def __init__(self, is_native_primitive, rust_obj, java_ty, java_fn_ty_arg, java_hu_ty, c_ty, is_const, passed_as_ptr, is_ptr, var_name, arr_len, arr_access, subty=None):
3-
self.is_native_primitive = is_native_primitive
4-
self.rust_obj = rust_obj
5-
self.java_ty = java_ty
6-
self.java_hu_ty = java_hu_ty
7-
self.java_fn_ty_arg = java_fn_ty_arg
8-
self.c_ty = c_ty
9-
self.is_const = is_const
10-
self.passed_as_ptr = passed_as_ptr
11-
self.is_ptr = is_ptr
12-
self.var_name = var_name
13-
self.arr_len = arr_len
14-
self.arr_access = arr_access
15-
self.subty = subty
16-
self.pass_by_ref = is_ptr
17-
self.requires_clone = None
2+
def __init__(self, is_native_primitive, rust_obj, swift_type, c_ty, is_const, passed_as_ptr, is_ptr, var_name,
3+
arr_len, arr_access, subty=None):
4+
self.is_native_primitive = is_native_primitive
5+
self.rust_obj = rust_obj
6+
# self.java_ty = java_ty
7+
# self.java_hu_ty = java_hu_ty
8+
# self.java_fn_ty_arg = java_fn_ty_arg
9+
self.swift_type = swift_type
10+
self.c_ty = c_ty
11+
self.is_const = is_const
12+
self.passed_as_ptr = passed_as_ptr
13+
self.is_ptr = is_ptr
14+
self.var_name = var_name
15+
self.arr_len = arr_len
16+
self.arr_access = arr_access
17+
self.subty = subty
18+
self.pass_by_ref = is_ptr
19+
self.requires_clone = None
1820

19-
def get_full_rust_ty(self):
20-
ret = ""
21-
if self.is_const:
22-
ret = "const "
23-
if self.rust_obj is not None:
24-
ret = ret + self.rust_obj
25-
if self.is_ptr:
26-
ret = ret + " *"
21+
def get_full_rust_ty(self):
22+
ret = ""
23+
if self.is_const:
24+
ret = "const "
25+
if self.rust_obj is not None:
26+
ret = ret + self.rust_obj
27+
if self.is_ptr:
28+
ret = ret + " *"
29+
30+
if self.arr_len is not None and self.arr_len.isnumeric():
31+
if self.rust_obj is not None:
32+
return (ret, "")
33+
assert self.c_ty.endswith("Array")
34+
if self.is_const:
35+
return ("const u" + self.c_ty[:-5] + " (*", ")[" + self.arr_len + "]")
36+
else:
37+
return ("u" + self.c_ty[:-5] + " (*", ")[" + self.arr_len + "]")
38+
if self.rust_obj is None:
39+
if self.c_ty.startswith("int"):
40+
# Ironically the entire API uses no signed integers. We really should handle this better, but for now just always add a u
41+
return ("u" + self.c_ty, "")
42+
if self.c_ty == "jboolean":
43+
return ("bool", "")
44+
return (self.c_ty, "")
45+
return (ret, "")
2746

28-
if self.arr_len is not None and self.arr_len.isnumeric():
29-
if self.rust_obj is not None:
30-
return (ret, "")
31-
assert self.c_ty.endswith("Array")
32-
if self.is_const:
33-
return ("const u" + self.c_ty[:-5] + " (*", ")[" + self.arr_len + "]")
34-
else:
35-
return ("u" + self.c_ty[:-5] + " (*", ")[" + self.arr_len + "]")
36-
if self.rust_obj is None:
37-
if self.c_ty.startswith("int"):
38-
# Ironically the entire API uses no signed integers. We really should handle this better, but for now just always add a u
39-
return ("u" + self.c_ty, "")
40-
if self.c_ty == "jboolean":
41-
return ("bool", "")
42-
return (self.c_ty, "")
43-
return (ret, "")
4447

4548
class ConvInfo:
46-
def __init__(self, ty_info, arg_name, arg_conv, arg_conv_name, arg_conv_cleanup, ret_conv, ret_conv_name, to_hu_conv, to_hu_conv_name, from_hu_conv):
47-
assert(ty_info.c_ty is not None)
48-
assert(ty_info.java_ty is not None)
49-
assert(arg_name is not None)
50-
self.passed_as_ptr = ty_info.passed_as_ptr
51-
self.rust_obj = ty_info.rust_obj
52-
self.c_ty = ty_info.c_ty
53-
self.java_ty = ty_info.java_ty
54-
self.java_hu_ty = ty_info.java_hu_ty
55-
self.java_fn_ty_arg = ty_info.java_fn_ty_arg
56-
self.is_native_primitive = ty_info.is_native_primitive
57-
self.ty_info = ty_info
58-
self.arg_name = arg_name
59-
self.arg_conv = arg_conv
60-
self.arg_conv_name = arg_conv_name
61-
self.arg_conv_cleanup = arg_conv_cleanup
62-
self.ret_conv = ret_conv
63-
self.ret_conv_name = ret_conv_name
64-
self.to_hu_conv = to_hu_conv
65-
self.to_hu_conv_name = to_hu_conv_name
66-
self.from_hu_conv = from_hu_conv
49+
def __init__(self, ty_info, arg_name, arg_conv, arg_conv_name, arg_conv_cleanup, ret_conv, ret_conv_name,
50+
to_hu_conv, to_hu_conv_name, from_hu_conv):
51+
assert (ty_info.c_ty is not None)
52+
assert (ty_info.java_ty is not None)
53+
assert (arg_name is not None)
54+
self.passed_as_ptr = ty_info.passed_as_ptr
55+
self.rust_obj = ty_info.rust_obj
56+
self.c_ty = ty_info.c_ty
57+
self.java_ty = ty_info.java_ty
58+
self.java_hu_ty = ty_info.java_hu_ty
59+
self.java_fn_ty_arg = ty_info.java_fn_ty_arg
60+
self.is_native_primitive = ty_info.is_native_primitive
61+
self.ty_info = ty_info
62+
self.arg_name = arg_name
63+
self.arg_conv = arg_conv
64+
self.arg_conv_name = arg_conv_name
65+
self.arg_conv_cleanup = arg_conv_cleanup
66+
self.ret_conv = ret_conv
67+
self.ret_conv_name = ret_conv_name
68+
self.to_hu_conv = to_hu_conv
69+
self.to_hu_conv_name = to_hu_conv_name
70+
self.from_hu_conv = from_hu_conv
71+
6772

6873
class TraitMethInfo:
69-
def __init__(self, fn_name, self_is_const, ret_ty_info, args_ty):
70-
self.fn_name = fn_name
71-
self.self_is_const = self_is_const
72-
self.ret_ty_info = ret_ty_info
73-
self.args_ty = args_ty
74+
def __init__(self, fn_name, self_is_const, ret_ty_info, args_ty):
75+
self.fn_name = fn_name
76+
self.self_is_const = self_is_const
77+
self.ret_ty_info = ret_ty_info
78+
self.args_ty = args_ty
79+
7480

7581
class ComplexEnumVariantInfo:
76-
def __init__(self, var_name, fields):
77-
self.var_name = var_name
78-
self.fields = fields
82+
def __init__(self, var_name, fields):
83+
self.var_name = var_name
84+
self.fields = fields

0 commit comments

Comments
 (0)