Skip to content

Typos in FFM tutorials #135

@danthe1st

Description

@danthe1st

There are a few typos and similar issues in the new FFM tutorials.


https://dev.java/learn/ffm/access-memory/

In the section "Allocate a MemorySegment with an Arena", the text "should be deallocated and no longer valid." is missing the word "is". It should be "Each arena has a scope, which specifies when the off-heap memory (associated with the MemorySegment object) should be deallocated and is no longer valid."

The section "Print a Value Stored in the Off-Heap Memory" contains the text "With the methods within MemorySegment interface" which is missing "the" (and a comma at the end). It should be "With the methods within the MemorySegment interface, , you can read from or write to memory segments."

In the same section, "For example, MemoryLayout.get(ValueLayout.OfByte,long) takes as an argument ValueLayout.JAVA_BYTE" refers to a nonexistent method. I assume it should be MemorySegment instead of MemoryLayout.

The codeblock at the end of that article contains the following code:

String pattern = "********"; 

try (Arena arena = Arena.ofConfined()) {
    MemorySegment nativeString = arena.allocateFrom(pattern);
} 

for (int i = 0; i < s.length(); i++ ) {
    // Exception in thread "main" java.lang.IllegalStateException: Already closed
    System.out.print((char)nativeString.get(ValueLayout.JAVA_BYTE, i)); 
}

Here, nativeString is declared within the try-with-resources block so accessing the variable outside is a compiler-error.


https://dev.java/learn/ffm/native/

The first sentence contains "As Foreign Function and Memory API can help you" which is missing a missing "the" It should be "As the Foreign Function and Memory API can help you with invoking native code,"

The first codeblock in the section "Locate the Address of the C Function" mentions "libc.so.6" which probably doesn't work on Windows. It might be a good idea to add a comment orr similar to avoid confusion (or mention the Windows DLL providing that function).

The same codeblock also contains the line "MemorySegment strlen_addr = stdLib.find("strdup").get(); ". This MemorySegment is named strlen_addr even though the function is not strlen.

The section "Describe the C Function Signature" contains invalid links to StructLayout and UnionLayout (starting with javadoc:). This is likely due to using inline Markdown codeblocks within links


https://dev.java/learn/ffm/access-structure/

The first paragraph of this article contains "An elegant solution is to use memory layouts that are more efficiently to initialize and can access more complex native data types such as C structures." - What's meant with "are more efficiently"?

In the final code snippet of the first section, the line "resultDenominator = d1 * d2;" references variables that are not declared at that point. I think this line should be removed.


https://dev.java/learn/ffm/upcall/

The second codeblock in the section "Create a Downcall Method Handle for the Foreign Function" contains a declaration "final static Linker linker". Since most people put static before final, I suggest reordering that.


https://dev.java/learn/ffm/troubleshoot/

The first section of this article contains the sentence "While not directly accessible, the goal of a zero-length memory segments is to pass them to other pointer-accepting foreign functions". I think the article "a" is incorrect there due to the plural afterwards and should therefore be removed.

The table at the end of that article (listing restricted methods) is out of bounds on small screens (e.g. mobile phones).


https://dev.java/learn/ffm/jextract/

The teapot code uses the line glutInit(argc, argc);. Iss it intentional that argc is used twice there? While it shouldn't matter (because argc is 0), I think this should at least be explained (or replaced by another MemorySegment).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions