Skip to content

Commit e11dcea

Browse files
committed
Always mark @cdecl thunks we generate in lowering as public
1 parent 8f00df5 commit e11dcea

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

Sources/JExtractSwift/CDeclLowering/Swift2JavaTranslator+FunctionLowering.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ extension Swift2JavaTranslator {
4949

5050
return try lowerFunctionSignature(signature)
5151
}
52+
5253
/// Lower the given Swift function signature to a Swift @_cdecl function signature,
5354
/// which is C compatible, and the corresponding Java method signature.
5455
///
@@ -333,6 +334,11 @@ extension LoweredFunctionSignature {
333334
let cdeclAttribute: AttributeSyntax = "@_cdecl(\(literal: cName))\n"
334335
loweredCDecl.attributes.append(.attribute(cdeclAttribute))
335336

337+
// Make it public.
338+
loweredCDecl.modifiers.append(
339+
DeclModifierSyntax(name: .keyword(.public), trailingTrivia: .space)
340+
)
341+
336342
// Create the body.
337343

338344
// Lower "self", if there is one.

Tests/JExtractSwiftTests/FunctionLoweringTests.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class FunctionLoweringTests {
2626
""",
2727
expectedCDecl: """
2828
@_cdecl("c_f")
29-
func c_f(_ x: Int, _ y: Float, _ z_pointer: UnsafeRawPointer, _ z_count: Int) {
29+
public func c_f(_ x: Int, _ y: Float, _ z_pointer: UnsafeRawPointer, _ z_count: Int) {
3030
f(x: x, y: y, z: UnsafeBufferPointer<Bool>(start: z_pointer.assumingMemoryBound(to: Bool.self), count: z_count))
3131
}
3232
""",
@@ -41,7 +41,7 @@ final class FunctionLoweringTests {
4141
""",
4242
expectedCDecl: """
4343
@_cdecl("c_f")
44-
func c_f(_ t_0: Int, _ t_1_0: Float, _ t_1_1: Double, _ z_pointer: UnsafeRawPointer) -> Int {
44+
public func c_f(_ t_0: Int, _ t_1_0: Float, _ t_1_1: Double, _ z_pointer: UnsafeRawPointer) -> Int {
4545
return f(t: (t_0, (t_1_0, t_1_1)), z: z_pointer.assumingMemoryBound(to: Int.self))
4646
}
4747
""",
@@ -59,7 +59,7 @@ final class FunctionLoweringTests {
5959
""",
6060
expectedCDecl: """
6161
@_cdecl("c_shift")
62-
func c_shift(_ point: UnsafeMutableRawPointer, _ delta_0: Double, _ delta_1: Double) {
62+
public func c_shift(_ point: UnsafeMutableRawPointer, _ delta_0: Double, _ delta_1: Double) {
6363
shift(point: &point.assumingMemoryBound(to: Point.self).pointee, by: (delta_0, delta_1))
6464
}
6565
""",
@@ -78,7 +78,7 @@ final class FunctionLoweringTests {
7878
enclosingType: "Point",
7979
expectedCDecl: """
8080
@_cdecl("c_shifted")
81-
func c_shifted(_ delta_0: Double, _ delta_1: Double, _ self: UnsafeRawPointer, _ _result: UnsafeMutableRawPointer) {
81+
public func c_shifted(_ delta_0: Double, _ delta_1: Double, _ self: UnsafeRawPointer, _ _result: UnsafeMutableRawPointer) {
8282
_result.assumingMemoryBound(to: Point.self).initialize(to: self.assumingMemoryBound(to: Point.self).pointee.shifted(by: (delta_0, delta_1)))
8383
}
8484
""",
@@ -97,7 +97,7 @@ final class FunctionLoweringTests {
9797
enclosingType: "Point",
9898
expectedCDecl: """
9999
@_cdecl("c_shift")
100-
func c_shift(_ delta_0: Double, _ delta_1: Double, _ self: UnsafeMutableRawPointer) {
100+
public func c_shift(_ delta_0: Double, _ delta_1: Double, _ self: UnsafeMutableRawPointer) {
101101
self.assumingMemoryBound(to: Point.self).pointee.shift(by: (delta_0, delta_1))
102102
}
103103
""",
@@ -116,7 +116,7 @@ final class FunctionLoweringTests {
116116
enclosingType: "Point",
117117
expectedCDecl: """
118118
@_cdecl("c_shift")
119-
func c_shift(_ delta_0: Double, _ delta_1: Double, _ self: UnsafeRawPointer) {
119+
public func c_shift(_ delta_0: Double, _ delta_1: Double, _ self: UnsafeRawPointer) {
120120
unsafeBitCast(self, to: Point.self).shift(by: (delta_0, delta_1))
121121
}
122122
""",
@@ -135,7 +135,7 @@ final class FunctionLoweringTests {
135135
enclosingType: "Point",
136136
expectedCDecl: """
137137
@_cdecl("c_scaledUnit")
138-
func c_scaledUnit(_ value: Double, _ _result: UnsafeMutableRawPointer) {
138+
public func c_scaledUnit(_ value: Double, _ _result: UnsafeMutableRawPointer) {
139139
_result.assumingMemoryBound(to: Point.self).initialize(to: Point.scaledUnit(by: value))
140140
}
141141
""",
@@ -151,7 +151,7 @@ final class FunctionLoweringTests {
151151
enclosingType: "Person",
152152
expectedCDecl: """
153153
@_cdecl("c_randomPerson")
154-
func c_randomPerson(_ seed: Double) -> UnsafeRawPointer {
154+
public func c_randomPerson(_ seed: Double) -> UnsafeRawPointer {
155155
return unsafeBitCast(Person.randomPerson(seed: seed), to: UnsafeRawPointer.self)
156156
}
157157
""",
@@ -170,7 +170,7 @@ final class FunctionLoweringTests {
170170
enclosingType: "Point",
171171
expectedCDecl: """
172172
@_cdecl("c_init")
173-
func c_init(_ value: Double, _ _result: UnsafeMutableRawPointer) {
173+
public func c_init(_ value: Double, _ _result: UnsafeMutableRawPointer) {
174174
_result.assumingMemoryBound(to: Point.self).initialize(to: Point(scaledBy: value))
175175
}
176176
""",
@@ -186,7 +186,7 @@ final class FunctionLoweringTests {
186186
enclosingType: "Person",
187187
expectedCDecl: """
188188
@_cdecl("c_init")
189-
func c_init(_ seed: Double) -> UnsafeRawPointer {
189+
public func c_init(_ seed: Double) -> UnsafeRawPointer {
190190
return unsafeBitCast(Person(seed: seed), to: UnsafeRawPointer.self)
191191
}
192192
""",
@@ -201,7 +201,7 @@ final class FunctionLoweringTests {
201201
""",
202202
expectedCDecl: """
203203
@_cdecl("c_f")
204-
func c_f(_ t: UnsafeRawPointer) {
204+
public func c_f(_ t: UnsafeRawPointer) {
205205
f(t: unsafeBitCast(t, to: Int.self))
206206
}
207207
""",
@@ -213,7 +213,7 @@ final class FunctionLoweringTests {
213213
""",
214214
expectedCDecl: """
215215
@_cdecl("c_f")
216-
func c_f() -> UnsafeRawPointer {
216+
public func c_f() -> UnsafeRawPointer {
217217
return unsafeBitCast(f(), to: UnsafeRawPointer.self)
218218
}
219219
""",
@@ -232,7 +232,7 @@ final class FunctionLoweringTests {
232232
enclosingType: "Point",
233233
expectedCDecl: """
234234
@_cdecl("c_shifted")
235-
func c_shifted(_ delta_0: Double, _ delta_1: Double, _ self: UnsafeRawPointer) -> UnsafeRawPointer {
235+
public func c_shifted(_ delta_0: Double, _ delta_1: Double, _ self: UnsafeRawPointer) -> UnsafeRawPointer {
236236
return unsafeBitCast(unsafeBitCast(self, to: Point.self).shifted(by: (delta_0, delta_1)), to: UnsafeRawPointer.self)
237237
}
238238
""",
@@ -250,7 +250,7 @@ final class FunctionLoweringTests {
250250
""",
251251
expectedCDecl: """
252252
@_cdecl("c_getPointer")
253-
func c_getPointer() -> UnsafeRawPointer {
253+
public func c_getPointer() -> UnsafeRawPointer {
254254
return UnsafeRawPointer(getPointer())
255255
}
256256
""",
@@ -268,7 +268,7 @@ final class FunctionLoweringTests {
268268
""",
269269
expectedCDecl: """
270270
@_cdecl("c_getTuple")
271-
func c_getTuple(_ _result_0: UnsafeMutableRawPointer, _ _result_1_0: UnsafeMutableRawPointer, _ _result_1_1: UnsafeMutableRawPointer) {
271+
public func c_getTuple(_ _result_0: UnsafeMutableRawPointer, _ _result_1_0: UnsafeMutableRawPointer, _ _result_1_1: UnsafeMutableRawPointer) {
272272
let __swift_result = getTuple()
273273
_result_0 = __swift_result_0
274274
_result_1_0 = __swift_result_1_0
@@ -289,7 +289,7 @@ final class FunctionLoweringTests {
289289
""",
290290
expectedCDecl: """
291291
@_cdecl("c_getBufferPointer")
292-
func c_getBufferPointer(_result_pointer: UnsafeMutableRawPointer, _result_count: UnsafeMutableRawPointer) {
292+
public func c_getBufferPointer(_result_pointer: UnsafeMutableRawPointer, _result_count: UnsafeMutableRawPointer) {
293293
return UnsafeRawPointer(getPointer())
294294
}
295295
""",

0 commit comments

Comments
 (0)