-
Notifications
You must be signed in to change notification settings - Fork 48
[JExtract] Import Foundation.Data
if used
#301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,10 @@ | |
import org.swift.swiftkit.ffm.AllocatingSwiftArena; | ||
import org.swift.swiftkit.ffm.SwiftRuntime; | ||
|
||
import java.lang.foreign.MemoryLayout; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.ValueLayout; | ||
|
||
public class HelloJava2Swift { | ||
|
||
public static void main(String[] args) { | ||
|
@@ -78,6 +82,20 @@ static void examples() { | |
}); | ||
} | ||
|
||
// Example of using 'Data'. | ||
try (var arena = AllocatingSwiftArena.ofConfined()) { | ||
var origBytes = arena.allocateFrom("foobar"); | ||
var origDat = Data.init(origBytes, origBytes.byteSize(), arena); | ||
SwiftRuntime.trace("origDat.count = " + origDat.getCount()); | ||
|
||
var retDat = MySwiftLibrary.globalReceiveReturnData(origDat, arena); | ||
retDat.withUnsafeBytes((retBytes) -> { | ||
var str = retBytes.getString(0); | ||
SwiftRuntime.trace("retStr=" + str); | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice! btw I'm thinking we should start trying to move all these examples into tests, so we'll get a better report "what failed" when CI fails. But this we can do later separately |
||
|
||
|
||
System.out.println("DONE."); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ package class FFMSwift2JavaGenerator: Swift2JavaGenerator { | |
let javaPackage: String | ||
let swiftOutputDirectory: String | ||
let javaOutputDirectory: String | ||
let swiftStdlibTypes: SwiftStandardLibraryTypeDecls | ||
let symbolTable: SwiftSymbolTable | ||
|
||
var javaPackagePath: String { | ||
|
@@ -53,7 +52,6 @@ package class FFMSwift2JavaGenerator: Swift2JavaGenerator { | |
self.swiftOutputDirectory = swiftOutputDirectory | ||
self.javaOutputDirectory = javaOutputDirectory | ||
self.symbolTable = translator.symbolTable | ||
self.swiftStdlibTypes = translator.swiftStdlibTypeDecls | ||
|
||
// If we are forced to write empty files, construct the expected outputs | ||
if translator.config.writeEmptyFiles ?? false { | ||
|
@@ -65,6 +63,9 @@ package class FFMSwift2JavaGenerator: Swift2JavaGenerator { | |
return String(filePathPart.replacing(".swift", with: "+SwiftJava.swift")) | ||
}) | ||
self.expectedOutputSwiftFiles.insert("\(translator.swiftModuleName)Module+SwiftJava.swift") | ||
|
||
// FIXME: Can we avoid this? | ||
self.expectedOutputSwiftFiles.insert("Data+SwiftJava.swift") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is unavoidable in today's SwiftPM. Can we call the file FYI ongoing sadness with build plugins @bnbarham heh |
||
} else { | ||
self.expectedOutputSwiftFiles = [] | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That FIXME will be hard to resolve... we'd have to grep files manually for any foundation imports etc I guess before we run any of the commands :(
But yeah, good to keep that fixme