Skip to content

Commit

Permalink
Merge pull request #21 from Over-Run/update
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 authored Oct 6, 2024
2 parents 1520025 + 5b05153 commit 5f4446b
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
java: [
23-ea
23
]
os: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/javadoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/setup-java@v4
with:
java-version: |
23-ea
23
distribution: 'temurin'
- name: Grant execute permission for gradlew
if: ${{ runner.os != 'Windows' }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Import as a Gradle dependency:

```groovy
dependencies {
implementation("io.github.over-run:marshal:0.1.0-alpha.34-jdk23")
implementation("io.github.over-run:marshal:0.1.0-alpha.35-jdk23")
}
```

Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ allprojects {

dependencies {
// add your dependencies
compileOnly("org.jetbrains:annotations:24.1.0")
compileOnly("org.jetbrains:annotations:25.0.0")
testImplementation("org.junit.jupiter:junit-jupiter:$junitVersion")
testImplementation("io.github.over-run:platform:$platformVersion")
api("io.github.over-run:memstack:$memstackVersion")
Expand Down Expand Up @@ -172,6 +172,7 @@ tasks.withType<Javadoc> {
} else {
links("https://download.java.net/java/early_access/$jdkEarlyAccessDoc/docs/api/")
}
links("https://over-run.github.io/memstack/")
if (jdkEnablePreview.toBoolean()) {
addBooleanOption("-enable-preview", true)
addStringOption("source", jdkVersion)
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ projGroupId=io.github.over-run
projArtifactId=marshal
# The project name should only contain lowercase letters, numbers and hyphen.
projName=marshal
projVersion=0.1.0-alpha.34-jdk23
projVersion=0.1.0-alpha.35-jdk23
projDesc=Marshaler of native libraries
# Uncomment them if you want to publish to maven repository.
projUrl=https://github.com/Over-Run/marshal
Expand All @@ -32,7 +32,7 @@ jdkEnablePreview=true
# javadoc link of JDK early access build
# https://download.java.net/java/early_access/$jdkEarlyAccessDoc/docs/api/
# Uncomment it if you need to use EA build of JDK.
jdkEarlyAccessDoc=jdk23
#jdkEarlyAccessDoc=jdk23

junitVersion=5.11.0
memstackVersion=0.3.0
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/overrun/marshal/CanonicalLayouts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* MIT License
*
* Copyright (c) 2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/

package overrun.marshal;

import java.lang.foreign.Linker;
import java.lang.foreign.MemoryLayout;
import java.util.Map;

/**
* Common C memory layouts obtained with {@link Linker#canonicalLayouts()}.
*
* @author squid233
* @since 0.1.0
*/
public final class CanonicalLayouts {
private static final Map<String, MemoryLayout> canonicalLayouts = Linker.nativeLinker().canonicalLayouts();
/// Specified canonical layouts
public static final MemoryLayout BOOL = get("bool"),
CHAR = get("char"),
SHORT = get("short"),
INT = get("int"),
FLOAT = get("float"),
LONG = get("long"),
LONG_LONG = get("long long"),
DOUBLE = get("double"),
VOID_POINTER = get("void*"),
SIZE_T = get("size_t"),
WCHAR_T = get("wchar_t");

private CanonicalLayouts() {
}

/// Gets the layout from {@link Linker#canonicalLayouts()} with the given name.
///
/// @param name the name of the layout
/// @return the layout
public static MemoryLayout get(String name) {
return canonicalLayouts.get(name);
}
}
2 changes: 1 addition & 1 deletion src/main/java/overrun/marshal/Unmarshal.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private Unmarshal() {
* @param segment the native segment
*/
public static boolean isNullPointer(@Nullable MemorySegment segment) {
return segment == null || segment == MemorySegment.NULL || segment.address() == 0L;
return segment == null || segment.equals(MemorySegment.NULL);
}

/**
Expand Down

0 comments on commit 5f4446b

Please sign in to comment.