diff --git a/.github/workflows/check-diplomat.yml b/.github/workflows/check-diplomat.yml new file mode 100644 index 0000000..6769a00 --- /dev/null +++ b/.github/workflows/check-diplomat.yml @@ -0,0 +1,21 @@ + +name: Check Diplomat Compatibility + +on: + schedule: + - cron: "0 0 * * 5" + +env: + CARGO_TERM_COLOR: always + +jobs: + check-latest-diplomat: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Add latest dipomat + run: cargo add -p diplomat-java --git https://github.com/rust-diplomat/diplomat.git --branch main diplomat-tool diplomat-runtime diplomat_core + + - name: Check build + run: cargo build diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3c02bc9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,85 @@ +name: Diplomat Java CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + CARGO_TERM_COLOR: always + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Check rustfmt + run: cargo fmt --all -- --check + + - name: Check clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + build-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Build + run: cargo build --verbose + + - name: Run tests + run: cargo test --verbose + + msrv: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install MSRV Rust + run: rustup install 1.71 --profile minimal + + - name: Check + run: cargo +1.71 check -p diplomat-java -p jextrsact -p feature-tests + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install cargo-make + uses: taiki-e/install-action@cargo-make + - name: Set up JDK 22 for x64 + uses: actions/setup-java@v4 + with: + java-version: '22' + distribution: 'temurin' + architecture: x64 + cache: maven + - name: Test Java + run: cargo make test-feature + + test-gen: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install cargo-make + uses: taiki-e/install-action@cargo-make + - name: Install curl + run: sudo apt-get update && sudo apt-get install -y curl + - name: Set up JDK 22 for x64 + uses: actions/setup-java@v4 + with: + java-version: '22' + distribution: 'temurin' + architecture: x64 + cache: maven + - name: get jextract + run: curl -o /opt/jextract.tgz https://download.java.net/java/early_access/jextract/22/5/openjdk-22-jextract+5-33_linux-x64_bin.tar.gz + - name: config jextract + run: tar -xzf /opt/jextract.tgz -C /opt/ + - name: Add jextract to path + run: echo "/opt/jextract-22/bin" >> $GITHUB_PATH + - name: Run generated java + run: cargo make gen-feature + diff --git a/.gitignore b/.gitignore index d01bd1a..6cff819 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,18 @@ # Generated by Cargo # will have compiled files and executables -debug/ target/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb +# VIM swap files +*.swp -# RustRover -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +# Compiled header files +*.gch + +# VS Code configuration +.vscode/ diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..43afda9 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,841 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" +dependencies = [ + "anstyle", + "windows-sys 0.48.0", +] + +[[package]] +name = "askama" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b79091df18a97caea757e28cd2d5fda49c6cd4bd01ddffd7ff01ace0c0ad2c28" +dependencies = [ + "askama_derive", + "askama_escape", + "humansize", + "num-traits", + "percent-encoding", +] + +[[package]] +name = "askama_derive" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19fe8d6cb13c4714962c072ea496f3392015f0989b1a2847bb4b2d9effd71d83" +dependencies = [ + "askama_parser", + "basic-toml", + "mime", + "mime_guess", + "proc-macro2", + "quote", + "serde", + "syn", +] + +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + +[[package]] +name = "askama_parser" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acb1161c6b64d1c3d83108213c2a2533a342ac225aabd0bda218278c2ddb00c0" +dependencies = [ + "nom", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "basic-toml" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "823388e228f614e9558c6804262db37960ec8821856535f5c3f59913140558f8" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "clap" +version = "4.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34d21f9bf1b425d2968943631ec91202fe5e837264063503708b83013f8fc938" +dependencies = [ + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "914c8c79fb560f238ef6429439a30023c862f7a28e688c58f7203f12b29970bd" +dependencies = [ + "anstream", + "anstyle", + "bitflags 1.3.2", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + +[[package]] +name = "colored" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys 0.48.0", +] + +[[package]] +name = "console" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "diplomat" +version = "0.8.0" +source = "git+https://github.com/rust-diplomat/diplomat?rev=588f6ffe413bfca367bbb2a749a5965d40a3d5b3#588f6ffe413bfca367bbb2a749a5965d40a3d5b3" +dependencies = [ + "diplomat_core", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "diplomat-java" +version = "0.1.0" +dependencies = [ + "askama", + "clap", + "colored", + "diplomat-runtime", + "diplomat-tool", + "diplomat_core", + "heck 0.5.0", + "indenter", + "insta", + "proc-macro2", + "pulldown-cmark 0.12.1", + "quote", + "serde", + "syn", + "syn-inline-mod", + "toml 0.8.19", +] + +[[package]] +name = "diplomat-runtime" +version = "0.8.1" +source = "git+https://github.com/rust-diplomat/diplomat?rev=588f6ffe413bfca367bbb2a749a5965d40a3d5b3#588f6ffe413bfca367bbb2a749a5965d40a3d5b3" + +[[package]] +name = "diplomat-tool" +version = "0.8.0" +source = "git+https://github.com/rust-diplomat/diplomat?rev=588f6ffe413bfca367bbb2a749a5965d40a3d5b3#588f6ffe413bfca367bbb2a749a5965d40a3d5b3" +dependencies = [ + "askama", + "clap", + "colored", + "diplomat_core", + "displaydoc", + "heck 0.4.1", + "indenter", + "pulldown-cmark 0.11.3", + "quote", + "serde", + "syn", + "syn-inline-mod", + "toml 0.5.11", +] + +[[package]] +name = "diplomat_core" +version = "0.8.0" +source = "git+https://github.com/rust-diplomat/diplomat?rev=588f6ffe413bfca367bbb2a749a5965d40a3d5b3#588f6ffe413bfca367bbb2a749a5965d40a3d5b3" +dependencies = [ + "displaydoc", + "either", + "proc-macro2", + "quote", + "serde", + "smallvec", + "strck_ident", + "syn", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "feature-tests" +version = "0.0.0" +dependencies = [ + "diplomat", + "diplomat-runtime", + "log", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + +[[package]] +name = "humansize" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" +dependencies = [ + "libm", +] + +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + +[[package]] +name = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "insta" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6593a41c7a73841868772495db7dc1e8ecab43bb5c0b6da2059246c4b506ab60" +dependencies = [ + "console", + "lazy_static", + "linked-hash-map", + "similar", +] + +[[package]] +name = "is-terminal" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "jextrsact" +version = "0.1.0" +dependencies = [ + "diplomat-runtime", + "diplomat-tool", + "diplomat_core", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pulldown-cmark" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "679341d22c78c6c649893cbd6c3278dcbe9fc4faa62fea3a9296ae2b50c14625" +dependencies = [ + "bitflags 2.6.0", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "666f0f59e259aea2d72e6012290c09877a780935cc3c18b1ceded41f3890d59c" +dependencies = [ + "bitflags 2.6.0", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae" + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +dependencies = [ + "serde", +] + +[[package]] +name = "similar" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "strck" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be91090ded9d8f979d9fe921777342d37e769e0b6b7296843a7a38247240e917" + +[[package]] +name = "strck_ident" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1c3802b169b3858a44667f221c9a0b3136e6019936ea926fc97fbad8af77202" +dependencies = [ + "strck", + "unicode-ident", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn-inline-mod" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fa6dca1fdb7b2ed46dd534a326725419d4fb10f23d8c85a8b2860e5eb25d0f9" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c603356 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] +members = [ + "feature", + "cli", + "jextrsact" +] diff --git a/Makefile.toml b/Makefile.toml new file mode 100644 index 0000000..45b2432 --- /dev/null +++ b/Makefile.toml @@ -0,0 +1,59 @@ +[config] +default_to_workspace = false + +# Metatasks invoked by CI +# Tests + +[tasks.test-feature.mac] +env = {"OUT_FILE" = "dylib"} + +[tasks.test-feature.linux] +env = {"OUT_FILE" = "so", "LD_LIBRARY_PATH" = "./"} + +[tasks.test-feature] +category = "Tests" +dependencies = ["build-feature"] +script = ''' +cp target/debug/libfeature_tests.$OUT_FILE feature/java/somelib/libsomelib.$OUT_FILE +cd feature/java/somelib +mvn test +''' + +[tasks.gen-feature] +category = "Code generation" +script = ''' +mkdir feature/tmp +cargo run -p diplomat-java -- -e feature/src/lib.rs -l feature/diplomat-java-conf.toml feature/tmp/ +rm -r feature/java/somelib/src/main +mv feature/tmp/src/main feature/java/somelib/src/main +rm -r feature/tmp +''' +# Build deps + +[tasks.build-feature-release] +description = "Build feature_tests" +category = "Plumbing" +command = "cargo" +args = ["build", "--release", "-p", "feature-tests"] + +[tasks.build-feature] +description = "Build feature_tests" +category = "Plumbing" +command = "cargo" +args = ["build", "-p", "feature-tests"] + +[tasks.bench-rust-feature] +description = "Benchmark rust example" +category = "Benchmark" +script = ''' +cargo bench --package diplomat-example +''' + +[tasks.bench-feature] +description = "Benchmark kotlin example" +category = "Benchmark" +dependencies = ["gen-feature", "test-feature"] +script = ''' +cd feature/java/somelib +mvn jmh --warning-mode all +''' diff --git a/README.md b/README.md index 34d4735..3219f9f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,35 @@ # diplomat-java -Panama-based Java backend for Diplomat. +Panama-based Java backend for Diplomat. This backend depends on the [`jextract`](https://github.com/openjdk/jextract) command-line tool +to generate [JEP 454](https://openjdk.org/jeps/454) access and calling code for the generated native library. Because of this dependency +this backend won't be packaged with the [diplomat tool](https://rust-diplomat.github.io/book/). + + +# JEP 454 binding generation +In order to package this backend with the other backends there is a long term plan to implement a subset of `jextract`'s functionality. +The reasons for this include +- reducing the amount of generated code: By default `jextract` produces wrappers for standard library code as well as other methods +that should not be unnecessary for a diplomat wrapped library. +- simplifying development setup: most diplomat developers are not not familier with java and setting up a java development environment +causes unnecessary friction. Diplomat strives to enable contributors to only have to set up an environment for the language that they +need a backend for. But all diplomat contributors need to generate the code for all backends +- simplifying ci setup: `jextract` does not appear to be available via package manager, and so needs to be downloaded via URL. This is +an undesired step for diplomat's + +This [JEP 454](https://openjdk.org/jeps/454) binding generation will be developed as a library [`jextrsact`](./jextrsact/README.md) in +this repository. It will not be a replacement for jextract as it will focus only on + +# Running +You need to specify a toml config file with a domain a library name +```toml +domain = "dev.diplomattest" +lib_name = "somelib" +``` +then pass the location of the library with `-e`, with a config path specified with `-l` and then an output directory + +```sh +diplomat-java -e feature/src/lib.rs -l feature/diplomat-java-conf.toml feature/tmp/ +``` + + + + diff --git a/cli/Cargo.toml b/cli/Cargo.toml new file mode 100644 index 0000000..e6d026d --- /dev/null +++ b/cli/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "diplomat-java" +version = "0.1.0" +edition = "2021" + +[dependencies] +askama = "0.12.1" +clap = "4" +colored = "2.1.0" +diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "588f6ffe413bfca367bbb2a749a5965d40a3d5b3", package = "diplomat-runtime"} +diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat", rev = "588f6ffe413bfca367bbb2a749a5965d40a3d5b3", package = "diplomat-tool" } +diplomat_core = { git = "https://github.com/rust-diplomat/diplomat", rev = "588f6ffe413bfca367bbb2a749a5965d40a3d5b3", package = "diplomat_core" } +heck = "0.5.0" +indenter = "0.3.3" +pulldown-cmark = "0.12.1" +quote = "1.0.37" +serde = "1.0.210" +syn = { version = "2", features = [ "full", "extra-traits" ] } +syn-inline-mod = "0.6.0" +toml = "0.8.19" + +[dev-dependencies] +insta = "1.40.0" +proc-macro2 = "1.0.79" diff --git a/cli/src/backend/formatter.rs b/cli/src/backend/formatter.rs new file mode 100644 index 0000000..47eee8f --- /dev/null +++ b/cli/src/backend/formatter.rs @@ -0,0 +1,112 @@ +use std::borrow::Cow; + +use diplomat_core::hir::{ + self, FloatType, IntType, PrimitiveType, ReturnType, Slice, StructPathLike, SuccessType, + TyPosition, Type, TypeContext, +}; +use heck::ToLowerCamelCase; + +pub(crate) struct JavaFormatter<'cx> { + tcx: &'cx TypeContext, +} + +const INVALID_NAMES: &[&str] = &[ + "new", "static", "default", "private", "internal", "toString", +]; + +const DISALLOWED_CORE_TYPES: &[&str] = &["Object", "String"]; + +impl<'cx> JavaFormatter<'cx> { + pub fn new(tcx: &'cx TypeContext) -> Self { + Self { tcx } + } + + pub fn fmt_c_method_name<'a>(&self, method: &'a hir::Method) -> Cow<'a, str> { + method.abi_name.as_str().into() + } + + pub fn fmt_field_name<'a, TyP: TyPosition>( + &self, + field: &'a hir::StructField, + ) -> Cow<'a, str> { + let name = field.name.as_str().to_lower_camel_case(); + if INVALID_NAMES.contains(&&*name) || DISALLOWED_CORE_TYPES.contains(&&*name) { + format!("{name}_").into() + } else { + name.into() + } + } + pub fn fmt_method_name<'a>(&self, method: &'a hir::Method) -> Cow<'a, str> { + let name = method.name.as_str().to_lower_camel_case(); + let name = method.attrs.rename.apply(name.into()); + if INVALID_NAMES.contains(&&*name) || DISALLOWED_CORE_TYPES.contains(&&*name) { + format!("{name}_").into() + } else { + name + } + } + + pub fn fmt_return_type_java<'a>(&self, return_ty: &'a ReturnType) -> Cow<'a, str> { + match return_ty { + ReturnType::Infallible(ref success) => self.fmt_success_type_java(success), + ReturnType::Fallible(success, _) => { + todo!("Don't yet support fallible returns. Return type was: {success:?}") + } + ReturnType::Nullable(success) => { + todo!("Don't yet support Nullable returns. Return type was: {success:?}") + } + } + } + + pub fn fmt_success_type_java<'a>(&self, success_ty: &'a SuccessType) -> Cow<'a, str> { + match success_ty { + SuccessType::Write => "String".into(), + SuccessType::OutType(ref o) => self.fmt_java_type(o), + SuccessType::Unit => "void".into(), + _ => todo!(), + } + } + + pub fn fmt_java_type<'a, P: TyPosition>(&self, ty: &'a Type

) -> Cow<'a, str> { + match ty { + hir::Type::Primitive(ref p) => self.fmt_java_primitive(p), + hir::Type::Opaque(o) => self.tcx.resolve_opaque(o.tcx_id).name.to_string().into(), + hir::Type::Struct(s) => self.tcx.resolve_type(s.id()).name().to_string().into(), + hir::Type::Enum(e) => self.tcx.resolve_enum(e.tcx_id).name.to_string().into(), + hir::Type::Slice(Slice::Str(_, _)) => "String".into(), + hir::Type::Slice(Slice::Primitive(_, p)) => { + format!("{}[]", self.fmt_java_primitive(p)).into() + } + hir::Type::Slice(Slice::Strs(_)) => "String []".into(), + ty => todo!("haven't implemented, {ty:?}"), + } + } + + pub fn fmt_java_primitive<'a>(&self, ty: &'a PrimitiveType) -> Cow<'a, str> { + match ty { + PrimitiveType::Bool => "boolean", + PrimitiveType::Char => "int", + PrimitiveType::Byte => "byte", + PrimitiveType::Int(IntType::I8 | IntType::U8) => "byte", + PrimitiveType::Int(IntType::I16 | IntType::U16) => "short", + PrimitiveType::Int(IntType::I32 | IntType::U32) => "int", + PrimitiveType::Int(IntType::I64 | IntType::U64) => "long", + PrimitiveType::IntSize(_) => "long", + PrimitiveType::Int128(_) => panic!("128 not supported by java"), + PrimitiveType::Float(FloatType::F32) => "float", + PrimitiveType::Float(FloatType::F64) => "double", + } + .into() + } + + pub fn fmt_native_primitive<'a>(&self, ty: &'a PrimitiveType) -> Cow<'a, str> { + match ty { + PrimitiveType::Bool => "byte".into(), + p => self.fmt_java_primitive(p), + } + } + + pub fn fmt_param_name(&self, name: &str) -> String { + name.to_lower_camel_case() + } +} diff --git a/cli/src/backend/mod.rs b/cli/src/backend/mod.rs new file mode 100644 index 0000000..cc18388 --- /dev/null +++ b/cli/src/backend/mod.rs @@ -0,0 +1,1703 @@ +use std::borrow::Cow; +use std::ffi::OsString; +use std::fs::File; +use std::io::Write; +use std::path::Path; + +use askama::Template; +use diplomat_core::hir::borrowing_param::BorrowingParamVisitor; +use diplomat_core::hir::{ + self, BackendAttrSupport, EnumDef, EnumVariant, FloatType, IntSizeType, IntType, MaybeOwn, + MaybeStatic, Method, OpaqueDef, OpaquePath, ReturnType, Slice, SpecialMethod, StringEncoding, + StructDef, StructPathLike, SuccessType, TyPosition, TypeContext, TypeDef, +}; +use formatter::JavaFormatter; +use heck::ToUpperCamelCase; +use serde::Deserialize; + +use diplomat_tool::{ErrorStore, FileMap}; + +const TMP_C_DIR: &str = "tmp"; + +mod formatter; + +pub(crate) fn attr_support() -> BackendAttrSupport { + let mut a = BackendAttrSupport::default(); + a.namespacing = false; // TODO + a.memory_sharing = true; + a.non_exhaustive_structs = true; + a.method_overloading = false; + a.utf8_strings = false; + a.utf16_strings = true; + + a.constructors = false; // TODO + a.named_constructors = false; // TODO + a.fallible_constructors = false; + a.accessors = false; // TODO + a.stringifiers = false; + a.comparators = false; // TODO + a.iterators = false; // TODO + a.iterables = false; // TODO + a.indexing = false; + a +} + +pub(crate) fn run<'a>( + tcx: &'a TypeContext, + conf_path: Option<&Path>, + out_folder: &Path, +) -> (FileMap, ErrorStore<'a, String>) { + let conf_path = conf_path.expect("Java library needs to be called with config"); + let conf_str = std::fs::read_to_string(conf_path) + .unwrap_or_else(|err| panic!("Failed to open config file {conf_path:?}: {err}")); + let tcx_config = toml::from_str::(&conf_str) + .expect("Failed to parse config. Required fields are `domain` and `lib_name`"); + + let java_formatter = JavaFormatter::new(tcx); + let formatter = &java_formatter; + let error_store = ErrorStore::default(); + let errors = &error_store; + let ty_gen_cx = TyGenContext { + tcx, + tcx_config, + formatter, + errors, + }; + + let Config { + ref domain, + ref lib_name, + } = ty_gen_cx.tcx_config; + let domain_path = domain.replace(".", "/"); + + let errors = ErrorStore::default(); + let c_errors = ErrorStore::default(); + let files = FileMap::default(); + let c_files = FileMap::default(); + + let mut heard_files: Vec = Vec::new(); + let c_formatter = diplomat_tool::c::CFormatter::new(tcx, false); + + c_files.add_file( + "diplomat_runtime.h".into(), + diplomat_tool::c::Runtime.to_string(), + ); + heard_files.push("diplomat_runtime.h".into()); + for (id, ty) in tcx.all_types() { + if ty.attrs().disable { + continue; + } + let id = id.into(); + let decl_header_path = c_formatter.fmt_decl_header_path(id); + let impl_header_path = c_formatter.fmt_impl_header_path(id); + let c_context = diplomat_tool::c::TyGenContext { + tcx, + formatter: &c_formatter, + errors: &c_errors, + is_for_cpp: false, + id, + decl_header_path: &decl_header_path, + impl_header_path: &impl_header_path, + }; + + let decl_header = match ty { + hir::TypeDef::Enum(e) => c_context.gen_enum_def(e), + hir::TypeDef::Opaque(o) => c_context.gen_opaque_def(o), + hir::TypeDef::Struct(s) => c_context.gen_struct_def(s), + hir::TypeDef::OutStruct(s) => c_context.gen_struct_def(s), + _ => unreachable!("unknown AST/HIR variant"), + }; + + let impl_header = c_context.gen_impl(ty); + + heard_files.push(impl_header_path.clone()); + + c_files.add_file(decl_header_path, decl_header.to_string()); + + c_files.add_file(impl_header_path, impl_header.to_string()); + + let _guard = ty_gen_cx.errors.set_context_ty(ty.name().as_str().into()); + + let (file, body) = match ty { + TypeDef::Opaque(opaque) => ty_gen_cx.gen_opaque_def(opaque), + TypeDef::Enum(enum_def) => ty_gen_cx.gen_enum_def(enum_def), + TypeDef::Struct(struct_def) => ty_gen_cx.gen_struct_def(struct_def), + TypeDef::OutStruct(struct_def) => ty_gen_cx.gen_struct_def(struct_def), + unknown => { + unreachable!("Encountered unknown variant: {unknown:?} while parsing all types") + } + }; + files.add_file( + format!("src/main/java/{domain_path}/{lib_name}/{file}",), + body, + ); + } + + let c_errors = c_errors.take_all(); + if !c_errors.is_empty() { + eprintln!("Found errors when generating c code"); + for error in c_errors { + eprintln!("\t{}: {}", error.0, error.1); + } + } + + let out_files = c_files.take_files(); + + let tmp_path = out_folder.join(TMP_C_DIR); + std::fs::create_dir(&tmp_path).expect("failed to create directory "); + for (subpath, text) in out_files { + let out_path = tmp_path.join(&subpath); + let parent = out_path + .parent() + .expect("Cannot create files at top level dir /"); + std::fs::create_dir_all(parent).expect("failed to create parent"); + let mut out_file = File::create(&out_path).expect("Failed to create out path"); + out_file + .write_all(text.as_bytes()) + .expect("failed to write files"); + } + + let lib_path = tmp_path.join(format!("{lib_name}.h")); + + { + let mut lib_file = File::create(&lib_path).expect("failed to create lib file"); + for include in heard_files { + writeln!(lib_file, "#include \"{include}\"").expect("failed to write line in lib file"); + } + } + + // Here we try to build the following command + // jextract \ + // --include-dir /path/to/mylib/include \ + // --output src \ + // --target-package org.jextract.mylib \ + // --library mylib \ + // /path/to/mylib/include/mylib.h + + let package = format!("{domain}.{lib_name}.ntv"); + let mut command = std::process::Command::new("jextract"); + command + .arg("--include-dir") + .arg(&tmp_path) + .arg("--output") + .arg(out_folder.join("src/main/java")) + .arg("--target-package") + .arg(package) + .arg("--library") + .arg(AsRef::::as_ref(lib_name)) + .arg(lib_path); + + // cleanup tmp c files + let cleanup = || { + let mut command = std::process::Command::new("rm"); + command.arg("-r").arg(tmp_path).output() + }; + + let remove_extraneous_files = |pattern| { + let removal_path = out_folder.join(format!( + "src/main/java/{domain}/{lib_name}/ntv/{pattern}", + domain = domain.replace(".", "/") + )); + let mut command = std::process::Command::new("sh"); + let mut inner_command = OsString::from("rm "); + inner_command.push(removal_path.as_os_str()); + command.arg("-c").arg(&inner_command); + println!("Command is {command:?}"); + command.output() + }; + + match command.output() { + Err(err) => match err.kind() { + std::io::ErrorKind::NotFound => { + // note to guarantee a working link we link to a specific commit. But this should + // be updated when we check the validity of jextract + //cleanup().expect("Failed to clean up temporary files"); + (cleanup.clone())().expect("failed to clean up resources"); + panic!("Check that jextract is in your path and all directories exist. See https://github.com/openjdk/jextract/blob/5715737be0a1a9de24cce3ee7190881cfc8b1350/doc/GUIDE.md"); + } + err => { + (cleanup.clone())().expect("failed to clean up resources"); + panic!("unexpected error {err}") + } + }, + Ok(ok) => { + let stdout = String::from_utf8_lossy(&ok.stdout); + println!("Output from jextract:\n{stdout}"); + + let stderr = String::from_utf8_lossy(&ok.stderr); + println!("Std Err from jextract:\n{stderr}"); + } + } + + cleanup().expect("Failed to clean up temporary files"); + remove_extraneous_files("_*").expect("Failed to remove extraneous files"); + remove_extraneous_files("funopen*").expect("Failed to remove extraneous files"); + remove_extraneous_files("FILE.java").expect("Failed to remove extraneous files"); + + let lib_file = LibFile { + domain: domain.clone(), + lib_name: lib_name.clone(), + } + .render() + .expect("Failed to render Lib.java file"); + files.add_file( + format!("src/main/java/{domain_path}/{lib_name}/Lib.java"), + lib_file, + ); + (files, errors) +} + +#[derive(Template, Clone, Debug)] +#[template(path = "Lib.java.jinja", escape = "none")] +struct LibFile<'a> { + domain: Cow<'a, str>, + lib_name: Cow<'a, str>, +} + +#[derive(Clone, Debug)] +struct Param<'a> { + name: Cow<'a, str>, + ty: Cow<'a, str>, +} + +#[derive(Clone, Debug)] +pub(crate) struct ParamConversion<'a> { + converted_value: Cow<'a, str>, + conversion_def: Cow<'a, str>, +} + +#[derive(Template, Clone, Debug)] +#[template(path = "Method.java.jinja", escape = "none")] +pub(crate) struct MethodTpl<'a> { + method_name: Option>, + is_static: bool, + return_ty: Cow<'a, str>, + native_invocation: Cow<'a, str>, + params: Vec>, + param_conversions: Vec>, + return_conversion: Cow<'a, str>, + allocations: bool, + native_return_void: bool, +} + +#[derive(Template, Clone, Debug)] +#[template(path = "Struct.java.jinja", escape = "none")] +pub(crate) struct StructTypeTpl<'a> { + type_name: Cow<'a, str>, + lib_name: Cow<'a, str>, + domain: Cow<'a, str>, + edges: Vec>, + fields: Vec>, + methods: Vec>, + is_zst: bool, +} + +#[derive(Clone, Debug)] +struct FieldTpl<'a> { + name: Cow<'a, str>, + native_name: Cow<'a, str>, + to_native: Conversion<'a>, + to_java: Conversion<'a>, + ty: Cow<'a, str>, +} + +#[derive(Template, Clone, Debug)] +#[template(path = "Enum.java.jinja", escape = "none")] +pub(crate) struct EnumTypeTpl<'a> { + type_name: Cow<'a, str>, + lib_name: Cow<'a, str>, + domain: Cow<'a, str>, + variants: Vec>, + methods: Vec>, +} + +#[derive(Clone, Debug)] +struct VariantTpl<'a> { + name: Cow<'a, str>, + index: Cow<'a, str>, +} + +#[derive(Template, Clone, Debug)] +#[template(path = "Opaque.java.jinja", escape = "none")] +pub(crate) struct OpaqueTypeTpl<'a> { + type_name: Cow<'a, str>, + lib_name: Cow<'a, str>, + domain: Cow<'a, str>, + edges: Vec>, + static_methods: Vec>, + class_methods: Vec>, +} + +#[derive(Debug, Clone)] +struct LifetimeTpl<'a> { + name: Cow<'a, str>, + edges: Vec>, +} + +#[derive(Template, Clone, Debug)] +#[template(path = "StructConversion.java.jinja", escape = "none")] +pub(crate) struct StructConversionTpl<'a> { + lifetimes: Vec>, + ty: Cow<'a, str>, + name: Cow<'a, str>, + native_val: Cow<'a, str>, +} + +#[derive(Template, Clone, Debug)] +#[template(path = "OpaqueConversion.java.jinja", escape = "none")] +pub(crate) struct OpaqueConversionTpl<'a> { + name: Cow<'a, str>, + lifetimes: Vec>, + self_edges: Option>, + ty: Cow<'a, str>, + native_val: Cow<'a, str>, +} + +#[derive(Template, Clone, Debug)] +#[template(path = "OpaqueConstructor.java.jinja", escape = "none")] +pub(crate) struct OpaqueConstructorTpl<'a> { + return_ty: Cow<'a, str>, +} + +#[derive(Debug, Clone, Deserialize)] +struct Config<'cx> { + domain: Cow<'cx, str>, + lib_name: Cow<'cx, str>, +} + +struct TyGenContext<'a, 'cx> { + tcx: &'cx TypeContext, + tcx_config: Config<'cx>, + formatter: &'a JavaFormatter<'cx>, + errors: &'a ErrorStore<'cx, String>, +} + +#[derive(Debug, Clone)] +pub(crate) struct Conversion<'cx> { + conversion: Cow<'cx, str>, + converted_value: Cow<'cx, str>, +} + +mod arena { + use std::fmt::Display; + pub(crate) type Render<'cx> = Box) -> Conversion<'cx> + 'cx>; + + const UNIT: &() = &(); + use super::Conversion; + + #[must_use] + pub(crate) struct AllocationConversion<'cx, F: Fn(Arena<'cx>) -> Conversion<'cx>> { + clos: F, + _marker: &'cx (), + } + impl<'cx, F: Fn(Arena<'cx>) -> Conversion<'cx> + 'cx> AllocationConversion<'cx, F> { + pub(crate) fn dynamic(clos: F) -> AllocationConversion<'cx, Render<'cx>> { + AllocationConversion { + clos: Box::new(clos) as Render<'cx>, + _marker: UNIT, + } + } + + pub(crate) fn render(self, arena: Arena<'cx>) -> Conversion<'cx> { + (self.clos)(arena) + } + } + + pub(crate) enum Arena<'cx> { + Closed, + Auto, + #[allow(unused)] + Phantom(&'cx ()), + } + + impl<'cx> Display for Arena<'cx> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Arena::Closed => write!(f, "arena"), + Arena::Auto => write!(f, "Arena.ofAuto()"), + Arena::Phantom(_) => write!(f, "phantom"), + } + } + } +} + +pub(crate) enum AllocateConversion<'cx, F: Fn(arena::Arena<'cx>) -> Conversion<'cx>> { + NotAllocating(Conversion<'cx>), + Allocating(arena::AllocationConversion<'cx, F>), +} + +impl<'a, 'cx> TyGenContext<'a, 'cx> { + #[allow(unused)] + fn java_to_native( + &self, + name: Cow<'cx, str>, + ty: &diplomat_core::hir::Type, + ) -> AllocateConversion<'cx, arena::Render<'cx>> { + match ty { + hir::Type::Primitive(_) => { + let converted_value: Cow<'cx, str> = format!("{name}Native").into(); + AllocateConversion::NotAllocating(Conversion { + conversion: format!("var {converted_value} = {name};").into(), + converted_value, + }) + } + hir::Type::Opaque(_) => { + let converted_value: Cow<'cx, str> = format!("{name}Native").into(); + AllocateConversion::NotAllocating(Conversion { + conversion: format!("var {converted_value} = {name}.internal;").into(), + converted_value, + }) + } + hir::Type::Struct(_) => { + let clos = move |arena| -> Conversion<'cx> { + let converted_value: Cow<'cx, str> = format!("{name}Native").into(); + Conversion { + conversion: format!("var {converted_value} = {name}.toNative({arena});") + .into(), + converted_value: format!("{name}Native").into(), + } + }; + AllocateConversion::Allocating(arena::AllocationConversion::dynamic(clos)) + } + hir::Type::Enum(_) => { + let converted_value: Cow<'cx, str> = format!("{name}Native").into(); + AllocateConversion::NotAllocating(Conversion { + conversion: format!("var {converted_value} = {name}.toInt();").into(), + converted_value, + }) + } + hir::Type::Slice(Slice::Str(borrow, StringEncoding::UnvalidatedUtf16)) => { + if borrow.is_none() { + panic!("Don't support owned slices. Parameter name: {name}") + }; + let clos = move |arena| -> Conversion<'cx> { + let converted_value: Cow<'cx, str> = format!("{name}View").into(); + let conversion: Cow<'cx, str> = format!( + r#"var {name}Data = {arena}.allocateFrom({name}, StandardCharsets.UTF_16); +var {name}Len = {name}Data.byteSize() - 1; // allocated strings are null terminated +var {name}View = DiplomatString16View.allocate({arena}); +DiplomatString16View.len({name}View, {name}Len); +DiplomatString16View.data({name}View, {name}Data);"# + ) + .into(); + Conversion { + conversion, + converted_value, + } + }; + AllocateConversion::Allocating(arena::AllocationConversion::dynamic(clos)) + } + hir::Type::Slice(Slice::Str( + borrow, + StringEncoding::Utf8 | StringEncoding::UnvalidatedUtf8, + )) => { + if borrow.is_none() { + panic!("Don't support owned slices. Parameter name: {name}") + }; + let clos = move |arena| -> Conversion<'cx> { + let converted_value: Cow<'cx, str> = format!("{name}View").into(); + let conversion: Cow<'cx, str> = format!( + r#"var {name}Data= {arena}.allocateFrom({name}, StandardCharsets.UTF_8); +var {name}Len = {name}Data.byteSize() - 1; // allocated strings are null terminated +var {name}View = DiplomatStringView.allocate({arena}); +DiplomatStringView.len({name}View, {name}Len); +DiplomatStringView.data({name}View, {name}Data);"# + ) + .into(); + Conversion { + conversion, + converted_value, + } + }; + AllocateConversion::Allocating(arena::AllocationConversion::dynamic(clos)) + } + + hir::Type::Slice(Slice::Strs(StringEncoding::UnvalidatedUtf16)) => { + let clos = move |arena| { + let conversion = format!( + r#"var {name}View = SliceUtils.strs16({arena}, {name}); + var {name}Len = {name}.length;"# + ) + .into(); + let converted_value = format!("{name}View").into(); + Conversion { + conversion, + converted_value, + } + }; + + AllocateConversion::Allocating(arena::AllocationConversion::dynamic(clos)) + } + hir::Type::Slice(Slice::Strs(_)) => { + let clos = move |arena| { + let conversion = format!( + r#"var {name}View = SliceUtils.strs8({arena}, {name}); + var {name}Len = {name}.length;"# + ) + .into(); + let converted_value = format!("{name}View").into(); + Conversion { + conversion, + converted_value, + } + }; + + AllocateConversion::Allocating(arena::AllocationConversion::dynamic(clos)) + } + hir::Type::Slice(Slice::Primitive(borrow, p)) => { + if borrow.is_none() { + panic!("Don't support owned slices. Parameter name: {name}") + }; + let rust_primitive_type = match p { + hir::PrimitiveType::Byte => "U8".to_string(), + _ => p.as_str().to_upper_camel_case(), + }; + let primitive_ty = match p { + hir::PrimitiveType::Bool => "JAVA_BYTE", // BYTE is the smallest + hir::PrimitiveType::Char => "JAVA_INT", + hir::PrimitiveType::Byte => "JAVA_BYTE", + hir::PrimitiveType::Int(IntType::I8 | IntType::U8) => "JAVA_BYTE", + hir::PrimitiveType::Int(IntType::I16 | IntType::U16) => "JAVA_SHORT", + hir::PrimitiveType::Int(IntType::I32 | IntType::U32) => "JAVA_INT", + hir::PrimitiveType::Int(IntType::I64 | IntType::U64) => "JAVA_LONG", + hir::PrimitiveType::IntSize(_) => "JAVA_LONG", + hir::PrimitiveType::Int128(_) => { + panic!("java backend doesn't support 128 bit integers") + } + hir::PrimitiveType::Float(hir::FloatType::F32) => "JAVA_FLOAT", + hir::PrimitiveType::Float(hir::FloatType::F64) => "JAVA_DOUBLE", + }; + + let p = *p; + let clos = move |arena| -> Conversion<'cx> { + let converted_value: Cow<'cx, str> = format!("{name}View").into(); + + let conversion: Cow<'cx, str> = match p { + hir::PrimitiveType::Bool => format!( + r#"var {name}Len = {name}.length; +byte[] {name}ByteArray = new byte[{name}Len]; +for (int i = 0; i < {name}Len; i++) {{ + {name}ByteArray[i] = (byte) ({name}[i] ? 1 : 0); +}} +var {name}Data = {arena}.allocateFrom({primitive_ty}, {name}ByteArray); +var {name}View = Diplomat{rust_primitive_type}View.allocate({arena}); +Diplomat{rust_primitive_type}View.len({name}View, {name}Len); +Diplomat{rust_primitive_type}View.data({name}View, {name}Data); +"# + ) + .into(), + _ => format!( + r#"var {name}Len = {name}.length; +var {name}Data= {arena}.allocateFrom({primitive_ty}, {name}); +var {name}View = Diplomat{rust_primitive_type}View.allocate({arena}); +Diplomat{rust_primitive_type}View.len({name}View, {name}Len); +Diplomat{rust_primitive_type}View.data({name}View, {name}Data); +"# + ) + .into(), + }; + Conversion { + conversion, + converted_value, + } + }; + AllocateConversion::Allocating(arena::AllocationConversion::dynamic(clos)) + } + hir::Type::Callback(_) => { + todo!("We don't support callbacks yet") + } + hir::Type::DiplomatOption(_) => { + todo!("We don't support options yet") + } + param => todo!("Don't support {param:?} yet"), + } + } + + fn native_to_java( + &self, + name: Cow<'cx, str>, + native_val: Cow<'cx, str>, + ty: &diplomat_core::hir::Type, + lifetimes: Vec>, + return_self_edges: Option>, + ) -> AllocateConversion<'cx, arena::Render<'cx>> { + match ty { + hir::Type::Primitive(_) => { + let converted_value = format!("{name}Val").into(); + let conversion = format!("var {name}Val = {native_val};").into(); + AllocateConversion::NotAllocating(Conversion { + conversion, + converted_value, + }) + } + hir::Type::Opaque(o) => { + let converted_value = format!("{name}Val").into(); + let ty_name = &self.tcx.resolve_opaque(o.tcx_id).name; + let conversion = OpaqueConversionTpl { + name: "return".into(), + lifetimes, + ty: ty_name.as_str().into(), + self_edges: return_self_edges, + native_val, + } + .render() + .unwrap_or_else(|err| { + panic!( + "Failed to render return val for type {}. Cause: {err}", + ty_name + ) + }) + .into(); + + AllocateConversion::NotAllocating(Conversion { + conversion, + converted_value, + }) + } + hir::Type::Struct(s) => { + let id = s.id(); + let ty_name = self.tcx.resolve_type(id).name(); + let clos = move |_| { + let lifetimes = lifetimes.clone(); + let name = name.clone(); + let native_val = native_val.clone(); + let converted_value = format!("{name}Val").into(); + let conversion = StructConversionTpl { + lifetimes, + ty: ty_name.as_str().into(), + name, + native_val, + } + .render() + .unwrap_or_else(|err| { + panic!("Failed to render return val for type {ty_name}. Cause: {err}") + }) + .into(); + Conversion { + conversion, + converted_value, + } + }; + AllocateConversion::Allocating(arena::AllocationConversion::dynamic(clos)) + } + hir::Type::Enum(e) => { + let converted_value = format!("{name}Val").into(); + let enum_ty = self.tcx.resolve_enum(e.tcx_id).name.as_str(); + let conversion = + format!(r#"var {name}Val = {enum_ty}.fromInt({native_val});"#).into(); + AllocateConversion::NotAllocating(Conversion { + conversion, + converted_value, + }) + } + + hir::Type::Slice(Slice::Str(_, encoding)) => { + let conversion = match encoding { + StringEncoding::Utf8 | StringEncoding::UnvalidatedUtf8 => { + format!("var {name}Val = SliceUtils.readUtf8({native_val});") + } + StringEncoding::UnvalidatedUtf16 => { + format!("var {name}Val = SliceUtils.readUtf16({native_val});") + } + _ => unreachable!("Not a valid string encoding for diplomat"), + } + .into(); + let converted_value = format!("{name}Val").into(); + AllocateConversion::NotAllocating(Conversion { + conversion, + converted_value, + }) + } + hir::Type::Slice(Slice::Primitive(_, p)) => { + let lib_name = self.tcx_config.lib_name.as_ref(); + let domain = self.tcx_config.domain.as_ref(); + let primitive_ty = match p { + hir::PrimitiveType::Bool => "Bool", + hir::PrimitiveType::Char => "Char", + hir::PrimitiveType::Byte => "U8", + hir::PrimitiveType::Int(IntType::U8) => "U8", + hir::PrimitiveType::Int(IntType::I8) => "I8", + hir::PrimitiveType::Int(IntType::U16) => "U16", + hir::PrimitiveType::Int(IntType::I16) => "I16", + hir::PrimitiveType::Int(IntType::U32) => "U32", + hir::PrimitiveType::Int(IntType::I32) => "I32", + hir::PrimitiveType::Int(IntType::U64) => "U64", + hir::PrimitiveType::Int(IntType::I64) => "I64", + hir::PrimitiveType::IntSize(IntSizeType::Usize) => "Usize", + hir::PrimitiveType::IntSize(IntSizeType::Isize) => "Isize", + hir::PrimitiveType::Int128(_) => { + panic!("Java backend doesn't support Int128 types") + } + hir::PrimitiveType::Float(FloatType::F32) => "F32", + hir::PrimitiveType::Float(FloatType::F64) => "F64", + }; + + let java_primitive_ty = self.formatter.fmt_native_primitive(p); + let conversion = format!( + r#"var data = {domain}.{lib_name}.ntv.Diplomat{primitive_ty}View.data({native_val}); +var len = {domain}.{lib_name}.ntv.Diplomat{primitive_ty}View.len({native_val}); +var returnVal = SliceUtils.{java_primitive_ty}SliceToArray({native_val});"# + ).into(); + let converted_value = format!("{name}Val").into(); + AllocateConversion::NotAllocating(Conversion { + conversion, + converted_value, + }) + } + hir::Type::Slice(Slice::Strs(_)) => { + panic!("[&str] not allowed in return position") + } + hir::Type::Callback(_) => todo!("Callback's aren't supported in java"), + hir::Type::DiplomatOption(_) => todo!("Options aren't support in java"), + _ => todo!(), + } + } + + fn gen_return_conversion( + &self, + ty: &ReturnType, + lifetimes: Vec>, + return_self_edges: Option>, + allocations: &mut bool, + ) -> Cow<'cx, str> { + let Config { lib_name, .. } = &self.tcx_config; + let ret = match ty { + ReturnType::Infallible(ref ret) => ret, + ReturnType::Fallible(ref ret, _) => ret, + ReturnType::Nullable(ref ret) => ret, + }; + let o = match ret { + /* + var writeable = somelib_h.diplomat_buffer_write_create(0); + somelib_h.Opaque_get_debug_str(internal, writeable); + var buffer = DiplomatWrite.buf(writeable); + var string = buffer.getString(0, StandardCharsets.UTF_8); + somelib_h.diplomat_buffer_write_destroy(writeable); + return string; + */ + SuccessType::Write => { + let write_return: Cow<'cx, str> = format!( + r#"var string = SliceUtils. readUtf8FromWriteable(writeable); +{}_h.diplomat_buffer_write_destroy(writeable); +return string;"#, + lib_name + ) + .into(); + return write_return; + } + SuccessType::OutType(ref o) => o, + SuccessType::Unit => return Cow::<'cx, str>::default(), + _ => todo!(), + }; + // (o, lifetimes, return_self_edges) + let Conversion { + conversion, + converted_value, + } = match self.native_to_java( + "return".into(), + "nativeVal".into(), + o, + lifetimes, + return_self_edges, + ) { + AllocateConversion::NotAllocating(conv) => conv, + AllocateConversion::Allocating(needs_arena) => { + *allocations = true; + needs_arena.render(arena::Arena::Closed) + } + }; + format!( + r#" +{conversion} +return {converted_value}; + "# + ) + .into() + } + + fn gen_methods( + &self, + ty_name: &str, + methods: &'cx [Method], + ) -> (Vec>, Vec>) { + let Config { lib_name, .. } = &self.tcx_config; + let mut static_methods = Vec::new(); + let mut class_methods = Vec::new(); + methods + .iter() + .filter(|method| !method.attrs.disable) + .map(|method: &'cx Method| -> (bool, Cow<'cx, str>) { + let mut visitor: BorrowingParamVisitor<'cx> = + method.borrowing_param_visitor(self.tcx); + + let (method_name, is_valid_constructor) = match method.attrs.special_method { + // We need to reserve the default constructor for internal methods so a constructor + // must always have params + Some(SpecialMethod::Constructor) if !method.params.is_empty() => (None, true), + Some(SpecialMethod::Constructor) => { + eprintln!( + "Attempted to create constructor for {:?} type {:?}", + method.name, ty_name + ); + (Some(self.formatter.fmt_method_name(method)), false) + } + _ => (Some(self.formatter.fmt_method_name(method)), false), + }; + + let return_ty = self.formatter.fmt_return_type_java(&method.output); + + if let Some(param) = &method.param_self { + visitor.visit_param(¶m.ty.clone().into(), "this"); + } + let mut allocations = false; + let (params, param_conversions) = method + .params + .iter() + .map(|diplomat_core::hir::Param { name, ty, .. }| { + let name: Cow<'cx, str> = + self.formatter.fmt_param_name(name.as_str()).into(); + let param_lt_info = visitor.visit_param(ty, name.as_ref()); + let Conversion { + conversion, + converted_value, + } = match self.java_to_native(name.clone(), ty) { + AllocateConversion::NotAllocating(conversion) => conversion, + AllocateConversion::Allocating(conversion_clos) => { + match param_lt_info { + hir::borrowing_param::ParamBorrowInfo::NotBorrowed => { + conversion_clos.render(arena::Arena::Auto) + } + hir::borrowing_param::ParamBorrowInfo::TemporarySlice => { + conversion_clos.render(arena::Arena::Auto) + } + hir::borrowing_param::ParamBorrowInfo::BorrowedSlice => { + conversion_clos.render(arena::Arena::Auto) + } + hir::borrowing_param::ParamBorrowInfo::Struct(_) => { + allocations = true; + conversion_clos.render(arena::Arena::Closed) + } + hir::borrowing_param::ParamBorrowInfo::BorrowedOpaque => { + allocations = true; + conversion_clos.render(arena::Arena::Closed) + } + _ => todo!(), + } + } + }; + let conversion = ParamConversion { + converted_value, + conversion_def: conversion, + }; + ( + Param { + name, + ty: self.formatter.fmt_java_type(ty), + }, + conversion, + ) + }) + .unzip::<_, _, Vec<_>, Vec<_>>(); + let lt_lookup = visitor.borrow_map(); + let (lifetime_edges, return_self_edges, boxed_return) = match &method.output { + ReturnType::Fallible(SuccessType::OutType(o), _) + | ReturnType::Nullable(SuccessType::OutType(o)) + | ReturnType::Infallible(SuccessType::OutType(o)) => { + let boxed_return = match o { + hir::Type::Slice(Slice::Str(None, _) | Slice::Primitive(None, _)) => { + Some(ParamConversion { + converted_value: "boxArena".into(), + conversion_def: "var boxArena = Arena.ofConfined();".into(), + }) + } + hir::Type::Slice( + Slice::Str(Some(_), _) | Slice::Primitive(Some(_), _), + ) + | hir::Type::Struct(_) => Some(ParamConversion { + converted_value: "arena".into(), + conversion_def: "".into(), + }), + _ => None, + }; + + let self_lt = match o { + hir::Type::Opaque(ref o) => match o.owner { + MaybeOwn::Borrow(hir::Borrow { + lifetime: MaybeStatic::NonStatic(lifetime), + .. + }) => Some(lifetime), + _ => None, + }, + _ => None, + }; + let return_self_edges: Option> = self_lt + .and_then(|lifetime| lt_lookup.get(&lifetime)) + .map(|param| { + param + .incoming_edges + .iter() + .map(|lt| self.formatter.fmt_param_name(<.param_name)) + .mk_str_iter(", ") + .into() + }); + let lifetime_edges = o + .lifetimes() + .filter_map(|lt| match lt { + MaybeStatic::Static => None, + MaybeStatic::NonStatic(lt) + if Some(lt).as_ref() != self_lt.as_ref() => + { + Some(lt) + } + _ => None, + }) + .filter_map(|lt| lt_lookup.get(<).map(|info| (info, lt))) + .map(|(lifetime_info, lt)| { + let edges = lifetime_info + .incoming_edges + .iter() + .map(|edge| edge.param_name.as_str()) + .map(|param| self.formatter.fmt_param_name(param).into()) + .collect::>(); + LifetimeTpl { + name: method.lifetime_env.fmt_lifetime(lt), + edges, + } + }) + .collect::>(); + (lifetime_edges, return_self_edges, boxed_return) + } + _ => (Vec::new(), None, None), + }; + let return_conversion = if method_name.is_none() { + OpaqueConstructorTpl { + return_ty: return_ty.clone(), + } + .render() + .unwrap_or_else(|err| { + panic!( + "Failed to render method {} for type {}. Cause: {err}", + method.name, ty_name + ) + }) + .into() + } else { + self.gen_return_conversion( + &method.output, + lifetime_edges, + return_self_edges, + &mut allocations, + ) + }; + let allocations = allocations + || method + .params + .iter() + .any(|diplomat_core::hir::Param { ty, .. }| { + matches!( + ty, + diplomat_core::hir::Type::Slice( + Slice::Str(Some(_), _) + | Slice::Primitive(Some(_), _) + | Slice::Strs(_) + ) + ) + }); + let allocations = allocations + || match &method.output { + ReturnType::Infallible(SuccessType::OutType(o)) + | ReturnType::Fallible(SuccessType::OutType(o), _) + | ReturnType::Nullable(SuccessType::OutType(o)) => matches!( + o, + hir::Type::Slice(Slice::Str(Some(_), _) | Slice::Primitive(Some(_), _),) + ), + _ => false, + }; + + let mut param_conversions: Vec<_> = boxed_return + .into_iter() + .chain(method.param_self.iter().map(|_| ParamConversion { + converted_value: "internal".into(), + conversion_def: "".into(), + })) + .chain(param_conversions) + .collect(); + let write_return = matches!( + method.output, + ReturnType::Fallible(SuccessType::Write, _) + | ReturnType::Infallible(SuccessType::Write) + | ReturnType::Nullable(SuccessType::Write) + ); + if write_return { + param_conversions.push(ParamConversion { + converted_value: "writeable".into(), + conversion_def: format!( + "var writeable = {lib_name}_h.diplomat_buffer_write_create(0);" + ) + .into(), + }) + } + let native_method: Cow = + format!("{lib_name}_h.{}", self.formatter.fmt_c_method_name(method)).into(); + let native_invocation = native_method.clone(); + let native_return_void = matches!( + method.output, + ReturnType::Infallible(SuccessType::Unit | SuccessType::Write) + ); + let method_rendered = MethodTpl { + method_name, + is_static: method.param_self.is_none() && !is_valid_constructor, + return_ty, + native_invocation, + params, + param_conversions, + return_conversion, + allocations, + native_return_void, + } + .render() + .unwrap_or_else(|err| { + panic!( + "Failed to render method {} for type {}. Cause: {err}", + method.name, ty_name + ) + }); + + (method.param_self.is_some(), method_rendered.into()) + }) + .for_each(|(self_param, method_rendered)| match self_param { + true => class_methods.push(method_rendered), + false => static_methods.push(method_rendered), + }); + + (static_methods, class_methods) + } + + fn gen_enum_def(&self, e: &'cx EnumDef) -> (Cow, String) { + let Config { domain, lib_name } = &self.tcx_config; + let type_name = e.name.as_str(); + let variants = e + .variants + .iter() + .map( + |EnumVariant { + name, discriminant, .. + }| { + let name = name.as_str().into(); + let index = discriminant.to_string().into(); + VariantTpl { name, index } + }, + ) + .collect(); + let (methods, _) = self.gen_methods(e.name.as_str(), &e.methods); + ( + format!("{type_name}.java").into(), + EnumTypeTpl { + type_name: type_name.into(), + lib_name: lib_name.clone(), + domain: domain.clone(), + variants, + methods, + } + .render() + .expect("failed to render struct type"), + ) + } + fn gen_struct_def(&self, s: &'cx StructDef) -> (Cow, String) { + let Config { domain, lib_name } = &self.tcx_config; + let type_name = s.name.as_str(); + let is_zst = s.fields.is_empty(); + let fields = s + .fields + .iter() + .map(|field| { + let name = self.formatter.fmt_field_name(field); + let native_name = field.name.as_str(); + let lifetimes = match &field.ty { + hir::Type::Enum(_) => vec![], + hir::Type::Struct(struct_path) => { + let lt_env = &s.lifetimes; + struct_path + .lifetimes() + .lifetimes() + .filter_map(|lt| match lt { + MaybeStatic::Static => None, + MaybeStatic::NonStatic(lt) => Some(lt), + }) + .map(|lt| { + let edges = lt_env + .all_longer_lifetimes(<) + .map(|lt| lt_env.fmt_lifetime(lt)) + .map(|lt| format!("{lt}Edges").into()) + .collect(); + + LifetimeTpl { + name: lt_env.fmt_lifetime(lt), + edges, + } + }) + .collect() + } + hir::Type::Primitive(_) => vec![], + hir::Type::Slice(Slice::Str( + _, + StringEncoding::Utf8 | StringEncoding::UnvalidatedUtf8, + )) => vec![], + hir::Type::Slice(Slice::Str(_, StringEncoding::UnvalidatedUtf16)) => { + vec![] + } + hir::Type::Slice(_) => { + todo!("Failed to generate field: {name} for struct {}", s.name) + } + hir::Type::Opaque(OpaquePath { ref lifetimes, .. }) => { + let lt_env = &s.lifetimes; + // todo: fix + // let self_edges: Cow = match owner.lifetime() { + // Some(MaybeStatic::Static) => "List.of()".into(), + // Some(MaybeStatic::NonStatic(lt)) => { + // let stream_edges = lt_env + // .all_longer_lifetimes(lt) + // .map(|lt| lt_env.fmt_lifetime(lt)) + // .map(|lt| format!("{lt}Edges.stream()")) + // .mk_str_iter(", "); + // format!("Stream.concat({stream_edges}).toList()").into() + // } + // None => unreachable!("Struct cannot have owned opaque as field."), + // }; + lifetimes + .lifetimes() + .filter_map(|lt| match lt { + MaybeStatic::Static => None, + MaybeStatic::NonStatic(lt) => Some(lt), + }) + .map(|lt| { + let edges = lt_env + .all_longer_lifetimes(<) + .map(|lt| lt_env.fmt_lifetime(lt)) + .map(|lt| format!("{lt}Edges.stream()").into()) + .collect::>(); + LifetimeTpl { + name: lt_env.fmt_lifetime(lt), + edges, + } + }) + .collect() + } + _ => todo!(), + }; + let ty = self.formatter.fmt_java_type(&field.ty); + let to_native = match self.java_to_native(name.clone(), &field.ty) { + AllocateConversion::NotAllocating(conv) => conv, + AllocateConversion::Allocating(clos) => clos.render(arena::Arena::Closed), + }; + let to_java = match self.native_to_java( + name.clone(), + format!("{name}Native").into(), + &field.ty, + lifetimes, + None, + ) { + AllocateConversion::NotAllocating(conv) => conv, + AllocateConversion::Allocating(needs_arena) => { + needs_arena.render(arena::Arena::Closed) + } + }; + FieldTpl { + name, + native_name: native_name.into(), + ty, + to_java, + to_native, + } + }) + .collect(); + let edges = s + .lifetimes + .lifetimes() + .lifetimes() + .filter_map(|lt| match lt { + MaybeStatic::Static => None, + MaybeStatic::NonStatic(lt) => Some(lt), + }) + .map(|lt| s.lifetimes.fmt_lifetime(lt)) + .collect(); + let (methods, _) = self.gen_methods(s.name.as_str(), &s.methods); + ( + format!("{type_name}.java").into(), + StructTypeTpl { + type_name: type_name.into(), + lib_name: lib_name.clone(), + domain: domain.clone(), + is_zst, + edges, + fields, + methods, + } + .render() + .expect("failed to render struct type"), + ) + } + + fn gen_opaque_def(&self, o: &'cx OpaqueDef) -> (Cow, String) { + let Config { domain, lib_name } = &self.tcx_config; + let (static_methods, class_methods) = self.gen_methods(o.name.as_str(), &o.methods); + + let edges = o + .lifetimes + .lifetimes() + .lifetimes() + .filter_map(|lt| match lt { + MaybeStatic::Static => None, + MaybeStatic::NonStatic(lt) => Some(lt), + }) + .map(|lt| o.lifetimes.fmt_lifetime(lt)) + .collect(); + + let opaque_tpl = OpaqueTypeTpl { + type_name: o.name.to_string().into(), + lib_name: lib_name.clone(), + domain: domain.clone(), + edges, + static_methods, + class_methods, + }; + + ( + format!("{}.java", o.name).into(), + opaque_tpl.render().expect("Failed to render opaque type"), + ) + } +} + +trait JoinStrIterator: Sized { + fn mk_str_iter(self, sep: S) -> String; +} + +impl JoinStrIterator for I +where + I: IntoIterator, + T: std::fmt::Display, +{ + fn mk_str_iter(self, sep: S) -> String { + let mut iter = self.into_iter(); + match iter.next() { + Some(t) => iter.fold(format!("{t}"), |accum, next| format!("{accum}{sep}{next}")), + None => String::new(), + } + } +} + +#[cfg(test)] +mod test { + + use askama::Template; + use diplomat_core::hir::{self, BackendAttrSupport, TypeContext, TypeDef, TypeId}; + use proc_macro2::TokenStream; + use quote::quote; + + use super::{Config, ErrorStore}; + + pub fn new_tcx(tk_stream: TokenStream, support: BackendAttrSupport) -> TypeContext { + let file = syn::parse2::(tk_stream).expect("failed to parse item "); + + let mut attr_validator = hir::BasicAttributeValidator::new("kotlin_test"); + attr_validator.support = support; + + match TypeContext::from_syn(&file, attr_validator) { + Ok(context) => context, + Err(e) => { + for (_cx, err) in e { + eprintln!("Lowering error: {}", err); + } + panic!("Failed to create context") + } + } + } + + use super::{attr_support, formatter::JavaFormatter, OpaqueTypeTpl, TyGenContext}; + #[test] + fn test_opaque_render() { + let opaque_type = OpaqueTypeTpl { + type_name: "Opaque2".into(), + lib_name: "somelib".into(), + domain: "dev.diplomattest".into(), + edges: Vec::new(), + static_methods: Vec::new(), + class_methods: Vec::new(), + }; + + let rendered = opaque_type.render().expect("Failed to render opaque type"); + insta::assert_snapshot!(rendered); + } + #[test] + fn test_slice() { + let tk_stream = quote! { + #[diplomat::bridge] + mod ffi { + + #[diplomat::opaque] + struct MyString(String); + + impl MyString { + #[diplomat::attr(supports = constructors, constructor)] + pub fn new(v: &DiplomatStr) -> Box { + Box::new(Self(String::from_utf8(v.to_owned()).unwrap())) + } + + #[diplomat::attr(supports = named_constructors, named_constructor = "unsafe")] + pub fn new_unsafe(v: &str) -> Box { + Box::new(Self(v.to_string())) + } + + #[diplomat::skip_if_ast] + pub fn new_from_first<'a>(v: &[DiplomatStrSlice]) -> Box { + Box::new(Self(core::str::from_utf8(v[0]).unwrap().into())) + } + + #[diplomat::attr(supports = accessors, setter = "str")] + pub fn set_str<'a>(&'a mut self, new_str: DiplomatStrSlice<'a>) { + self.0 = String::from_utf8(new_str.to_owned()).unwrap(); + } + + #[diplomat::attr(supports = accessors, getter = "str")] + pub fn get_str(&self, write: &mut DiplomatWrite) { + let _infallible = write!(write, "{}", self.0); + } + + #[diplomat::skip_if_ast] + pub fn get_boxed_str<'a>(&'a self) -> &'a str { + self.0.as_str() + } + } + + #[diplomat::opaque] + struct Float64Vec(Vec); + + impl Float64Vec { + pub fn new(v: &[f64]) -> Box { + Box::new(Self(v.to_vec())) + } + + #[diplomat::attr(supports = accessors, getter = "asSlice")] + pub fn as_slice<'a>(&'a self) -> &'a [f64] { + &self.0 + } + } + } + }; + let support = attr_support(); + let tcx = new_tcx(tk_stream, support); + + let formatter = JavaFormatter::new(&tcx); + + let errors = ErrorStore::default(); + let tcx_gen = TyGenContext { + tcx: &tcx, + tcx_config: Config { + domain: "dev.diplomattest".into(), + lib_name: "somelib".into(), + }, + formatter: &formatter, + errors: &errors, + }; + + let mut res = String::new(); + for (_ty, def) in tcx.all_types() { + let rendered = match def { + TypeDef::Opaque(opaque) => { + let (_, rendered) = tcx_gen.gen_opaque_def(opaque); + rendered + } + _ => String::new(), + }; + + res.push_str(&rendered); + res.push_str("\n============================\n") + } + insta::assert_snapshot!(res); + } + + #[test] + fn test_enum_and_struct() { + let tk_stream = quote! { + #[diplomat::bridge] + mod ffi { + + pub struct MyStruct { + a: u8, + b: bool, + c: u8, + d: u64, + e: i32, + f: DiplomatChar, + g: MyEnum, + } + + impl MyStruct { + #[diplomat::attr(supports = constructors, constructor)] + pub fn new() -> MyStruct { + MyStruct { + a: 17, + b: true, + c: 209, + d: 1234, + e: 5991, + f: '餐' as DiplomatChar, + g: MyEnum::B, + } + } + + pub fn into_a(self) -> u8 { + self.a + } + + fn assert_value(&self) { + assert_eq!(self.a, 17); + assert!(self.b); + assert_eq!(self.c, 209); + assert_eq!(self.d, 1234); + assert_eq!(self.e, 5991); + assert_eq!(self.f, '餐' as DiplomatChar); + assert_eq!(self.g, MyEnum::B); + } + + } + + #[derive(Debug, PartialEq, Eq)] + pub enum MyEnum { + A = -2, + B = -1, + C = 0, + D = 1, + E = 2, + F = 3, + } + + impl MyEnum { + pub fn into_value(self) -> i8 { + self as i8 + } + + pub fn get_a() -> MyEnum { + MyEnum::A + } + } + } + }; + + let validator = attr_support(); + let tcx = new_tcx(tk_stream, validator); + + let formatter = JavaFormatter::new(&tcx); + + let errors = ErrorStore::default(); + let tcx_gen = TyGenContext { + tcx: &tcx, + tcx_config: Config { + domain: "dev.diplomattest".into(), + lib_name: "somelib".into(), + }, + formatter: &formatter, + errors: &errors, + }; + + let mut res = String::new(); + for (ty, def) in tcx.all_types() { + let rendered = match (ty, def) { + (_, TypeDef::Struct(struct_def)) => { + let (_, rendered) = tcx_gen.gen_struct_def(struct_def); + rendered + } + (_, TypeDef::Enum(enum_def)) => { + let (_, rendered) = tcx_gen.gen_enum_def(enum_def); + rendered + } + _ => String::new(), + }; + + res.push_str(&rendered); + res.push_str("\n============================\n") + } + insta::assert_snapshot!(res); + } + + #[test] + fn test_opaque() { + let tk_stream = quote! { + #[diplomat::bridge] + mod ffi { + + #[diplomat::opaque] + pub struct Opaque(String); + + impl Opaque { + #[diplomat::attr(supports = constructors, constructor)] + pub fn new() -> Box { + Box::new(Opaque("".into())) + } + + pub fn from_str(input: &str) -> Box { + Box::new(Self(input.into())) + } + + + pub fn returns_usize() -> usize { + 412 + } + + pub fn internal_len(&self) -> usize { + self.0.len() + } + + pub fn get_debug_str(&self, write: &mut DiplomatWrite) { + let _infallible = write!(write, "{:?}", &self.0); + } + } + + } + }; + + let validator = attr_support(); + let tcx = new_tcx(tk_stream, validator); + + let formatter = JavaFormatter::new(&tcx); + + let errors = ErrorStore::default(); + let tcx_gen = TyGenContext { + tcx: &tcx, + tcx_config: Config { + domain: "dev.diplomattest".into(), + lib_name: "somelib".into(), + }, + formatter: &formatter, + errors: &errors, + }; + + let mut res = String::new(); + for (ty, def) in tcx.all_types() { + let rendered = match (ty, def) { + (_, TypeDef::Opaque(opaque)) => { + let (_, rendered) = tcx_gen.gen_opaque_def(opaque); + rendered + } + (_, TypeDef::Struct(struct_def)) => { + let (_, rendered) = tcx_gen.gen_struct_def(struct_def); + rendered + } + + (_, TypeDef::Enum(enum_def)) => { + let (_, rendered) = tcx_gen.gen_enum_def(enum_def); + rendered + } + _ => String::new(), + }; + + res.push_str(&rendered); + res.push_str("\n============================\n") + } + insta::assert_snapshot!(res); + } + + #[test] + fn test_lifetimes() { + let tk_stream = quote! { + #[diplomat::bridge] + pub mod ffi { + use diplomat_runtime::DiplomatStr16; + + #[diplomat::opaque] + pub struct Foo<'a>(&'a DiplomatStr); + + #[diplomat::opaque] + #[diplomat::transparent_convert] + pub struct Bar<'b, 'a: 'b>(&'b Foo<'a>); + + pub struct BorrowedFields<'a> { + a: DiplomatStr16Slice<'a>, + b: DiplomatStrSlice<'a>, + c: DiplomatStrSlice<'a>, + } + + pub struct BorrowedFieldsWithBounds<'a, 'b: 'a, 'c: 'b> { + field_a: DiplomatStr16Slice<'a>, + field_b: DiplomatStrSlice<'b>, + field_c: DiplomatStrSlice<'c>, + } + + pub struct BorrowedFieldsReturning<'a> { + bytes: DiplomatStrSlice<'a>, + } + + impl<'a> Foo<'a> { + pub fn new(x: &'a DiplomatStr) -> Box { + Box::new(Foo(x)) + } + + pub fn get_bar<'b>(&'b self) -> Box> { + Box::new(Bar(self)) + } + + pub fn as_returning(&self) -> BorrowedFieldsReturning<'a> { + BorrowedFieldsReturning { bytes: self.0 } + } + + pub fn extract_from_fields(fields: BorrowedFields<'a>) -> Box { + Box::new(Foo(fields.b)) + } + + /// Test that the extraction logic correctly pins the right fields + pub fn extract_from_bounds<'x, 'y: 'x + 'a, 'z: 'x + 'y>( + bounds: BorrowedFieldsWithBounds<'x, 'y, 'z>, + another_string: &'a DiplomatStr, + ) -> Box { + if bounds.field_b.is_empty() { + Box::new(Self(another_string)) + } else { + Box::new(Self(bounds.field_b)) + } + } + } + } + }; + + let validator = attr_support(); + let tcx = new_tcx(tk_stream, validator); + + let formatter = JavaFormatter::new(&tcx); + + let errors = ErrorStore::default(); + let tcx_gen = TyGenContext { + tcx: &tcx, + tcx_config: Config { + domain: "dev.diplomattest".into(), + lib_name: "somelib".into(), + }, + formatter: &formatter, + errors: &errors, + }; + + let mut res = String::new(); + for (ty, def) in tcx.all_types() { + let rendered = match (ty, def) { + (_, TypeDef::Opaque(opaque)) => { + let (_, rendered) = tcx_gen.gen_opaque_def(opaque); + rendered + } + (_, TypeDef::Struct(struct_def)) => { + let (_, rendered) = tcx_gen.gen_struct_def(struct_def); + rendered + } + + (TypeId::Enum(_), TypeDef::Enum(enum_def)) => { + let (_, rendered) = tcx_gen.gen_enum_def(enum_def); + rendered + } + _ => String::new(), + }; + + res.push_str(&rendered); + res.push_str("\n============================\n") + } + insta::assert_snapshot!(res); + } +} diff --git a/cli/src/backend/snapshots/diplomat_java__backend__test__enum_and_struct.snap b/cli/src/backend/snapshots/diplomat_java__backend__test__enum_and_struct.snap new file mode 100644 index 0000000..9797949 --- /dev/null +++ b/cli/src/backend/snapshots/diplomat_java__backend__test__enum_and_struct.snap @@ -0,0 +1,185 @@ +--- +source: cli/src/backend/mod.rs +expression: res +--- +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class MyStruct { + byte a; + boolean b; + byte c; + long d; + int e; + int f; + MyEnum g; + + + List selfEdges = List.of(); + + + private MyStruct() { + } + + MyStruct(MemorySegment structSegment) { + this.selfEdges = selfEdges; + + + var aNative = dev.diplomattest.somelib.ntv.MyStruct.a(structSegment); + var aVal = aNative; + this.a = aVal; + var bNative = dev.diplomattest.somelib.ntv.MyStruct.b(structSegment); + var bVal = bNative; + this.b = bVal; + var cNative = dev.diplomattest.somelib.ntv.MyStruct.c(structSegment); + var cVal = cNative; + this.c = cVal; + var dNative = dev.diplomattest.somelib.ntv.MyStruct.d(structSegment); + var dVal = dNative; + this.d = dVal; + var eNative = dev.diplomattest.somelib.ntv.MyStruct.e(structSegment); + var eVal = eNative; + this.e = eVal; + var fNative = dev.diplomattest.somelib.ntv.MyStruct.f(structSegment); + var fVal = fNative; + this.f = fVal; + var gNative = dev.diplomattest.somelib.ntv.MyStruct.g(structSegment); + var gVal = MyEnum.fromInt(gNative); + this.g = gVal; + + + } + + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = dev.diplomattest.somelib.ntv.MyStruct.allocate(arena); + + var aNative = a; + dev.diplomattest.somelib.ntv.MyStruct.a(returnVal, aNative); + var bNative = b; + dev.diplomattest.somelib.ntv.MyStruct.b(returnVal, bNative); + var cNative = c; + dev.diplomattest.somelib.ntv.MyStruct.c(returnVal, cNative); + var dNative = d; + dev.diplomattest.somelib.ntv.MyStruct.d(returnVal, dNative); + var eNative = e; + dev.diplomattest.somelib.ntv.MyStruct.e(returnVal, eNative); + var fNative = f; + dev.diplomattest.somelib.ntv.MyStruct.f(returnVal, fNative); + var gNative = g.toInt(); + dev.diplomattest.somelib.ntv.MyStruct.g(returnVal, gNative); + + + return returnVal; + + } + + public static MyStruct new_() { + + try (var arena = Arena.ofConfined()) { + + var nativeVal = somelib_h.MyStruct_new(arena); + + var returnVal = new MyStruct(nativeVal); + return returnVal; + + } + } + +} + + +============================ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.somelib_h; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; + +public enum MyEnum { + A, + B, + C, + D, + E, + F, + ; + + static MyEnum fromInt(int i) { + switch (i) { + case -2 -> { + return MyEnum.A; + } + case -1 -> { + return MyEnum.B; + } + case 0 -> { + return MyEnum.C; + } + case 1 -> { + return MyEnum.D; + } + case 2 -> { + return MyEnum.E; + } + case 3 -> { + return MyEnum.F; + } + + } + throw new RuntimeException("Unexpected int for MyEnum:" + i); + } + + int toInt() { + switch (this) { + case A -> { + return -2; + } + case B -> { + return -1; + } + case C -> { + return 0; + } + case D -> { + return 1; + } + case E -> { + return 2; + } + case F -> { + return 3; + } + + } + throw new RuntimeException("Unexpected variant for MyEnum:" + this); + } + + + public static MyEnum getA() { + + var nativeVal = somelib_h.MyEnum_get_a(); + + var returnVal = MyEnum.fromInt(nativeVal); + return returnVal; + + } + +} + +============================ diff --git a/cli/src/backend/snapshots/diplomat_java__backend__test__lifetimes.snap b/cli/src/backend/snapshots/diplomat_java__backend__test__lifetimes.snap new file mode 100644 index 0000000..b64d942 --- /dev/null +++ b/cli/src/backend/snapshots/diplomat_java__backend__test__lifetimes.snap @@ -0,0 +1,400 @@ +--- +source: cli/src/backend/mod.rs +expression: res +--- +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class BorrowedFields { + String a; + String b; + String c; + + + List selfEdges = List.of(); + List aEdges = List.of(); + + + private BorrowedFields() { + } + + BorrowedFields(MemorySegment structSegment, List aEdges) { + this.selfEdges = selfEdges; + this.aEdges = aEdges; + + + var aNative = dev.diplomattest.somelib.ntv.BorrowedFields.a(structSegment); + var aVal = SliceUtils.readUtf16(aNative); + this.a = aVal; + var bNative = dev.diplomattest.somelib.ntv.BorrowedFields.b(structSegment); + var bVal = SliceUtils.readUtf8(bNative); + this.b = bVal; + var cNative = dev.diplomattest.somelib.ntv.BorrowedFields.c(structSegment); + var cVal = SliceUtils.readUtf8(cNative); + this.c = cVal; + + + } + + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = dev.diplomattest.somelib.ntv.BorrowedFields.allocate(arena); + + var aData = arena.allocateFrom(a, StandardCharsets.UTF_16); + var aLen = aData.byteSize() - 1; // allocated strings are null terminated + var aView = DiplomatString16View.allocate(arena); + DiplomatString16View.len(aView, aLen); + DiplomatString16View.data(aView, aData); + dev.diplomattest.somelib.ntv.BorrowedFields.a(returnVal, aView); + var bData= arena.allocateFrom(b, StandardCharsets.UTF_8); + var bLen = bData.byteSize() - 1; // allocated strings are null terminated + var bView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(bView, bLen); + DiplomatStringView.data(bView, bData); + dev.diplomattest.somelib.ntv.BorrowedFields.b(returnVal, bView); + var cData= arena.allocateFrom(c, StandardCharsets.UTF_8); + var cLen = cData.byteSize() - 1; // allocated strings are null terminated + var cView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(cView, cLen); + DiplomatStringView.data(cView, cData); + dev.diplomattest.somelib.ntv.BorrowedFields.c(returnVal, cView); + + + return returnVal; + + } + +} + + +============================ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class BorrowedFieldsReturning { + String bytes; + + + List selfEdges = List.of(); + List aEdges = List.of(); + + + private BorrowedFieldsReturning() { + } + + BorrowedFieldsReturning(MemorySegment structSegment, List aEdges) { + this.selfEdges = selfEdges; + this.aEdges = aEdges; + + + var bytesNative = dev.diplomattest.somelib.ntv.BorrowedFieldsReturning.bytes(structSegment); + var bytesVal = SliceUtils.readUtf8(bytesNative); + this.bytes = bytesVal; + + + } + + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = dev.diplomattest.somelib.ntv.BorrowedFieldsReturning.allocate(arena); + + var bytesData= arena.allocateFrom(bytes, StandardCharsets.UTF_8); + var bytesLen = bytesData.byteSize() - 1; // allocated strings are null terminated + var bytesView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(bytesView, bytesLen); + DiplomatStringView.data(bytesView, bytesData); + dev.diplomattest.somelib.ntv.BorrowedFieldsReturning.bytes(returnVal, bytesView); + + + return returnVal; + + } + +} + + +============================ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class BorrowedFieldsWithBounds { + String fieldA; + String fieldB; + String fieldC; + + + List selfEdges = List.of(); + List aEdges = List.of(); + List bEdges = List.of(); + List cEdges = List.of(); + + + private BorrowedFieldsWithBounds() { + } + + BorrowedFieldsWithBounds(MemorySegment structSegment, List aEdges, List bEdges, List cEdges) { + this.selfEdges = selfEdges; + this.aEdges = aEdges; + this.bEdges = bEdges; + this.cEdges = cEdges; + + + var fieldANative = dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.field_a(structSegment); + var fieldAVal = SliceUtils.readUtf16(fieldANative); + this.fieldA = fieldAVal; + var fieldBNative = dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.field_b(structSegment); + var fieldBVal = SliceUtils.readUtf8(fieldBNative); + this.fieldB = fieldBVal; + var fieldCNative = dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.field_c(structSegment); + var fieldCVal = SliceUtils.readUtf8(fieldCNative); + this.fieldC = fieldCVal; + + + } + + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.allocate(arena); + + var fieldAData = arena.allocateFrom(fieldA, StandardCharsets.UTF_16); + var fieldALen = fieldAData.byteSize() - 1; // allocated strings are null terminated + var fieldAView = DiplomatString16View.allocate(arena); + DiplomatString16View.len(fieldAView, fieldALen); + DiplomatString16View.data(fieldAView, fieldAData); + dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.field_a(returnVal, fieldAView); + var fieldBData= arena.allocateFrom(fieldB, StandardCharsets.UTF_8); + var fieldBLen = fieldBData.byteSize() - 1; // allocated strings are null terminated + var fieldBView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(fieldBView, fieldBLen); + DiplomatStringView.data(fieldBView, fieldBData); + dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.field_b(returnVal, fieldBView); + var fieldCData= arena.allocateFrom(fieldC, StandardCharsets.UTF_8); + var fieldCLen = fieldCData.byteSize() - 1; // allocated strings are null terminated + var fieldCView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(fieldCView, fieldCLen); + DiplomatStringView.data(fieldCView, fieldCData); + dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.field_c(returnVal, fieldCView); + + + return returnVal; + + } + +} + + +============================ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class Bar { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + List bEdges = List.of(); + List aEdges = List.of(); + + + static class BarCleaner implements Runnable { + + MemorySegment segment; + BarCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.Bar_destroy(this.segment); + } + } + + Bar() {} + Bar(MemorySegment handle, List selfEdges, List bEdges, List aEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + this.bEdges = bEdges; + this.aEdges = aEdges; + + + } + + +} +============================ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class Foo { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + List aEdges = List.of(); + + + static class FooCleaner implements Runnable { + + MemorySegment segment; + FooCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.Foo_destroy(this.segment); + } + } + + Foo() {} + Foo(MemorySegment handle, List selfEdges, List aEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + this.aEdges = aEdges; + + + } + + public static Foo new_(String x) { + + try (var arena = Arena.ofConfined()) { + var xData= Arena.ofAuto().allocateFrom(x, StandardCharsets.UTF_8); + var xLen = xData.byteSize() - 1; // allocated strings are null terminated + var xView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(xView, xLen); + DiplomatStringView.data(xView, xData); + var nativeVal = somelib_h.Foo_new(xView); + + List selfEdges = List.of(); + + + + List aEdges = List.of(x); + var returnVal = new Foo(nativeVal, selfEdges, aEdges); + return returnVal; + + } + } + + public static Foo extractFromFields(BorrowedFields fields) { + + try (var arena = Arena.ofConfined()) { + var fieldsNative = fields.toNative(arena); + var nativeVal = somelib_h.Foo_extract_from_fields(fieldsNative); + + List selfEdges = List.of(); + + + + List aEdges = List.of(fields); + var returnVal = new Foo(nativeVal, selfEdges, aEdges); + return returnVal; + + } + } + + public static Foo extractFromBounds(BorrowedFieldsWithBounds bounds,String anotherString) { + + try (var arena = Arena.ofConfined()) { + var boundsNative = bounds.toNative(arena); + var anotherStringData= Arena.ofAuto().allocateFrom(anotherString, StandardCharsets.UTF_8); + var anotherStringLen = anotherStringData.byteSize() - 1; // allocated strings are null terminated + var anotherStringView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(anotherStringView, anotherStringLen); + DiplomatStringView.data(anotherStringView, anotherStringData); + var nativeVal = somelib_h.Foo_extract_from_bounds(boundsNative, anotherStringView); + + List selfEdges = List.of(); + + + + List aEdges = List.of(bounds, bounds, anotherString); + var returnVal = new Foo(nativeVal, selfEdges, aEdges); + return returnVal; + + } + } + + + public Bar getBar() { + + + var nativeVal = somelib_h.Foo_get_bar(internal); + + List selfEdges = List.of(); + + + + List bEdges = List.of(this); + List aEdges = List.of(this); + var returnVal = new Bar(nativeVal, selfEdges, bEdges, aEdges); + return returnVal; + + } + + public BorrowedFieldsReturning asReturning() { + + try (var arena = Arena.ofConfined()) { + + + var nativeVal = somelib_h.Foo_as_returning(arena, internal); + + var returnVal = new BorrowedFieldsReturning(nativeVal, List.of()); + return returnVal; + + } + } + +} +============================ diff --git a/cli/src/backend/snapshots/diplomat_java__backend__test__opaque.snap b/cli/src/backend/snapshots/diplomat_java__backend__test__opaque.snap new file mode 100644 index 0000000..8479262 --- /dev/null +++ b/cli/src/backend/snapshots/diplomat_java__backend__test__opaque.snap @@ -0,0 +1,112 @@ +--- +source: cli/src/backend/mod.rs +expression: res +--- +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class Opaque { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + + + static class OpaqueCleaner implements Runnable { + + MemorySegment segment; + OpaqueCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.Opaque_destroy(this.segment); + } + } + + Opaque() {} + Opaque(MemorySegment handle, List selfEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + + + } + + public static Opaque new_() { + + var nativeVal = somelib_h.Opaque_new(); + + List selfEdges = List.of(); + + + + var returnVal = new Opaque(nativeVal, selfEdges); + return returnVal; + + } + + public static Opaque fromStr(String input) { + + try (var arena = Arena.ofConfined()) { + var inputData= Arena.ofAuto().allocateFrom(input, StandardCharsets.UTF_8); + var inputLen = inputData.byteSize() - 1; // allocated strings are null terminated + var inputView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(inputView, inputLen); + DiplomatStringView.data(inputView, inputData); + var nativeVal = somelib_h.Opaque_from_str(inputView); + + List selfEdges = List.of(); + + + + var returnVal = new Opaque(nativeVal, selfEdges); + return returnVal; + + } + } + + public static long returnsUsize() { + + var nativeVal = somelib_h.Opaque_returns_usize(); + + var returnVal = nativeVal; + return returnVal; + + } + + + public long internalLen() { + + + var nativeVal = somelib_h.Opaque_internal_len(internal); + + var returnVal = nativeVal; + return returnVal; + + } + + public String getDebugStr() { + + + var writeable = somelib_h.diplomat_buffer_write_create(0); + somelib_h.Opaque_get_debug_str(internal, writeable); + var string = SliceUtils. readUtf8FromWriteable(writeable); + somelib_h.diplomat_buffer_write_destroy(writeable); + return string; + } + +} +============================ diff --git a/cli/src/backend/snapshots/diplomat_java__backend__test__opaque_render.snap b/cli/src/backend/snapshots/diplomat_java__backend__test__opaque_render.snap new file mode 100644 index 0000000..8e511e2 --- /dev/null +++ b/cli/src/backend/snapshots/diplomat_java__backend__test__opaque_render.snap @@ -0,0 +1,49 @@ +--- +source: cli/src/backend/mod.rs +expression: rendered +--- +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class Opaque2 { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + + + static class Opaque2Cleaner implements Runnable { + + MemorySegment segment; + Opaque2Cleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.Opaque2_destroy(this.segment); + } + } + + Opaque2() {} + Opaque2(MemorySegment handle, List selfEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + + + } + + +} diff --git a/cli/src/backend/snapshots/diplomat_java__backend__test__slice.snap b/cli/src/backend/snapshots/diplomat_java__backend__test__slice.snap new file mode 100644 index 0000000..182977f --- /dev/null +++ b/cli/src/backend/snapshots/diplomat_java__backend__test__slice.snap @@ -0,0 +1,226 @@ +--- +source: cli/src/backend/mod.rs +expression: res +--- +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class Float64Vec { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + + + static class Float64VecCleaner implements Runnable { + + MemorySegment segment; + Float64VecCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.Float64Vec_destroy(this.segment); + } + } + + Float64Vec() {} + Float64Vec(MemorySegment handle, List selfEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + + + } + + public static Float64Vec new_(double[] v) { + + try (var arena = Arena.ofConfined()) { + var vLen = v.length; + var vData= Arena.ofAuto().allocateFrom(JAVA_DOUBLE, v); + var vView = DiplomatF64View.allocate(Arena.ofAuto()); + DiplomatF64View.len(vView, vLen); + DiplomatF64View.data(vView, vData); + + var nativeVal = somelib_h.Float64Vec_new(vView); + + List selfEdges = List.of(); + + + + var returnVal = new Float64Vec(nativeVal, selfEdges); + return returnVal; + + } + } + + + public double[] asSlice() { + + try (var arena = Arena.ofConfined()) { + + + var nativeVal = somelib_h.Float64Vec_as_slice(arena, internal); + + var data = dev.diplomattest.somelib.ntv.DiplomatF64View.data(nativeVal); + var len = dev.diplomattest.somelib.ntv.DiplomatF64View.len(nativeVal); + var returnVal = SliceUtils.doubleSliceToArray(nativeVal); + return returnVal; + + } + } + +} +============================ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class MyString { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + + + static class MyStringCleaner implements Runnable { + + MemorySegment segment; + MyStringCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.MyString_destroy(this.segment); + } + } + + MyString() {} + MyString(MemorySegment handle, List selfEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + + + } + + public static MyString new_(String v) { + + try (var arena = Arena.ofConfined()) { + var vData= Arena.ofAuto().allocateFrom(v, StandardCharsets.UTF_8); + var vLen = vData.byteSize() - 1; // allocated strings are null terminated + var vView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(vView, vLen); + DiplomatStringView.data(vView, vData); + var nativeVal = somelib_h.MyString_new(vView); + + List selfEdges = List.of(); + + + + var returnVal = new MyString(nativeVal, selfEdges); + return returnVal; + + } + } + + public static MyString newUnsafe(String v) { + + try (var arena = Arena.ofConfined()) { + var vData= Arena.ofAuto().allocateFrom(v, StandardCharsets.UTF_8); + var vLen = vData.byteSize() - 1; // allocated strings are null terminated + var vView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(vView, vLen); + DiplomatStringView.data(vView, vData); + var nativeVal = somelib_h.MyString_new_unsafe(vView); + + List selfEdges = List.of(); + + + + var returnVal = new MyString(nativeVal, selfEdges); + return returnVal; + + } + } + + public static MyString newFromFirst(String [] v) { + + try (var arena = Arena.ofConfined()) { + var vView = SliceUtils.strs8(Arena.ofAuto(), v); + var vLen = v.length; + var nativeVal = somelib_h.MyString_new_from_first(vView); + + List selfEdges = List.of(); + + + + var returnVal = new MyString(nativeVal, selfEdges); + return returnVal; + + } + } + + + public void setStr(String newStr) { + + try (var arena = Arena.ofConfined()) { + + var newStrData= Arena.ofAuto().allocateFrom(newStr, StandardCharsets.UTF_8); + var newStrLen = newStrData.byteSize() - 1; // allocated strings are null terminated + var newStrView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(newStrView, newStrLen); + DiplomatStringView.data(newStrView, newStrData); + somelib_h.MyString_set_str(internal, newStrView); + + } + } + + public String getStr() { + + + var writeable = somelib_h.diplomat_buffer_write_create(0); + somelib_h.MyString_get_str(internal, writeable); + var string = SliceUtils. readUtf8FromWriteable(writeable); + somelib_h.diplomat_buffer_write_destroy(writeable); + return string; + } + + public String getBoxedStr() { + + try (var arena = Arena.ofConfined()) { + + + var nativeVal = somelib_h.MyString_get_boxed_str(arena, internal); + + var returnVal = SliceUtils.readUtf8(nativeVal); + return returnVal; + + } + } + +} +============================ diff --git a/cli/src/main.rs b/cli/src/main.rs new file mode 100644 index 0000000..16a88fe --- /dev/null +++ b/cli/src/main.rs @@ -0,0 +1,103 @@ +use clap::Parser; +use colored::Colorize; +use diplomat_core::hir; +use std::path::{Path, PathBuf}; +mod backend; + +pub fn gen( + entry: &Path, + out_folder: &Path, + library_config: Option<&Path>, + silent: bool, +) -> std::io::Result<()> { + if !entry.exists() { + eprintln!( + "{}{}\n{}", + "Error: ".red().bold(), + if entry.file_name().map(|e| e == "lib.rs").unwrap_or_default() { + "Could not find the lib.rs file to process." + } else { + "The entry file does not exist." + }, + format!("{}", std::env::current_dir().unwrap().join(entry).display()).red() + ); + std::process::exit(1); + } + + // The HIR backends used to be named "c2", "js2", etc + let mut attr_validator = hir::BasicAttributeValidator::new("java"); + attr_validator.support = backend::attr_support(); + + let module = syn_inline_mod::parse_and_inline_modules(entry); + let tcx = hir::TypeContext::from_syn(&module, attr_validator).unwrap_or_else(|e| { + for (ctx, err) in e { + eprintln!("Lowering error in {ctx}: {err}"); + } + std::process::exit(1); + }); + + let (files, errors) = backend::run(&tcx, library_config, out_folder); + + let errors = errors.take_all(); + if !errors.is_empty() { + eprintln!("Found errors whilst:"); + for error in errors { + eprintln!("\t{}: {}", error.0, error.1); + } + eprintln!("Not generating files due to errors"); + // Eventually this should use eyre or something + std::process::exit(1); + } + + if !silent { + println!("{}", "Generating bindings:".green().bold()); + } + for (subpath, text) in files.take_files() { + let out_path = out_folder.join(subpath); + if !silent { + println!("{}", format!(" {}", out_path.display()).dimmed()); + } + std::fs::create_dir_all(out_path.parent().unwrap()).unwrap(); + std::fs::write(&out_path, text)?; + } + + Ok(()) +} + +/// diplomat-tool CLI options, as parsed by [clap-derive]. +#[derive(Debug, Parser)] +#[clap( + name = "diplomat-tool", + about = "Generate bindings to a target language" +)] +struct Opt { + /// The folder that stores the bindings. + #[clap(value_parser)] + out_folder: PathBuf, + + #[clap(short = 'u', long)] + docs_base_urls: Vec, + + /// The path to the lib.rs file. + #[clap(short, long, value_parser, default_value = "src/lib.rs")] + entry: PathBuf, + + /// The path to an optional config file to override code generation defaults. + /// This is currently used by kotlin and demo_gen. + #[clap(short, long, value_parser)] + library_config: Option, + + #[clap(short = 's', long)] + silent: bool, +} + +fn main() -> std::io::Result<()> { + let opt = Opt::parse(); + + gen( + &opt.entry, + &opt.out_folder, + opt.library_config.as_deref(), + opt.silent, + ) +} diff --git a/cli/templates/Enum.java.jinja b/cli/templates/Enum.java.jinja new file mode 100644 index 0000000..d8fe2d4 --- /dev/null +++ b/cli/templates/Enum.java.jinja @@ -0,0 +1,44 @@ +package {{domain}}.{{lib_name}}; + +import {{domain}}.{{lib_name}}.ntv.{{lib_name}}_h; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; + +public enum {{type_name}} { + {% for variant in variants -%} + {{variant.name}}, + {% endfor %}; + + static {{type_name}} fromInt(int i) { + switch (i) { + {% for variant in variants -%} + case {{variant.index}} -> { + return {{type_name}}.{{variant.name}}; + } + {% endfor %} + } + throw new RuntimeException("Unexpected int for {{type_name}}:" + i); + } + + int toInt() { + switch (this) { + {% for variant in variants -%} + case {{variant.name}} -> { + return {{variant.index}}; + } + {% endfor %} + } + throw new RuntimeException("Unexpected variant for {{type_name}}:" + this); + } + + {% for method in methods %} + {{method|indent(4)}} + {% endfor %} +} + diff --git a/cli/templates/Lib.java.jinja b/cli/templates/Lib.java.jinja new file mode 100644 index 0000000..a62658f --- /dev/null +++ b/cli/templates/Lib.java.jinja @@ -0,0 +1,205 @@ +package {{domain}}.{{lib_name}}; + +import {{domain}}.{{lib_name}}.ntv.*; + +import java.lang.foreign.*; +import java.lang.ref.Cleaner; +import java.nio.charset.StandardCharsets; +import java.util.function.Consumer; +import java.util.Arrays; + +import static java.lang.foreign.ValueLayout.*; + +public class Lib { + static final Cleaner cleaner = Cleaner.create(); +} + +class SliceUtils { + + + static boolean[] booleanSliceToArray(MemorySegment segment) { + var data = DiplomatU8View.data(segment); + var len = DiplomatU8View.len(segment); + var slice = data.asSlice(0, len * JAVA_BYTE.byteSize()); + var byteArray = slice.toArray(JAVA_BYTE); + var returnArray = new boolean[(int) len]; + for (var i=0; i < len; i++ ) { + returnArray[i] = (byteArray[i] == 1); + } + return returnArray; + } + + static byte[] byteSliceToArray(MemorySegment segment) { + var data = DiplomatU8View.data(segment); + var len = DiplomatU8View.len(segment); + var slice = data.asSlice(0, len * JAVA_BYTE.byteSize()); + return slice.toArray(JAVA_BYTE); + } + + static short[] shortSliceToArray(MemorySegment segment) { + var data = DiplomatU16View.data(segment); + var len = DiplomatU16View.len(segment); + var slice = data.asSlice(0, len * JAVA_SHORT.byteSize()); + return slice.toArray(JAVA_SHORT); + } + static int[] intSliceToArray(MemorySegment segment) { + var data = DiplomatU32View.data(segment); + var len = DiplomatU32View.len(segment); + var slice = data.asSlice(0, len * JAVA_INT.byteSize()); + return slice.toArray(JAVA_INT); + } + static long[] longSliceToArray(MemorySegment segment) { + var data = DiplomatU64View.data(segment); + var len = DiplomatU64View.len(segment); + var slice = data.asSlice(0, len * JAVA_LONG.byteSize()); + return slice.toArray(JAVA_LONG); + } + static float[] floatSliceToArray(MemorySegment segment) { + var data = DiplomatF32View.data(segment); + var len = DiplomatF32View.len(segment); + var slice = data.asSlice(0, len * JAVA_FLOAT.byteSize()); + return slice.toArray(JAVA_FLOAT); + } + + static double[] doubleSliceToArray(MemorySegment segment) { + var data = DiplomatF64View.data(segment); + var len = DiplomatF64View.len(segment); + var slice = data.asSlice(0, len * JAVA_DOUBLE.byteSize()); + return slice.toArray(JAVA_DOUBLE); + } + + static MemorySegment byteArrayToSlice(SegmentAllocator arena, byte[] array) { + var len = array.length; + var memSeg = arena.allocate(JAVA_BYTE, len); + for (var i = 0; i < len; i++) { + memSeg.setAtIndex(JAVA_BYTE, i, array[i]); + } + return memSeg; + } + + static MemorySegment shortArrayToSlice(SegmentAllocator arena, short[] array) { + var len = array.length; + var memSeg = arena.allocate(JAVA_SHORT, len); + for (var i = 0; i < len; i++) { + memSeg.setAtIndex(JAVA_SHORT, i, array[i]); + } + return memSeg; + } + + static MemorySegment intArrayToSlice(SegmentAllocator arena, int[] array) { + var len = array.length; + var memSeg = arena.allocate(JAVA_INT, len); + for (var i = 0; i < len; i++) { + memSeg.setAtIndex(JAVA_INT, i, array[i]); + } + return memSeg; + } + static MemorySegment longArrayToSlice(SegmentAllocator arena, long[] array) { + var len = array.length; + var memSeg = arena.allocate(JAVA_LONG, len); + for (var i = 0; i < len; i++) { + memSeg.setAtIndex(JAVA_LONG, i, array[i]); + } + return memSeg; + } + static MemorySegment floatArrayToSlice(SegmentAllocator arena, float[] array) { + var len = array.length; + var memSeg = arena.allocate(JAVA_FLOAT, len); + for (var i = 0; i < len; i++) { + memSeg.setAtIndex(JAVA_FLOAT, i, array[i]); + } + return memSeg; + } + + static MemorySegment doubleArrayToSlice(SegmentAllocator arena, double[] array) { + return arena.allocateFrom(JAVA_DOUBLE, array); + } + + static String readUtf8(MemorySegment segment) { + var data = DiplomatStringView.data(segment); + var len = DiplomatStringView.len(segment); + var strData = data.asSlice(0, len); + var bytes = strData.toArray(JAVA_BYTE); + var string = new String(bytes, StandardCharsets.UTF_8); + return string; + } + + static String readUtf16(MemorySegment segment) { + var data = DiplomatStringView.data(segment); + var len = DiplomatStringView.len(segment); + var strData = data.asSlice(0, len); + var bytes = strData.toArray(JAVA_BYTE); + var string = new String(bytes, StandardCharsets.UTF_16); + return string; + } + // for parameter conversion + static MemorySegment strToUtf8Slice(SegmentAllocator arena, String str) { + var vData = arena.allocateFrom(str, StandardCharsets.UTF_8); + var vLen = vData.byteSize() - 1; + var vView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(vView, vLen); + DiplomatStringView.data(vView, vData); + return vData; + } + + static MemorySegment strToUtf16Slice(SegmentAllocator arena, String str) { + var vData = arena.allocateFrom(str, StandardCharsets.UTF_16); + var vLen = vData.byteSize() - 1; + var vView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(vView, vLen); + DiplomatStringView.data(vView, vData); + return vData; + } + static MemorySegment strs16(SegmentAllocator arena, String [] strings) { + var diplomatStrsData = DiplomatStringView.allocateArray(strings.length, arena); + var layout = DiplomatStringView.layout(); + diplomatStrsData.elements(layout).forEach(new Consumer() { + int i = 0; + @Override + public void accept(MemorySegment memorySegment) { + var str = strings[i]; + var bytes = str.getBytes(StandardCharsets.UTF_16); + var data = arena.allocateFrom(JAVA_BYTE, bytes); + DiplomatStringView.data(memorySegment, data); + DiplomatStringView.len(memorySegment, bytes.length); + i++; + } + }); + var diplomatStrsView = DiplomatStrings16View.allocate(arena); + DiplomatStrings16View.len(diplomatStrsView, strings.length); + DiplomatStrings16View.data(diplomatStrsView, diplomatStrsData); + return diplomatStrsView; + } + + static MemorySegment strs8(SegmentAllocator arena, String [] strings) { + var diplomatStrsData = DiplomatStringView.allocateArray(strings.length, arena); + var layout = DiplomatStringView.layout(); + diplomatStrsData.elements(layout).forEach(new Consumer() { + int i = 0; + @Override + public void accept(MemorySegment memorySegment) { + var str = strings[i]; + var bytes = str.getBytes(StandardCharsets.UTF_8); + var data = arena.allocateFrom(JAVA_BYTE, bytes); + DiplomatStringView.data(memorySegment, data); + DiplomatStringView.len(memorySegment, bytes.length); + i++; + } + }); + + var diplomatStrsView = DiplomatStringsView.allocate(arena); + DiplomatStringsView.len(diplomatStrsView, strings.length); + DiplomatStringsView.data(diplomatStrsView, diplomatStrsData); + return diplomatStrsView; + } + + static String readUtf8FromWriteable(MemorySegment writeable) { + var buffer = DiplomatWrite.buf(writeable); + var len = DiplomatWrite.len(writeable); + var bytes = new byte[(int) len]; + for (var i = 0; i < len; i++) { + bytes[i] = buffer.get(JAVA_BYTE, i); + } + return new String(bytes, StandardCharsets.UTF_8); + } +} diff --git a/cli/templates/Method.java.jinja b/cli/templates/Method.java.jinja new file mode 100644 index 0000000..5cc4081 --- /dev/null +++ b/cli/templates/Method.java.jinja @@ -0,0 +1,35 @@ +public{% if is_static %} static {% else %} {% endif %}{{return_ty}} +{%- match method_name -%} +{%- when Some with (method_name) %} {{method_name}} +{%- when None -%} +{%- endmatch -%} +( +{%- for param in params -%} +{{param.ty}} {{param.name}}{% if loop.last%}{% else %},{% endif -%} +{%- endfor -%} +) { + {# need to match on the type of allocations? #} + {% if allocations -%} + try (var arena = Arena.ofConfined()) { + {% for conv in param_conversions -%} + {{conv.conversion_def|indent(8)}} + {% endfor -%} + {% if native_return_void %}{% else %}var nativeVal = {% endif %}{{native_invocation}}( + {%- for conv in param_conversions -%} + {{conv.converted_value}}{% if loop.last %}{% else %}, {% endif -%} + {% endfor -%} + ); + {{return_conversion|indent(8)}} + } + {%- else -%} + {% for conv in param_conversions -%} + {{conv.conversion_def|indent(4)}} + {% endfor -%} + {% if native_return_void %}{% else %}var nativeVal = {% endif %}{{native_invocation}}( + {%- for conv in param_conversions -%} + {{conv.converted_value}}{% if loop.last %}{% else %}, {% endif -%} + {% endfor -%} + ); + {{return_conversion|indent(4)}} + {%- endif %} +} diff --git a/cli/templates/Opaque.java.jinja b/cli/templates/Opaque.java.jinja new file mode 100644 index 0000000..d828a2b --- /dev/null +++ b/cli/templates/Opaque.java.jinja @@ -0,0 +1,57 @@ +package {{domain}}.{{lib_name}}; + +import {{domain}}.{{lib_name}}.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class {{type_name}} { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + {% for edge in edges -%} + List {{edge}}Edges = List.of(); + {% endfor %} + + static class {{type_name}}Cleaner implements Runnable { + + MemorySegment segment; + {{type_name}}Cleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + {{lib_name}}_h.{{type_name}}_destroy(this.segment); + } + } + + {{type_name}}() {} + {{type_name}}(MemorySegment handle, List selfEdges + {%- for edge in edges -%} + , List {{edge}}Edges + {%- endfor -%} + ) { + this.internal = handle; + this.selfEdges = selfEdges; + {% for edge in edges -%} + this.{{edge}}Edges = {{edge}}Edges; + {% endfor %} + + } + {% for method in static_methods %} + {{method|indent(4)}} + {% endfor %} + {% for method in class_methods %} + {{method|indent(4)}} + {% endfor %} +} diff --git a/cli/templates/OpaqueConstructor.java.jinja b/cli/templates/OpaqueConstructor.java.jinja new file mode 100644 index 0000000..3e8578d --- /dev/null +++ b/cli/templates/OpaqueConstructor.java.jinja @@ -0,0 +1,3 @@ +this.internal = nativeVal; +var cleaner = new {{return_ty}}.{{return_ty}}Cleaner(nativeVal); +this.cleanable = Lib.cleaner.register(this, cleaner); diff --git a/cli/templates/OpaqueConversion.java.jinja b/cli/templates/OpaqueConversion.java.jinja new file mode 100644 index 0000000..e9fe2bf --- /dev/null +++ b/cli/templates/OpaqueConversion.java.jinja @@ -0,0 +1,20 @@ +List selfEdges = +{%- match self_edges %} +{%- when Some with (self_edges) %} List.of({{self_edges}}); +{%- when None %} List.of(); +{%- endmatch %} + + +{% for lifetime in lifetimes %} +List {{lifetime.name}}Edges = List.of( +{%- for edge in lifetime.edges -%} +{% if loop.first %}{% else %}, {% endif %}{{edge}} +{%- endfor -%} +); + +{%- endfor %} +var {{name}}Val = new {{ty}}({{native_val}}, selfEdges +{%- for lifetime in lifetimes -%} +, {{lifetime.name}}Edges +{%- endfor -%} +); diff --git a/cli/templates/Struct.java.jinja b/cli/templates/Struct.java.jinja new file mode 100644 index 0000000..e1e4799 --- /dev/null +++ b/cli/templates/Struct.java.jinja @@ -0,0 +1,65 @@ +package {{domain}}.{{lib_name}}; + +import {{domain}}.{{lib_name}}.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class {{type_name}} { + {% for field in fields -%} + {{field.ty}} {{field.name}}; + {% endfor %} + + List selfEdges = List.of(); + {% for edge in edges -%} + List {{edge}}Edges = List.of(); + {% endfor %} + + private {{type_name}}() { + } + + {{type_name}}(MemorySegment structSegment + {%- for edge in edges -%} + , List {{edge}}Edges + {%- endfor -%} + ) { + this.selfEdges = selfEdges; + {% for edge in edges -%} + this.{{edge}}Edges = {{edge}}Edges; + {% endfor %} + + {% for field in fields -%} + var {{field.name}}Native = {{domain}}.{{lib_name}}.ntv.{{type_name}}.{{field.native_name}}(structSegment); + {{field.to_java.conversion|indent(8)}} + this.{{field.name}} = {{field.to_java.converted_value}}; + {% endfor %} + + } + + {% if is_zst -%} + {% else -%} + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = {{domain}}.{{lib_name}}.ntv.{{type_name}}.allocate(arena); + + {% for field in fields -%} + {{field.to_native.conversion|indent(8)}} + {{domain}}.{{lib_name}}.ntv.{{type_name}}.{{field.native_name}}(returnVal, {{field.to_native.converted_value}}); + {% endfor %} + + return returnVal; + + } + {% endif -%} + + {% for method in methods %} + {{method|indent(4)}} + {% endfor %} +} + + diff --git a/cli/templates/StructConversion.java.jinja b/cli/templates/StructConversion.java.jinja new file mode 100644 index 0000000..50b5ff6 --- /dev/null +++ b/cli/templates/StructConversion.java.jinja @@ -0,0 +1,17 @@ +var {{name}}Val = new {{ty}}({{native_val}} +{%- for lifetime in lifetimes -%} +, {% if lifetime.edges.len() > 1 -%} +List.of( +{%- for edge in lifetime.edges -%} +{% if loop.first %}{% else %}, {% endif %}{{edge}} +{%- endfor -%} +) +{%- else if lifetime.edges.len() == 0 -%} +{%- for edge in lifetime.edges -%} +List.of({{edge}}) +{%- endfor -%} +{%- else -%} +List.of() +{%- endif -%} +{%- endfor -%} +); diff --git a/feature/.gitignore b/feature/.gitignore new file mode 100644 index 0000000..f8305e7 --- /dev/null +++ b/feature/.gitignore @@ -0,0 +1 @@ +a.out \ No newline at end of file diff --git a/feature/Cargo.toml b/feature/Cargo.toml new file mode 100644 index 0000000..25baafd --- /dev/null +++ b/feature/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "feature-tests" +version = "0.0.0" +publish = false +authors = [ + "Jan Cristina ", + "Manish Goregaokar ", +] +edition = "2021" + +[lib] +crate-type = ["staticlib", "rlib", "cdylib"] + +[dependencies] +diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "588f6ffe413bfca367bbb2a749a5965d40a3d5b3", package = "diplomat-runtime"} +diplomat = { git = "https://github.com/rust-diplomat/diplomat", rev = "588f6ffe413bfca367bbb2a749a5965d40a3d5b3", package = "diplomat" } +log = { version = "0.4" } diff --git a/feature/diplomat-java-conf.toml b/feature/diplomat-java-conf.toml new file mode 100644 index 0000000..31bf6f3 --- /dev/null +++ b/feature/diplomat-java-conf.toml @@ -0,0 +1,2 @@ +domain = "dev.diplomattest" +lib_name = "somelib" diff --git a/feature/java/somelib/.gitignore b/feature/java/somelib/.gitignore new file mode 100644 index 0000000..f355166 --- /dev/null +++ b/feature/java/somelib/.gitignore @@ -0,0 +1,45 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +.idea/encodings.xml +.idea/misc.xml +.idea/vcs.xml +.idea/codeStyles +.idea/** +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store + +libsomelib.dylib diff --git a/feature/java/somelib/pom.xml b/feature/java/somelib/pom.xml new file mode 100644 index 0000000..6b89185 --- /dev/null +++ b/feature/java/somelib/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + dev.diplomattest.somelib + somelib + 1.0-SNAPSHOT + + + 22 + 22 + UTF-8 + + + + net.java.dev.jna + jna + 5.14.0 + + + org.junit.jupiter + junit-jupiter + 5.10.3 + test + + + org.openjdk.jmh + jmh-core + 1.37 + + + org.openjdk.jmh + jmh-generator-annprocess + 1.37 + provided + + + org.apache.maven.surefire + surefire-junit47 + 3.5.0 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.0 + + + + + \ No newline at end of file diff --git a/feature/java/somelib/src/jmh/java/dev/diplomattest/somelib/OpaqueBench.java b/feature/java/somelib/src/jmh/java/dev/diplomattest/somelib/OpaqueBench.java new file mode 100644 index 0000000..8a33739 --- /dev/null +++ b/feature/java/somelib/src/jmh/java/dev/diplomattest/somelib/OpaqueBench.java @@ -0,0 +1,28 @@ +package dev.diplomattest.somelib; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +public class OpaqueBench { + @Benchmark + public static void benchOpaque(Blackhole bh) { + var opaque = Opaque.fromStr("it's amazing to be here"); + bh.consume(opaque); + // opaque.destroy(); + } + + public static void main(String[] args) throws RunnerException { + Options opt = new OptionsBuilder() + .include(OpaqueBench.class.getSimpleName()) + .warmupIterations(2) + .measurementIterations(2) + .forks(1) + .build(); + + new Runner(opt).run(); + } +} diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Bar.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Bar.java new file mode 100644 index 0000000..e63774e --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Bar.java @@ -0,0 +1,64 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class Bar { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + List bEdges = List.of(); + List aEdges = List.of(); + + + static class BarCleaner implements Runnable { + + MemorySegment segment; + BarCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.Bar_destroy(this.segment); + } + } + + Bar() {} + Bar(MemorySegment handle, List selfEdges, List bEdges, List aEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + this.bEdges = bEdges; + this.aEdges = aEdges; + + + } + + + public Foo foo() { + + + var nativeVal = somelib_h.Bar_foo(internal); + + List selfEdges = List.of(this); + + + + List aEdges = List.of(this); + var returnVal = new Foo(nativeVal, selfEdges, aEdges); + return returnVal; + + } + +} \ No newline at end of file diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/BorrowedFields.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/BorrowedFields.java new file mode 100644 index 0000000..066f5f4 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/BorrowedFields.java @@ -0,0 +1,96 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class BorrowedFields { + String a; + String b; + String c; + + + List selfEdges = List.of(); + List aEdges = List.of(); + + + private BorrowedFields() { + } + + BorrowedFields(MemorySegment structSegment, List aEdges) { + this.selfEdges = selfEdges; + this.aEdges = aEdges; + + + var aNative = dev.diplomattest.somelib.ntv.BorrowedFields.a(structSegment); + var aVal = SliceUtils.readUtf16(aNative); + this.a = aVal; + var bNative = dev.diplomattest.somelib.ntv.BorrowedFields.b(structSegment); + var bVal = SliceUtils.readUtf8(bNative); + this.b = bVal; + var cNative = dev.diplomattest.somelib.ntv.BorrowedFields.c(structSegment); + var cVal = SliceUtils.readUtf8(cNative); + this.c = cVal; + + + } + + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = dev.diplomattest.somelib.ntv.BorrowedFields.allocate(arena); + + var aData = arena.allocateFrom(a, StandardCharsets.UTF_16); + var aLen = aData.byteSize() - 1; // allocated strings are null terminated + var aView = DiplomatString16View.allocate(arena); + DiplomatString16View.len(aView, aLen); + DiplomatString16View.data(aView, aData); + dev.diplomattest.somelib.ntv.BorrowedFields.a(returnVal, aView); + var bData= arena.allocateFrom(b, StandardCharsets.UTF_8); + var bLen = bData.byteSize() - 1; // allocated strings are null terminated + var bView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(bView, bLen); + DiplomatStringView.data(bView, bData); + dev.diplomattest.somelib.ntv.BorrowedFields.b(returnVal, bView); + var cData= arena.allocateFrom(c, StandardCharsets.UTF_8); + var cLen = cData.byteSize() - 1; // allocated strings are null terminated + var cView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(cView, cLen); + DiplomatStringView.data(cView, cData); + dev.diplomattest.somelib.ntv.BorrowedFields.c(returnVal, cView); + + + return returnVal; + + } + + public static BorrowedFields fromBarAndStrings(Bar bar,String dstr16,String utf8Str) { + + try (var arena = Arena.ofConfined()) { + + var barNative = bar.internal; + var dstr16Data = Arena.ofAuto().allocateFrom(dstr16, StandardCharsets.UTF_16); + var dstr16Len = dstr16Data.byteSize() - 1; // allocated strings are null terminated + var dstr16View = DiplomatString16View.allocate(Arena.ofAuto()); + DiplomatString16View.len(dstr16View, dstr16Len); + DiplomatString16View.data(dstr16View, dstr16Data); + var utf8StrData= Arena.ofAuto().allocateFrom(utf8Str, StandardCharsets.UTF_8); + var utf8StrLen = utf8StrData.byteSize() - 1; // allocated strings are null terminated + var utf8StrView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(utf8StrView, utf8StrLen); + DiplomatStringView.data(utf8StrView, utf8StrData); + var nativeVal = somelib_h.BorrowedFields_from_bar_and_strings(arena, barNative, dstr16View, utf8StrView); + + var returnVal = new BorrowedFields(nativeVal, List.of(bar, dstr16, utf8Str)); + return returnVal; + + } + } + +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/BorrowedFieldsReturning.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/BorrowedFieldsReturning.java new file mode 100644 index 0000000..eefce6a --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/BorrowedFieldsReturning.java @@ -0,0 +1,53 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class BorrowedFieldsReturning { + String bytes; + + + List selfEdges = List.of(); + List aEdges = List.of(); + + + private BorrowedFieldsReturning() { + } + + BorrowedFieldsReturning(MemorySegment structSegment, List aEdges) { + this.selfEdges = selfEdges; + this.aEdges = aEdges; + + + var bytesNative = dev.diplomattest.somelib.ntv.BorrowedFieldsReturning.bytes(structSegment); + var bytesVal = SliceUtils.readUtf8(bytesNative); + this.bytes = bytesVal; + + + } + + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = dev.diplomattest.somelib.ntv.BorrowedFieldsReturning.allocate(arena); + + var bytesData= arena.allocateFrom(bytes, StandardCharsets.UTF_8); + var bytesLen = bytesData.byteSize() - 1; // allocated strings are null terminated + var bytesView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(bytesView, bytesLen); + DiplomatStringView.data(bytesView, bytesData); + dev.diplomattest.somelib.ntv.BorrowedFieldsReturning.bytes(returnVal, bytesView); + + + return returnVal; + + } + +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/BorrowedFieldsWithBounds.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/BorrowedFieldsWithBounds.java new file mode 100644 index 0000000..f595e1d --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/BorrowedFieldsWithBounds.java @@ -0,0 +1,100 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class BorrowedFieldsWithBounds { + String fieldA; + String fieldB; + String fieldC; + + + List selfEdges = List.of(); + List aEdges = List.of(); + List bEdges = List.of(); + List cEdges = List.of(); + + + private BorrowedFieldsWithBounds() { + } + + BorrowedFieldsWithBounds(MemorySegment structSegment, List aEdges, List bEdges, List cEdges) { + this.selfEdges = selfEdges; + this.aEdges = aEdges; + this.bEdges = bEdges; + this.cEdges = cEdges; + + + var fieldANative = dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.field_a(structSegment); + var fieldAVal = SliceUtils.readUtf16(fieldANative); + this.fieldA = fieldAVal; + var fieldBNative = dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.field_b(structSegment); + var fieldBVal = SliceUtils.readUtf8(fieldBNative); + this.fieldB = fieldBVal; + var fieldCNative = dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.field_c(structSegment); + var fieldCVal = SliceUtils.readUtf8(fieldCNative); + this.fieldC = fieldCVal; + + + } + + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.allocate(arena); + + var fieldAData = arena.allocateFrom(fieldA, StandardCharsets.UTF_16); + var fieldALen = fieldAData.byteSize() - 1; // allocated strings are null terminated + var fieldAView = DiplomatString16View.allocate(arena); + DiplomatString16View.len(fieldAView, fieldALen); + DiplomatString16View.data(fieldAView, fieldAData); + dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.field_a(returnVal, fieldAView); + var fieldBData= arena.allocateFrom(fieldB, StandardCharsets.UTF_8); + var fieldBLen = fieldBData.byteSize() - 1; // allocated strings are null terminated + var fieldBView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(fieldBView, fieldBLen); + DiplomatStringView.data(fieldBView, fieldBData); + dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.field_b(returnVal, fieldBView); + var fieldCData= arena.allocateFrom(fieldC, StandardCharsets.UTF_8); + var fieldCLen = fieldCData.byteSize() - 1; // allocated strings are null terminated + var fieldCView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(fieldCView, fieldCLen); + DiplomatStringView.data(fieldCView, fieldCData); + dev.diplomattest.somelib.ntv.BorrowedFieldsWithBounds.field_c(returnVal, fieldCView); + + + return returnVal; + + } + + public static BorrowedFieldsWithBounds fromFooAndStrings(Foo foo,String dstr16X,String utf8StrZ) { + + try (var arena = Arena.ofConfined()) { + + var fooNative = foo.internal; + var dstr16XData = Arena.ofAuto().allocateFrom(dstr16X, StandardCharsets.UTF_16); + var dstr16XLen = dstr16XData.byteSize() - 1; // allocated strings are null terminated + var dstr16XView = DiplomatString16View.allocate(Arena.ofAuto()); + DiplomatString16View.len(dstr16XView, dstr16XLen); + DiplomatString16View.data(dstr16XView, dstr16XData); + var utf8StrZData= Arena.ofAuto().allocateFrom(utf8StrZ, StandardCharsets.UTF_8); + var utf8StrZLen = utf8StrZData.byteSize() - 1; // allocated strings are null terminated + var utf8StrZView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(utf8StrZView, utf8StrZLen); + DiplomatStringView.data(utf8StrZView, utf8StrZData); + var nativeVal = somelib_h.BorrowedFieldsWithBounds_from_foo_and_strings(arena, fooNative, dstr16XView, utf8StrZView); + + var returnVal = new BorrowedFieldsWithBounds(nativeVal, List.of(foo, dstr16X, utf8StrZ), List.of(foo, utf8StrZ), List.of()); + return returnVal; + + } + } + +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ContiguousEnum.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ContiguousEnum.java new file mode 100644 index 0000000..bea541a --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ContiguousEnum.java @@ -0,0 +1,59 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.somelib_h; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; + +public enum ContiguousEnum { + C, + D, + E, + F, + ; + + static ContiguousEnum fromInt(int i) { + switch (i) { + case 0 -> { + return ContiguousEnum.C; + } + case 1 -> { + return ContiguousEnum.D; + } + case 2 -> { + return ContiguousEnum.E; + } + case 3 -> { + return ContiguousEnum.F; + } + + } + throw new RuntimeException("Unexpected int for ContiguousEnum:" + i); + } + + int toInt() { + switch (this) { + case C -> { + return 0; + } + case D -> { + return 1; + } + case E -> { + return 2; + } + case F -> { + return 3; + } + + } + throw new RuntimeException("Unexpected variant for ContiguousEnum:" + this); + } + + +} diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/CyclicStructA.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/CyclicStructA.java new file mode 100644 index 0000000..2eb0b76 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/CyclicStructA.java @@ -0,0 +1,59 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class CyclicStructA { + CyclicStructB a; + + + List selfEdges = List.of(); + + + private CyclicStructA() { + } + + CyclicStructA(MemorySegment structSegment) { + this.selfEdges = selfEdges; + + + var aNative = dev.diplomattest.somelib.ntv.CyclicStructA.a(structSegment); + var aVal = new CyclicStructB(aNative); + this.a = aVal; + + + } + + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = dev.diplomattest.somelib.ntv.CyclicStructA.allocate(arena); + + var aNative = a.toNative(arena); + dev.diplomattest.somelib.ntv.CyclicStructA.a(returnVal, aNative); + + + return returnVal; + + } + + public static CyclicStructB getB() { + + try (var arena = Arena.ofConfined()) { + + var nativeVal = somelib_h.CyclicStructA_get_b(arena); + + var returnVal = new CyclicStructB(nativeVal); + return returnVal; + + } + } + +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/CyclicStructB.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/CyclicStructB.java new file mode 100644 index 0000000..f7d41fc --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/CyclicStructB.java @@ -0,0 +1,59 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class CyclicStructB { + byte field; + + + List selfEdges = List.of(); + + + private CyclicStructB() { + } + + CyclicStructB(MemorySegment structSegment) { + this.selfEdges = selfEdges; + + + var fieldNative = dev.diplomattest.somelib.ntv.CyclicStructB.field(structSegment); + var fieldVal = fieldNative; + this.field = fieldVal; + + + } + + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = dev.diplomattest.somelib.ntv.CyclicStructB.allocate(arena); + + var fieldNative = field; + dev.diplomattest.somelib.ntv.CyclicStructB.field(returnVal, fieldNative); + + + return returnVal; + + } + + public static CyclicStructA getA() { + + try (var arena = Arena.ofConfined()) { + + var nativeVal = somelib_h.CyclicStructB_get_a(arena); + + var returnVal = new CyclicStructA(nativeVal); + return returnVal; + + } + } + +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Float64Vec.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Float64Vec.java new file mode 100644 index 0000000..97f3fdf --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Float64Vec.java @@ -0,0 +1,266 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class Float64Vec { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + + + static class Float64VecCleaner implements Runnable { + + MemorySegment segment; + Float64VecCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.Float64Vec_destroy(this.segment); + } + } + + Float64Vec() {} + Float64Vec(MemorySegment handle, List selfEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + + + } + + public static Float64Vec new_(double[] v) { + + try (var arena = Arena.ofConfined()) { + var vLen = v.length; + var vData= Arena.ofAuto().allocateFrom(JAVA_DOUBLE, v); + var vView = DiplomatF64View.allocate(Arena.ofAuto()); + DiplomatF64View.len(vView, vLen); + DiplomatF64View.data(vView, vData); + + var nativeVal = somelib_h.Float64Vec_new(vView); + + List selfEdges = List.of(); + + + + var returnVal = new Float64Vec(nativeVal, selfEdges); + return returnVal; + + } + } + + public static Float64Vec newBool(boolean[] v) { + + try (var arena = Arena.ofConfined()) { + var vLen = v.length; + byte[] vByteArray = new byte[vLen]; + for (int i = 0; i < vLen; i++) { + vByteArray[i] = (byte) (v[i] ? 1 : 0); + } + var vData = Arena.ofAuto().allocateFrom(JAVA_BYTE, vByteArray); + var vView = DiplomatBoolView.allocate(Arena.ofAuto()); + DiplomatBoolView.len(vView, vLen); + DiplomatBoolView.data(vView, vData); + + var nativeVal = somelib_h.Float64Vec_new_bool(vView); + + List selfEdges = List.of(); + + + + var returnVal = new Float64Vec(nativeVal, selfEdges); + return returnVal; + + } + } + + public static Float64Vec newI16(short[] v) { + + try (var arena = Arena.ofConfined()) { + var vLen = v.length; + var vData= Arena.ofAuto().allocateFrom(JAVA_SHORT, v); + var vView = DiplomatI16View.allocate(Arena.ofAuto()); + DiplomatI16View.len(vView, vLen); + DiplomatI16View.data(vView, vData); + + var nativeVal = somelib_h.Float64Vec_new_i16(vView); + + List selfEdges = List.of(); + + + + var returnVal = new Float64Vec(nativeVal, selfEdges); + return returnVal; + + } + } + + public static Float64Vec newU16(short[] v) { + + try (var arena = Arena.ofConfined()) { + var vLen = v.length; + var vData= Arena.ofAuto().allocateFrom(JAVA_SHORT, v); + var vView = DiplomatU16View.allocate(Arena.ofAuto()); + DiplomatU16View.len(vView, vLen); + DiplomatU16View.data(vView, vData); + + var nativeVal = somelib_h.Float64Vec_new_u16(vView); + + List selfEdges = List.of(); + + + + var returnVal = new Float64Vec(nativeVal, selfEdges); + return returnVal; + + } + } + + public static Float64Vec newIsize(long[] v) { + + try (var arena = Arena.ofConfined()) { + var vLen = v.length; + var vData= Arena.ofAuto().allocateFrom(JAVA_LONG, v); + var vView = DiplomatIsizeView.allocate(Arena.ofAuto()); + DiplomatIsizeView.len(vView, vLen); + DiplomatIsizeView.data(vView, vData); + + var nativeVal = somelib_h.Float64Vec_new_isize(vView); + + List selfEdges = List.of(); + + + + var returnVal = new Float64Vec(nativeVal, selfEdges); + return returnVal; + + } + } + + public static Float64Vec newUsize(long[] v) { + + try (var arena = Arena.ofConfined()) { + var vLen = v.length; + var vData= Arena.ofAuto().allocateFrom(JAVA_LONG, v); + var vView = DiplomatUsizeView.allocate(Arena.ofAuto()); + DiplomatUsizeView.len(vView, vLen); + DiplomatUsizeView.data(vView, vData); + + var nativeVal = somelib_h.Float64Vec_new_usize(vView); + + List selfEdges = List.of(); + + + + var returnVal = new Float64Vec(nativeVal, selfEdges); + return returnVal; + + } + } + + public static Float64Vec newF64BeBytes(byte[] v) { + + try (var arena = Arena.ofConfined()) { + var vLen = v.length; + var vData= Arena.ofAuto().allocateFrom(JAVA_BYTE, v); + var vView = DiplomatU8View.allocate(Arena.ofAuto()); + DiplomatU8View.len(vView, vLen); + DiplomatU8View.data(vView, vData); + + var nativeVal = somelib_h.Float64Vec_new_f64_be_bytes(vView); + + List selfEdges = List.of(); + + + + var returnVal = new Float64Vec(nativeVal, selfEdges); + return returnVal; + + } + } + + + public double[] asSlice() { + + try (var arena = Arena.ofConfined()) { + + + var nativeVal = somelib_h.Float64Vec_as_slice(arena, internal); + + var data = dev.diplomattest.somelib.ntv.DiplomatF64View.data(nativeVal); + var len = dev.diplomattest.somelib.ntv.DiplomatF64View.len(nativeVal); + var returnVal = SliceUtils.doubleSliceToArray(nativeVal); + return returnVal; + + } + } + + public void fillSlice(double[] v) { + + try (var arena = Arena.ofConfined()) { + + var vLen = v.length; + var vData= Arena.ofAuto().allocateFrom(JAVA_DOUBLE, v); + var vView = DiplomatF64View.allocate(Arena.ofAuto()); + DiplomatF64View.len(vView, vLen); + DiplomatF64View.data(vView, vData); + + somelib_h.Float64Vec_fill_slice(internal, vView); + + } + } + + public void setValue(double[] newSlice) { + + try (var arena = Arena.ofConfined()) { + + var newSliceLen = newSlice.length; + var newSliceData= Arena.ofAuto().allocateFrom(JAVA_DOUBLE, newSlice); + var newSliceView = DiplomatF64View.allocate(Arena.ofAuto()); + DiplomatF64View.len(newSliceView, newSliceLen); + DiplomatF64View.data(newSliceView, newSliceData); + + somelib_h.Float64Vec_set_value(internal, newSliceView); + + } + } + + public String toString_() { + + + var writeable = somelib_h.diplomat_buffer_write_create(0); + somelib_h.Float64Vec_to_string(internal, writeable); + var string = SliceUtils. readUtf8FromWriteable(writeable); + somelib_h.diplomat_buffer_write_destroy(writeable); + return string; + } + + public double[] borrow() { + + try (var arena = Arena.ofConfined()) { + + + var nativeVal = somelib_h.Float64Vec_borrow(arena, internal); + + var data = dev.diplomattest.somelib.ntv.DiplomatF64View.data(nativeVal); + var len = dev.diplomattest.somelib.ntv.DiplomatF64View.len(nativeVal); + var returnVal = SliceUtils.doubleSliceToArray(nativeVal); + return returnVal; + + } + } + +} \ No newline at end of file diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Foo.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Foo.java new file mode 100644 index 0000000..9981364 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Foo.java @@ -0,0 +1,136 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class Foo { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + List aEdges = List.of(); + + + static class FooCleaner implements Runnable { + + MemorySegment segment; + FooCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.Foo_destroy(this.segment); + } + } + + Foo() {} + Foo(MemorySegment handle, List selfEdges, List aEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + this.aEdges = aEdges; + + + } + + public static Foo new_(String x) { + + try (var arena = Arena.ofConfined()) { + var xData= Arena.ofAuto().allocateFrom(x, StandardCharsets.UTF_8); + var xLen = xData.byteSize() - 1; // allocated strings are null terminated + var xView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(xView, xLen); + DiplomatStringView.data(xView, xData); + var nativeVal = somelib_h.Foo_new(xView); + + List selfEdges = List.of(); + + + + List aEdges = List.of(x); + var returnVal = new Foo(nativeVal, selfEdges, aEdges); + return returnVal; + + } + } + + public static Foo extractFromFields(BorrowedFields fields) { + + try (var arena = Arena.ofConfined()) { + var fieldsNative = fields.toNative(arena); + var nativeVal = somelib_h.Foo_extract_from_fields(fieldsNative); + + List selfEdges = List.of(); + + + + List aEdges = List.of(fields); + var returnVal = new Foo(nativeVal, selfEdges, aEdges); + return returnVal; + + } + } + + public static Foo extractFromBounds(BorrowedFieldsWithBounds bounds,String anotherString) { + + try (var arena = Arena.ofConfined()) { + var boundsNative = bounds.toNative(arena); + var anotherStringData= Arena.ofAuto().allocateFrom(anotherString, StandardCharsets.UTF_8); + var anotherStringLen = anotherStringData.byteSize() - 1; // allocated strings are null terminated + var anotherStringView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(anotherStringView, anotherStringLen); + DiplomatStringView.data(anotherStringView, anotherStringData); + var nativeVal = somelib_h.Foo_extract_from_bounds(boundsNative, anotherStringView); + + List selfEdges = List.of(); + + + + List aEdges = List.of(bounds, bounds, anotherString); + var returnVal = new Foo(nativeVal, selfEdges, aEdges); + return returnVal; + + } + } + + + public Bar getBar() { + + + var nativeVal = somelib_h.Foo_get_bar(internal); + + List selfEdges = List.of(); + + + + List bEdges = List.of(this); + List aEdges = List.of(this); + var returnVal = new Bar(nativeVal, selfEdges, bEdges, aEdges); + return returnVal; + + } + + public BorrowedFieldsReturning asReturning() { + + try (var arena = Arena.ofConfined()) { + + + var nativeVal = somelib_h.Foo_as_returning(arena, internal); + + var returnVal = new BorrowedFieldsReturning(nativeVal, List.of()); + return returnVal; + + } + } + +} \ No newline at end of file diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ImportedStruct.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ImportedStruct.java new file mode 100644 index 0000000..c17cc32 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ImportedStruct.java @@ -0,0 +1,53 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class ImportedStruct { + UnimportedEnum foo; + byte count; + + + List selfEdges = List.of(); + + + private ImportedStruct() { + } + + ImportedStruct(MemorySegment structSegment) { + this.selfEdges = selfEdges; + + + var fooNative = dev.diplomattest.somelib.ntv.ImportedStruct.foo(structSegment); + var fooVal = UnimportedEnum.fromInt(fooNative); + this.foo = fooVal; + var countNative = dev.diplomattest.somelib.ntv.ImportedStruct.count(structSegment); + var countVal = countNative; + this.count = countVal; + + + } + + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = dev.diplomattest.somelib.ntv.ImportedStruct.allocate(arena); + + var fooNative = foo.toInt(); + dev.diplomattest.somelib.ntv.ImportedStruct.foo(returnVal, fooNative); + var countNative = count; + dev.diplomattest.somelib.ntv.ImportedStruct.count(returnVal, countNative); + + + return returnVal; + + } + +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Lib.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Lib.java new file mode 100644 index 0000000..77d56cc --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Lib.java @@ -0,0 +1,205 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.*; +import java.lang.ref.Cleaner; +import java.nio.charset.StandardCharsets; +import java.util.function.Consumer; +import java.util.Arrays; + +import static java.lang.foreign.ValueLayout.*; + +public class Lib { + static final Cleaner cleaner = Cleaner.create(); +} + +class SliceUtils { + + + static boolean[] booleanSliceToArray(MemorySegment segment) { + var data = DiplomatU8View.data(segment); + var len = DiplomatU8View.len(segment); + var slice = data.asSlice(0, len * JAVA_BYTE.byteSize()); + var byteArray = slice.toArray(JAVA_BYTE); + var returnArray = new boolean[(int) len]; + for (var i=0; i < len; i++ ) { + returnArray[i] = (byteArray[i] == 1); + } + return returnArray; + } + + static byte[] byteSliceToArray(MemorySegment segment) { + var data = DiplomatU8View.data(segment); + var len = DiplomatU8View.len(segment); + var slice = data.asSlice(0, len * JAVA_BYTE.byteSize()); + return slice.toArray(JAVA_BYTE); + } + + static short[] shortSliceToArray(MemorySegment segment) { + var data = DiplomatU16View.data(segment); + var len = DiplomatU16View.len(segment); + var slice = data.asSlice(0, len * JAVA_SHORT.byteSize()); + return slice.toArray(JAVA_SHORT); + } + static int[] intSliceToArray(MemorySegment segment) { + var data = DiplomatU32View.data(segment); + var len = DiplomatU32View.len(segment); + var slice = data.asSlice(0, len * JAVA_INT.byteSize()); + return slice.toArray(JAVA_INT); + } + static long[] longSliceToArray(MemorySegment segment) { + var data = DiplomatU64View.data(segment); + var len = DiplomatU64View.len(segment); + var slice = data.asSlice(0, len * JAVA_LONG.byteSize()); + return slice.toArray(JAVA_LONG); + } + static float[] floatSliceToArray(MemorySegment segment) { + var data = DiplomatF32View.data(segment); + var len = DiplomatF32View.len(segment); + var slice = data.asSlice(0, len * JAVA_FLOAT.byteSize()); + return slice.toArray(JAVA_FLOAT); + } + + static double[] doubleSliceToArray(MemorySegment segment) { + var data = DiplomatF64View.data(segment); + var len = DiplomatF64View.len(segment); + var slice = data.asSlice(0, len * JAVA_DOUBLE.byteSize()); + return slice.toArray(JAVA_DOUBLE); + } + + static MemorySegment byteArrayToSlice(SegmentAllocator arena, byte[] array) { + var len = array.length; + var memSeg = arena.allocate(JAVA_BYTE, len); + for (var i = 0; i < len; i++) { + memSeg.setAtIndex(JAVA_BYTE, i, array[i]); + } + return memSeg; + } + + static MemorySegment shortArrayToSlice(SegmentAllocator arena, short[] array) { + var len = array.length; + var memSeg = arena.allocate(JAVA_SHORT, len); + for (var i = 0; i < len; i++) { + memSeg.setAtIndex(JAVA_SHORT, i, array[i]); + } + return memSeg; + } + + static MemorySegment intArrayToSlice(SegmentAllocator arena, int[] array) { + var len = array.length; + var memSeg = arena.allocate(JAVA_INT, len); + for (var i = 0; i < len; i++) { + memSeg.setAtIndex(JAVA_INT, i, array[i]); + } + return memSeg; + } + static MemorySegment longArrayToSlice(SegmentAllocator arena, long[] array) { + var len = array.length; + var memSeg = arena.allocate(JAVA_LONG, len); + for (var i = 0; i < len; i++) { + memSeg.setAtIndex(JAVA_LONG, i, array[i]); + } + return memSeg; + } + static MemorySegment floatArrayToSlice(SegmentAllocator arena, float[] array) { + var len = array.length; + var memSeg = arena.allocate(JAVA_FLOAT, len); + for (var i = 0; i < len; i++) { + memSeg.setAtIndex(JAVA_FLOAT, i, array[i]); + } + return memSeg; + } + + static MemorySegment doubleArrayToSlice(SegmentAllocator arena, double[] array) { + return arena.allocateFrom(JAVA_DOUBLE, array); + } + + static String readUtf8(MemorySegment segment) { + var data = DiplomatStringView.data(segment); + var len = DiplomatStringView.len(segment); + var strData = data.asSlice(0, len); + var bytes = strData.toArray(JAVA_BYTE); + var string = new String(bytes, StandardCharsets.UTF_8); + return string; + } + + static String readUtf16(MemorySegment segment) { + var data = DiplomatStringView.data(segment); + var len = DiplomatStringView.len(segment); + var strData = data.asSlice(0, len); + var bytes = strData.toArray(JAVA_BYTE); + var string = new String(bytes, StandardCharsets.UTF_16); + return string; + } + // for parameter conversion + static MemorySegment strToUtf8Slice(SegmentAllocator arena, String str) { + var vData = arena.allocateFrom(str, StandardCharsets.UTF_8); + var vLen = vData.byteSize() - 1; + var vView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(vView, vLen); + DiplomatStringView.data(vView, vData); + return vData; + } + + static MemorySegment strToUtf16Slice(SegmentAllocator arena, String str) { + var vData = arena.allocateFrom(str, StandardCharsets.UTF_16); + var vLen = vData.byteSize() - 1; + var vView = DiplomatStringView.allocate(arena); + DiplomatStringView.len(vView, vLen); + DiplomatStringView.data(vView, vData); + return vData; + } + static MemorySegment strs16(SegmentAllocator arena, String [] strings) { + var diplomatStrsData = DiplomatStringView.allocateArray(strings.length, arena); + var layout = DiplomatStringView.layout(); + diplomatStrsData.elements(layout).forEach(new Consumer() { + int i = 0; + @Override + public void accept(MemorySegment memorySegment) { + var str = strings[i]; + var bytes = str.getBytes(StandardCharsets.UTF_16); + var data = arena.allocateFrom(JAVA_BYTE, bytes); + DiplomatStringView.data(memorySegment, data); + DiplomatStringView.len(memorySegment, bytes.length); + i++; + } + }); + var diplomatStrsView = DiplomatStrings16View.allocate(arena); + DiplomatStrings16View.len(diplomatStrsView, strings.length); + DiplomatStrings16View.data(diplomatStrsView, diplomatStrsData); + return diplomatStrsView; + } + + static MemorySegment strs8(SegmentAllocator arena, String [] strings) { + var diplomatStrsData = DiplomatStringView.allocateArray(strings.length, arena); + var layout = DiplomatStringView.layout(); + diplomatStrsData.elements(layout).forEach(new Consumer() { + int i = 0; + @Override + public void accept(MemorySegment memorySegment) { + var str = strings[i]; + var bytes = str.getBytes(StandardCharsets.UTF_8); + var data = arena.allocateFrom(JAVA_BYTE, bytes); + DiplomatStringView.data(memorySegment, data); + DiplomatStringView.len(memorySegment, bytes.length); + i++; + } + }); + + var diplomatStrsView = DiplomatStringsView.allocate(arena); + DiplomatStringsView.len(diplomatStrsView, strings.length); + DiplomatStringsView.data(diplomatStrsView, diplomatStrsData); + return diplomatStrsView; + } + + static String readUtf8FromWriteable(MemorySegment writeable) { + var buffer = DiplomatWrite.buf(writeable); + var len = DiplomatWrite.len(writeable); + var bytes = new byte[(int) len]; + for (var i = 0; i < len; i++) { + bytes[i] = buffer.get(JAVA_BYTE, i); + } + return new String(bytes, StandardCharsets.UTF_8); + } +} \ No newline at end of file diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/MyEnum.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/MyEnum.java new file mode 100644 index 0000000..11c4296 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/MyEnum.java @@ -0,0 +1,82 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.somelib_h; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; + +public enum MyEnum { + A, + B, + C, + D, + E, + F, + ; + + static MyEnum fromInt(int i) { + switch (i) { + case -2 -> { + return MyEnum.A; + } + case -1 -> { + return MyEnum.B; + } + case 0 -> { + return MyEnum.C; + } + case 1 -> { + return MyEnum.D; + } + case 2 -> { + return MyEnum.E; + } + case 3 -> { + return MyEnum.F; + } + + } + throw new RuntimeException("Unexpected int for MyEnum:" + i); + } + + int toInt() { + switch (this) { + case A -> { + return -2; + } + case B -> { + return -1; + } + case C -> { + return 0; + } + case D -> { + return 1; + } + case E -> { + return 2; + } + case F -> { + return 3; + } + + } + throw new RuntimeException("Unexpected variant for MyEnum:" + this); + } + + + public static MyEnum getA() { + + var nativeVal = somelib_h.MyEnum_get_a(); + + var returnVal = MyEnum.fromInt(nativeVal); + return returnVal; + + } + +} diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/MyString.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/MyString.java new file mode 100644 index 0000000..48a73a6 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/MyString.java @@ -0,0 +1,142 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class MyString { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + + + static class MyStringCleaner implements Runnable { + + MemorySegment segment; + MyStringCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.MyString_destroy(this.segment); + } + } + + MyString() {} + MyString(MemorySegment handle, List selfEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + + + } + + public static MyString new_(String v) { + + try (var arena = Arena.ofConfined()) { + var vData= Arena.ofAuto().allocateFrom(v, StandardCharsets.UTF_8); + var vLen = vData.byteSize() - 1; // allocated strings are null terminated + var vView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(vView, vLen); + DiplomatStringView.data(vView, vData); + var nativeVal = somelib_h.MyString_new(vView); + + List selfEdges = List.of(); + + + + var returnVal = new MyString(nativeVal, selfEdges); + return returnVal; + + } + } + + public static MyString newUnsafe(String v) { + + try (var arena = Arena.ofConfined()) { + var vData= Arena.ofAuto().allocateFrom(v, StandardCharsets.UTF_8); + var vLen = vData.byteSize() - 1; // allocated strings are null terminated + var vView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(vView, vLen); + DiplomatStringView.data(vView, vData); + var nativeVal = somelib_h.MyString_new_unsafe(vView); + + List selfEdges = List.of(); + + + + var returnVal = new MyString(nativeVal, selfEdges); + return returnVal; + + } + } + + public static MyString newFromFirst(String [] v) { + + try (var arena = Arena.ofConfined()) { + var vView = SliceUtils.strs8(Arena.ofAuto(), v); + var vLen = v.length; + var nativeVal = somelib_h.MyString_new_from_first(vView); + + List selfEdges = List.of(); + + + + var returnVal = new MyString(nativeVal, selfEdges); + return returnVal; + + } + } + + public static String stringTransform(String foo) { + + try (var arena = Arena.ofConfined()) { + var fooData= Arena.ofAuto().allocateFrom(foo, StandardCharsets.UTF_8); + var fooLen = fooData.byteSize() - 1; // allocated strings are null terminated + var fooView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(fooView, fooLen); + DiplomatStringView.data(fooView, fooData); + var writeable = somelib_h.diplomat_buffer_write_create(0); + somelib_h.MyString_string_transform(fooView, writeable); + var string = SliceUtils. readUtf8FromWriteable(writeable); + somelib_h.diplomat_buffer_write_destroy(writeable); + return string; + } + } + + + public void setStr(String newStr) { + + try (var arena = Arena.ofConfined()) { + + var newStrData= Arena.ofAuto().allocateFrom(newStr, StandardCharsets.UTF_8); + var newStrLen = newStrData.byteSize() - 1; // allocated strings are null terminated + var newStrView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(newStrView, newStrLen); + DiplomatStringView.data(newStrView, newStrData); + somelib_h.MyString_set_str(internal, newStrView); + + } + } + + public String getStr() { + + + var writeable = somelib_h.diplomat_buffer_write_create(0); + somelib_h.MyString_get_str(internal, writeable); + var string = SliceUtils. readUtf8FromWriteable(writeable); + somelib_h.diplomat_buffer_write_destroy(writeable); + return string; + } + +} \ No newline at end of file diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/MyStruct.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/MyStruct.java new file mode 100644 index 0000000..756d05d --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/MyStruct.java @@ -0,0 +1,95 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class MyStruct { + byte a; + boolean b; + byte c; + long d; + int e; + int f; + MyEnum g; + + + List selfEdges = List.of(); + + + private MyStruct() { + } + + MyStruct(MemorySegment structSegment) { + this.selfEdges = selfEdges; + + + var aNative = dev.diplomattest.somelib.ntv.MyStruct.a(structSegment); + var aVal = aNative; + this.a = aVal; + var bNative = dev.diplomattest.somelib.ntv.MyStruct.b(structSegment); + var bVal = bNative; + this.b = bVal; + var cNative = dev.diplomattest.somelib.ntv.MyStruct.c(structSegment); + var cVal = cNative; + this.c = cVal; + var dNative = dev.diplomattest.somelib.ntv.MyStruct.d(structSegment); + var dVal = dNative; + this.d = dVal; + var eNative = dev.diplomattest.somelib.ntv.MyStruct.e(structSegment); + var eVal = eNative; + this.e = eVal; + var fNative = dev.diplomattest.somelib.ntv.MyStruct.f(structSegment); + var fVal = fNative; + this.f = fVal; + var gNative = dev.diplomattest.somelib.ntv.MyStruct.g(structSegment); + var gVal = MyEnum.fromInt(gNative); + this.g = gVal; + + + } + + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = dev.diplomattest.somelib.ntv.MyStruct.allocate(arena); + + var aNative = a; + dev.diplomattest.somelib.ntv.MyStruct.a(returnVal, aNative); + var bNative = b; + dev.diplomattest.somelib.ntv.MyStruct.b(returnVal, bNative); + var cNative = c; + dev.diplomattest.somelib.ntv.MyStruct.c(returnVal, cNative); + var dNative = d; + dev.diplomattest.somelib.ntv.MyStruct.d(returnVal, dNative); + var eNative = e; + dev.diplomattest.somelib.ntv.MyStruct.e(returnVal, eNative); + var fNative = f; + dev.diplomattest.somelib.ntv.MyStruct.f(returnVal, fNative); + var gNative = g.toInt(); + dev.diplomattest.somelib.ntv.MyStruct.g(returnVal, gNative); + + + return returnVal; + + } + + public static MyStruct new_() { + + try (var arena = Arena.ofConfined()) { + + var nativeVal = somelib_h.MyStruct_new(arena); + + var returnVal = new MyStruct(nativeVal); + return returnVal; + + } + } + +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/MyZst.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/MyZst.java new file mode 100644 index 0000000..e68eb57 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/MyZst.java @@ -0,0 +1,33 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class MyZst { + + + List selfEdges = List.of(); + + + private MyZst() { + } + + MyZst(MemorySegment structSegment) { + this.selfEdges = selfEdges; + + + + + } + + +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/NestedBorrowedFields.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/NestedBorrowedFields.java new file mode 100644 index 0000000..f6a9cb3 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/NestedBorrowedFields.java @@ -0,0 +1,99 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class NestedBorrowedFields { + BorrowedFields fields; + BorrowedFieldsWithBounds bounds; + BorrowedFieldsWithBounds bounds2; + + + List selfEdges = List.of(); + List xEdges = List.of(); + List yEdges = List.of(); + List zEdges = List.of(); + + + private NestedBorrowedFields() { + } + + NestedBorrowedFields(MemorySegment structSegment, List xEdges, List yEdges, List zEdges) { + this.selfEdges = selfEdges; + this.xEdges = xEdges; + this.yEdges = yEdges; + this.zEdges = zEdges; + + + var fieldsNative = dev.diplomattest.somelib.ntv.NestedBorrowedFields.fields(structSegment); + var fieldsVal = new BorrowedFields(fieldsNative, List.of(xEdges, yEdges)); + this.fields = fieldsVal; + var boundsNative = dev.diplomattest.somelib.ntv.NestedBorrowedFields.bounds(structSegment); + var boundsVal = new BorrowedFieldsWithBounds(boundsNative, List.of(xEdges, yEdges), List.of(), List.of()); + this.bounds = boundsVal; + var bounds2Native = dev.diplomattest.somelib.ntv.NestedBorrowedFields.bounds2(structSegment); + var bounds2Val = new BorrowedFieldsWithBounds(bounds2Native, List.of(), List.of(), List.of()); + this.bounds2 = bounds2Val; + + + } + + MemorySegment toNative(SegmentAllocator arena) { + var returnVal = dev.diplomattest.somelib.ntv.NestedBorrowedFields.allocate(arena); + + var fieldsNative = fields.toNative(arena); + dev.diplomattest.somelib.ntv.NestedBorrowedFields.fields(returnVal, fieldsNative); + var boundsNative = bounds.toNative(arena); + dev.diplomattest.somelib.ntv.NestedBorrowedFields.bounds(returnVal, boundsNative); + var bounds2Native = bounds2.toNative(arena); + dev.diplomattest.somelib.ntv.NestedBorrowedFields.bounds2(returnVal, bounds2Native); + + + return returnVal; + + } + + public static NestedBorrowedFields fromBarAndFooAndStrings(Bar bar,Foo foo,String dstr16X,String dstr16Z,String utf8StrY,String utf8StrZ) { + + try (var arena = Arena.ofConfined()) { + + var barNative = bar.internal; + var fooNative = foo.internal; + var dstr16XData = Arena.ofAuto().allocateFrom(dstr16X, StandardCharsets.UTF_16); + var dstr16XLen = dstr16XData.byteSize() - 1; // allocated strings are null terminated + var dstr16XView = DiplomatString16View.allocate(Arena.ofAuto()); + DiplomatString16View.len(dstr16XView, dstr16XLen); + DiplomatString16View.data(dstr16XView, dstr16XData); + var dstr16ZData = Arena.ofAuto().allocateFrom(dstr16Z, StandardCharsets.UTF_16); + var dstr16ZLen = dstr16ZData.byteSize() - 1; // allocated strings are null terminated + var dstr16ZView = DiplomatString16View.allocate(Arena.ofAuto()); + DiplomatString16View.len(dstr16ZView, dstr16ZLen); + DiplomatString16View.data(dstr16ZView, dstr16ZData); + var utf8StrYData= Arena.ofAuto().allocateFrom(utf8StrY, StandardCharsets.UTF_8); + var utf8StrYLen = utf8StrYData.byteSize() - 1; // allocated strings are null terminated + var utf8StrYView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(utf8StrYView, utf8StrYLen); + DiplomatStringView.data(utf8StrYView, utf8StrYData); + var utf8StrZData= Arena.ofAuto().allocateFrom(utf8StrZ, StandardCharsets.UTF_8); + var utf8StrZLen = utf8StrZData.byteSize() - 1; // allocated strings are null terminated + var utf8StrZView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(utf8StrZView, utf8StrZLen); + DiplomatStringView.data(utf8StrZView, utf8StrZData); + var nativeVal = somelib_h.NestedBorrowedFields_from_bar_and_foo_and_strings(arena, barNative, fooNative, dstr16XView, dstr16ZView, utf8StrYView, utf8StrZView); + + var returnVal = new NestedBorrowedFields(nativeVal, List.of(bar, dstr16X, utf8StrY), List.of(bar, utf8StrY), List.of(foo, dstr16Z, utf8StrZ)); + return returnVal; + + } + } + +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/One.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/One.java new file mode 100644 index 0000000..0e84f66 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/One.java @@ -0,0 +1,240 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class One { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + List aEdges = List.of(); + + + static class OneCleaner implements Runnable { + + MemorySegment segment; + OneCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.One_destroy(this.segment); + } + } + + One() {} + One(MemorySegment handle, List selfEdges, List aEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + this.aEdges = aEdges; + + + } + + public static One transitivity(One hold,One nohold) { + + var holdNative = hold.internal; + var noholdNative = nohold.internal; + var nativeVal = somelib_h.One_transitivity(holdNative, noholdNative); + + List selfEdges = List.of(); + + + + List aEdges = List.of(hold); + var returnVal = new One(nativeVal, selfEdges, aEdges); + return returnVal; + + } + + public static One cycle(Two hold,One nohold) { + + var holdNative = hold.internal; + var noholdNative = nohold.internal; + var nativeVal = somelib_h.One_cycle(holdNative, noholdNative); + + List selfEdges = List.of(); + + + + List aEdges = List.of(hold); + var returnVal = new One(nativeVal, selfEdges, aEdges); + return returnVal; + + } + + public static One manyDependents(One a,One b,Two c,Two d,Two nohold) { + + var aNative = a.internal; + var bNative = b.internal; + var cNative = c.internal; + var dNative = d.internal; + var noholdNative = nohold.internal; + var nativeVal = somelib_h.One_many_dependents(aNative, bNative, cNative, dNative, noholdNative); + + List selfEdges = List.of(); + + + + List aEdges = List.of(a, b, c, d); + var returnVal = new One(nativeVal, selfEdges, aEdges); + return returnVal; + + } + + public static One returnOutlivesParam(Two hold,One nohold) { + + var holdNative = hold.internal; + var noholdNative = nohold.internal; + var nativeVal = somelib_h.One_return_outlives_param(holdNative, noholdNative); + + List selfEdges = List.of(); + + + + List longEdges = List.of(hold); + var returnVal = new One(nativeVal, selfEdges, longEdges); + return returnVal; + + } + + public static One diamondTop(One top,One left,One right,One bottom) { + + var topNative = top.internal; + var leftNative = left.internal; + var rightNative = right.internal; + var bottomNative = bottom.internal; + var nativeVal = somelib_h.One_diamond_top(topNative, leftNative, rightNative, bottomNative); + + List selfEdges = List.of(); + + + + List topEdges = List.of(top, left, right, bottom); + var returnVal = new One(nativeVal, selfEdges, topEdges); + return returnVal; + + } + + public static One diamondLeft(One top,One left,One right,One bottom) { + + var topNative = top.internal; + var leftNative = left.internal; + var rightNative = right.internal; + var bottomNative = bottom.internal; + var nativeVal = somelib_h.One_diamond_left(topNative, leftNative, rightNative, bottomNative); + + List selfEdges = List.of(); + + + + List leftEdges = List.of(left, bottom); + var returnVal = new One(nativeVal, selfEdges, leftEdges); + return returnVal; + + } + + public static One diamondRight(One top,One left,One right,One bottom) { + + var topNative = top.internal; + var leftNative = left.internal; + var rightNative = right.internal; + var bottomNative = bottom.internal; + var nativeVal = somelib_h.One_diamond_right(topNative, leftNative, rightNative, bottomNative); + + List selfEdges = List.of(); + + + + List rightEdges = List.of(right, bottom); + var returnVal = new One(nativeVal, selfEdges, rightEdges); + return returnVal; + + } + + public static One diamondBottom(One top,One left,One right,One bottom) { + + var topNative = top.internal; + var leftNative = left.internal; + var rightNative = right.internal; + var bottomNative = bottom.internal; + var nativeVal = somelib_h.One_diamond_bottom(topNative, leftNative, rightNative, bottomNative); + + List selfEdges = List.of(); + + + + List bottomEdges = List.of(bottom); + var returnVal = new One(nativeVal, selfEdges, bottomEdges); + return returnVal; + + } + + public static One diamondAndNestedTypes(One a,One b,One c,One d,One nohold) { + + var aNative = a.internal; + var bNative = b.internal; + var cNative = c.internal; + var dNative = d.internal; + var noholdNative = nohold.internal; + var nativeVal = somelib_h.One_diamond_and_nested_types(aNative, bNative, cNative, dNative, noholdNative); + + List selfEdges = List.of(); + + + + List aEdges = List.of(a, b, c, d); + var returnVal = new One(nativeVal, selfEdges, aEdges); + return returnVal; + + } + + public static One implicitBounds(One explicitHold,One implicitHold,One nohold) { + + var explicitHoldNative = explicitHold.internal; + var implicitHoldNative = implicitHold.internal; + var noholdNative = nohold.internal; + var nativeVal = somelib_h.One_implicit_bounds(explicitHoldNative, implicitHoldNative, noholdNative); + + List selfEdges = List.of(); + + + + List aEdges = List.of(explicitHold, implicitHold); + var returnVal = new One(nativeVal, selfEdges, aEdges); + return returnVal; + + } + + public static One implicitBoundsDeep(One explicit,One implicit1,One implicit2,One nohold) { + + var explicitNative = explicit.internal; + var implicit1Native = implicit1.internal; + var implicit2Native = implicit2.internal; + var noholdNative = nohold.internal; + var nativeVal = somelib_h.One_implicit_bounds_deep(explicitNative, implicit1Native, implicit2Native, noholdNative); + + List selfEdges = List.of(); + + + + List aEdges = List.of(explicit, implicit1, implicit2); + var returnVal = new One(nativeVal, selfEdges, aEdges); + return returnVal; + + } + + +} \ No newline at end of file diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Opaque.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Opaque.java new file mode 100644 index 0000000..f5f4b0a --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Opaque.java @@ -0,0 +1,136 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class Opaque { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + + + static class OpaqueCleaner implements Runnable { + + MemorySegment segment; + OpaqueCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.Opaque_destroy(this.segment); + } + } + + Opaque() {} + Opaque(MemorySegment handle, List selfEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + + + } + + public static Opaque new_() { + + var nativeVal = somelib_h.Opaque_new(); + + List selfEdges = List.of(); + + + + var returnVal = new Opaque(nativeVal, selfEdges); + return returnVal; + + } + + public static Opaque fromStr(String input) { + + try (var arena = Arena.ofConfined()) { + var inputData= Arena.ofAuto().allocateFrom(input, StandardCharsets.UTF_8); + var inputLen = inputData.byteSize() - 1; // allocated strings are null terminated + var inputView = DiplomatStringView.allocate(Arena.ofAuto()); + DiplomatStringView.len(inputView, inputLen); + DiplomatStringView.data(inputView, inputData); + var nativeVal = somelib_h.Opaque_from_str(inputView); + + List selfEdges = List.of(); + + + + var returnVal = new Opaque(nativeVal, selfEdges); + return returnVal; + + } + } + + public static long returnsUsize() { + + var nativeVal = somelib_h.Opaque_returns_usize(); + + var returnVal = nativeVal; + return returnVal; + + } + + public static ImportedStruct returnsImported() { + + try (var arena = Arena.ofConfined()) { + + var nativeVal = somelib_h.Opaque_returns_imported(arena); + + var returnVal = new ImportedStruct(nativeVal); + return returnVal; + + } + } + + public static byte cmp() { + + var nativeVal = somelib_h.Opaque_cmp(); + + var returnVal = nativeVal; + return returnVal; + + } + + + public String getDebugStr() { + + + var writeable = somelib_h.diplomat_buffer_write_create(0); + somelib_h.Opaque_get_debug_str(internal, writeable); + var string = SliceUtils. readUtf8FromWriteable(writeable); + somelib_h.diplomat_buffer_write_destroy(writeable); + return string; + } + + public void assertStruct(MyStruct s) { + + + var sNative = s.toNative(Arena.ofAuto()); + somelib_h.Opaque_assert_struct(internal, sNative); + + } + + public long internalLen() { + + + var nativeVal = somelib_h.Opaque_internal_len(internal); + + var returnVal = nativeVal; + return returnVal; + + } + +} \ No newline at end of file diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/OpaqueMutexedString.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/OpaqueMutexedString.java new file mode 100644 index 0000000..3c13bbc --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/OpaqueMutexedString.java @@ -0,0 +1,148 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class OpaqueMutexedString { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + + + static class OpaqueMutexedStringCleaner implements Runnable { + + MemorySegment segment; + OpaqueMutexedStringCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.OpaqueMutexedString_destroy(this.segment); + } + } + + OpaqueMutexedString() {} + OpaqueMutexedString(MemorySegment handle, List selfEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + + + } + + public static OpaqueMutexedString fromUsize(long number) { + + var numberNative = number; + var nativeVal = somelib_h.OpaqueMutexedString_from_usize(numberNative); + + List selfEdges = List.of(); + + + + var returnVal = new OpaqueMutexedString(nativeVal, selfEdges); + return returnVal; + + } + + public static OpaqueMutexedString borrowOther(OpaqueMutexedString other) { + + var otherNative = other.internal; + var nativeVal = somelib_h.OpaqueMutexedString_borrow_other(otherNative); + + List selfEdges = List.of(other); + + + + var returnVal = new OpaqueMutexedString(nativeVal, selfEdges); + return returnVal; + + } + + + public void change(long number) { + + + var numberNative = number; + somelib_h.OpaqueMutexedString_change(internal, numberNative); + + } + + public OpaqueMutexedString borrow() { + + + var nativeVal = somelib_h.OpaqueMutexedString_borrow(internal); + + List selfEdges = List.of(this); + + + + var returnVal = new OpaqueMutexedString(nativeVal, selfEdges); + return returnVal; + + } + + public OpaqueMutexedString borrowSelfOrOther(OpaqueMutexedString other) { + + + var otherNative = other.internal; + var nativeVal = somelib_h.OpaqueMutexedString_borrow_self_or_other(internal, otherNative); + + List selfEdges = List.of(this, other); + + + + var returnVal = new OpaqueMutexedString(nativeVal, selfEdges); + return returnVal; + + } + + public long getLenAndAdd(long other) { + + + var otherNative = other; + var nativeVal = somelib_h.OpaqueMutexedString_get_len_and_add(internal, otherNative); + + var returnVal = nativeVal; + return returnVal; + + } + + public String dummyStr() { + + try (var arena = Arena.ofConfined()) { + + + var nativeVal = somelib_h.OpaqueMutexedString_dummy_str(arena, internal); + + var returnVal = SliceUtils.readUtf8(nativeVal); + return returnVal; + + } + } + + public Utf16Wrap wrapper() { + + + var nativeVal = somelib_h.OpaqueMutexedString_wrapper(internal); + + List selfEdges = List.of(); + + + + var returnVal = new Utf16Wrap(nativeVal, selfEdges); + return returnVal; + + } + +} \ No newline at end of file diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/RefList.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/RefList.java new file mode 100644 index 0000000..9a1864f --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/RefList.java @@ -0,0 +1,62 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class RefList { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + List aEdges = List.of(); + + + static class RefListCleaner implements Runnable { + + MemorySegment segment; + RefListCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.RefList_destroy(this.segment); + } + } + + RefList() {} + RefList(MemorySegment handle, List selfEdges, List aEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + this.aEdges = aEdges; + + + } + + public static RefList node(RefListParameter data) { + + var dataNative = data.internal; + var nativeVal = somelib_h.RefList_node(dataNative); + + List selfEdges = List.of(); + + + + List bEdges = List.of(data); + var returnVal = new RefList(nativeVal, selfEdges, bEdges); + return returnVal; + + } + + +} \ No newline at end of file diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/RefListParameter.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/RefListParameter.java new file mode 100644 index 0000000..ab41826 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/RefListParameter.java @@ -0,0 +1,45 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class RefListParameter { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + + + static class RefListParameterCleaner implements Runnable { + + MemorySegment segment; + RefListParameterCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.RefListParameter_destroy(this.segment); + } + } + + RefListParameter() {} + RefListParameter(MemorySegment handle, List selfEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + + + } + + +} \ No newline at end of file diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Two.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Two.java new file mode 100644 index 0000000..287eec4 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Two.java @@ -0,0 +1,49 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class Two { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + List aEdges = List.of(); + List bEdges = List.of(); + + + static class TwoCleaner implements Runnable { + + MemorySegment segment; + TwoCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.Two_destroy(this.segment); + } + } + + Two() {} + Two(MemorySegment handle, List selfEdges, List aEdges, List bEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + this.aEdges = aEdges; + this.bEdges = bEdges; + + + } + + +} \ No newline at end of file diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/UnimportedEnum.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/UnimportedEnum.java new file mode 100644 index 0000000..667a1ac --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/UnimportedEnum.java @@ -0,0 +1,52 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.somelib_h; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.ref.Cleaner; +import java.lang.foreign.SegmentAllocator; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; + +public enum UnimportedEnum { + A, + B, + C, + ; + + static UnimportedEnum fromInt(int i) { + switch (i) { + case 0 -> { + return UnimportedEnum.A; + } + case 1 -> { + return UnimportedEnum.B; + } + case 2 -> { + return UnimportedEnum.C; + } + + } + throw new RuntimeException("Unexpected int for UnimportedEnum:" + i); + } + + int toInt() { + switch (this) { + case A -> { + return 0; + } + case B -> { + return 1; + } + case C -> { + return 2; + } + + } + throw new RuntimeException("Unexpected variant for UnimportedEnum:" + this); + } + + +} diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Utf16Wrap.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Utf16Wrap.java new file mode 100644 index 0000000..b498c80 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/Utf16Wrap.java @@ -0,0 +1,88 @@ +package dev.diplomattest.somelib; + +import dev.diplomattest.somelib.ntv.*; + + +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.ref.Cleaner; +import java.util.List; +import static java.lang.foreign.ValueLayout.*; +import java.nio.charset.StandardCharsets; +import java.util.stream.Stream; + +public class Utf16Wrap { + + MemorySegment internal; + Cleaner.Cleanable cleanable; + SegmentAllocator arena; + + List selfEdges = List.of(); + + + static class Utf16WrapCleaner implements Runnable { + + MemorySegment segment; + Utf16WrapCleaner(MemorySegment segment) { + this.segment = segment; + } + + public void run() { + somelib_h.Utf16Wrap_destroy(this.segment); + } + } + + Utf16Wrap() {} + Utf16Wrap(MemorySegment handle, List selfEdges) { + this.internal = handle; + this.selfEdges = selfEdges; + + + } + + public static Utf16Wrap fromUtf16(String input) { + + try (var arena = Arena.ofConfined()) { + var inputData = Arena.ofAuto().allocateFrom(input, StandardCharsets.UTF_16); + var inputLen = inputData.byteSize() - 1; // allocated strings are null terminated + var inputView = DiplomatString16View.allocate(Arena.ofAuto()); + DiplomatString16View.len(inputView, inputLen); + DiplomatString16View.data(inputView, inputData); + var nativeVal = somelib_h.Utf16Wrap_from_utf16(inputView); + + List selfEdges = List.of(); + + + + var returnVal = new Utf16Wrap(nativeVal, selfEdges); + return returnVal; + + } + } + + + public String getDebugStr() { + + + var writeable = somelib_h.diplomat_buffer_write_create(0); + somelib_h.Utf16Wrap_get_debug_str(internal, writeable); + var string = SliceUtils. readUtf8FromWriteable(writeable); + somelib_h.diplomat_buffer_write_destroy(writeable); + return string; + } + + public String borrowCont() { + + try (var arena = Arena.ofConfined()) { + + + var nativeVal = somelib_h.Utf16Wrap_borrow_cont(arena, internal); + + var returnVal = SliceUtils.readUtf16(nativeVal); + return returnVal; + + } + } + +} \ No newline at end of file diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFields.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFields.java new file mode 100644 index 0000000..069d1f9 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFields.java @@ -0,0 +1,219 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct BorrowedFields { + * DiplomatString16View a; + * DiplomatStringView b; + * DiplomatStringView c; + * } + * } + */ +public class BorrowedFields { + + BorrowedFields() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + DiplomatString16View.layout().withName("a"), + DiplomatStringView.layout().withName("b"), + DiplomatStringView.layout().withName("c") + ).withName("BorrowedFields"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout a$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("a")); + + /** + * Layout for field: + * {@snippet lang=c : + * DiplomatString16View a + * } + */ + public static final GroupLayout a$layout() { + return a$LAYOUT; + } + + private static final long a$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * DiplomatString16View a + * } + */ + public static final long a$offset() { + return a$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * DiplomatString16View a + * } + */ + public static MemorySegment a(MemorySegment struct) { + return struct.asSlice(a$OFFSET, a$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * DiplomatString16View a + * } + */ + public static void a(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, a$OFFSET, a$LAYOUT.byteSize()); + } + + private static final GroupLayout b$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("b")); + + /** + * Layout for field: + * {@snippet lang=c : + * DiplomatStringView b + * } + */ + public static final GroupLayout b$layout() { + return b$LAYOUT; + } + + private static final long b$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * DiplomatStringView b + * } + */ + public static final long b$offset() { + return b$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * DiplomatStringView b + * } + */ + public static MemorySegment b(MemorySegment struct) { + return struct.asSlice(b$OFFSET, b$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * DiplomatStringView b + * } + */ + public static void b(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, b$OFFSET, b$LAYOUT.byteSize()); + } + + private static final GroupLayout c$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("c")); + + /** + * Layout for field: + * {@snippet lang=c : + * DiplomatStringView c + * } + */ + public static final GroupLayout c$layout() { + return c$LAYOUT; + } + + private static final long c$OFFSET = 32; + + /** + * Offset for field: + * {@snippet lang=c : + * DiplomatStringView c + * } + */ + public static final long c$offset() { + return c$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * DiplomatStringView c + * } + */ + public static MemorySegment c(MemorySegment struct) { + return struct.asSlice(c$OFFSET, c$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * DiplomatStringView c + * } + */ + public static void c(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, c$OFFSET, c$LAYOUT.byteSize()); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFieldsReturning.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFieldsReturning.java new file mode 100644 index 0000000..f6ea5f2 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFieldsReturning.java @@ -0,0 +1,127 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct BorrowedFieldsReturning { + * DiplomatStringView bytes; + * } + * } + */ +public class BorrowedFieldsReturning { + + BorrowedFieldsReturning() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + DiplomatStringView.layout().withName("bytes") + ).withName("BorrowedFieldsReturning"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout bytes$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("bytes")); + + /** + * Layout for field: + * {@snippet lang=c : + * DiplomatStringView bytes + * } + */ + public static final GroupLayout bytes$layout() { + return bytes$LAYOUT; + } + + private static final long bytes$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * DiplomatStringView bytes + * } + */ + public static final long bytes$offset() { + return bytes$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * DiplomatStringView bytes + * } + */ + public static MemorySegment bytes(MemorySegment struct) { + return struct.asSlice(bytes$OFFSET, bytes$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * DiplomatStringView bytes + * } + */ + public static void bytes(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, bytes$OFFSET, bytes$LAYOUT.byteSize()); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFieldsReturning_option.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFieldsReturning_option.java new file mode 100644 index 0000000..d58dc99 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFieldsReturning_option.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct BorrowedFieldsReturning_option { + * union { + * BorrowedFieldsReturning ok; + * }; + * bool is_ok; + * } + * } + */ +public class BorrowedFieldsReturning_option { + + BorrowedFieldsReturning_option() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + BorrowedFieldsReturning.layout().withName("ok") + ).withName("$anon$18:48"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(7) + ).withName("BorrowedFieldsReturning_option"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout ok$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$18:48"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * BorrowedFieldsReturning ok + * } + */ + public static final GroupLayout ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * BorrowedFieldsReturning ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * BorrowedFieldsReturning ok + * } + */ + public static MemorySegment ok(MemorySegment struct) { + return struct.asSlice(ok$OFFSET, ok$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * BorrowedFieldsReturning ok + * } + */ + public static void ok(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, ok$OFFSET, ok$LAYOUT.byteSize()); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFieldsWithBounds.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFieldsWithBounds.java new file mode 100644 index 0000000..ae8284f --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFieldsWithBounds.java @@ -0,0 +1,219 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct BorrowedFieldsWithBounds { + * DiplomatString16View field_a; + * DiplomatStringView field_b; + * DiplomatStringView field_c; + * } + * } + */ +public class BorrowedFieldsWithBounds { + + BorrowedFieldsWithBounds() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + DiplomatString16View.layout().withName("field_a"), + DiplomatStringView.layout().withName("field_b"), + DiplomatStringView.layout().withName("field_c") + ).withName("BorrowedFieldsWithBounds"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout field_a$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("field_a")); + + /** + * Layout for field: + * {@snippet lang=c : + * DiplomatString16View field_a + * } + */ + public static final GroupLayout field_a$layout() { + return field_a$LAYOUT; + } + + private static final long field_a$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * DiplomatString16View field_a + * } + */ + public static final long field_a$offset() { + return field_a$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * DiplomatString16View field_a + * } + */ + public static MemorySegment field_a(MemorySegment struct) { + return struct.asSlice(field_a$OFFSET, field_a$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * DiplomatString16View field_a + * } + */ + public static void field_a(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, field_a$OFFSET, field_a$LAYOUT.byteSize()); + } + + private static final GroupLayout field_b$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("field_b")); + + /** + * Layout for field: + * {@snippet lang=c : + * DiplomatStringView field_b + * } + */ + public static final GroupLayout field_b$layout() { + return field_b$LAYOUT; + } + + private static final long field_b$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * DiplomatStringView field_b + * } + */ + public static final long field_b$offset() { + return field_b$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * DiplomatStringView field_b + * } + */ + public static MemorySegment field_b(MemorySegment struct) { + return struct.asSlice(field_b$OFFSET, field_b$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * DiplomatStringView field_b + * } + */ + public static void field_b(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, field_b$OFFSET, field_b$LAYOUT.byteSize()); + } + + private static final GroupLayout field_c$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("field_c")); + + /** + * Layout for field: + * {@snippet lang=c : + * DiplomatStringView field_c + * } + */ + public static final GroupLayout field_c$layout() { + return field_c$LAYOUT; + } + + private static final long field_c$OFFSET = 32; + + /** + * Offset for field: + * {@snippet lang=c : + * DiplomatStringView field_c + * } + */ + public static final long field_c$offset() { + return field_c$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * DiplomatStringView field_c + * } + */ + public static MemorySegment field_c(MemorySegment struct) { + return struct.asSlice(field_c$OFFSET, field_c$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * DiplomatStringView field_c + * } + */ + public static void field_c(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, field_c$OFFSET, field_c$LAYOUT.byteSize()); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFieldsWithBounds_option.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFieldsWithBounds_option.java new file mode 100644 index 0000000..c48810c --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFieldsWithBounds_option.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct BorrowedFieldsWithBounds_option { + * union { + * BorrowedFieldsWithBounds ok; + * }; + * bool is_ok; + * } + * } + */ +public class BorrowedFieldsWithBounds_option { + + BorrowedFieldsWithBounds_option() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + BorrowedFieldsWithBounds.layout().withName("ok") + ).withName("$anon$20:49"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(7) + ).withName("BorrowedFieldsWithBounds_option"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout ok$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$20:49"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * BorrowedFieldsWithBounds ok + * } + */ + public static final GroupLayout ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * BorrowedFieldsWithBounds ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * BorrowedFieldsWithBounds ok + * } + */ + public static MemorySegment ok(MemorySegment struct) { + return struct.asSlice(ok$OFFSET, ok$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * BorrowedFieldsWithBounds ok + * } + */ + public static void ok(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, ok$OFFSET, ok$LAYOUT.byteSize()); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 48; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFields_option.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFields_option.java new file mode 100644 index 0000000..0ff95db --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/BorrowedFields_option.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct BorrowedFields_option { + * union { + * BorrowedFields ok; + * }; + * bool is_ok; + * } + * } + */ +public class BorrowedFields_option { + + BorrowedFields_option() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + BorrowedFields.layout().withName("ok") + ).withName("$anon$20:39"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(7) + ).withName("BorrowedFields_option"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout ok$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$20:39"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * BorrowedFields ok + * } + */ + public static final GroupLayout ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * BorrowedFields ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * BorrowedFields ok + * } + */ + public static MemorySegment ok(MemorySegment struct) { + return struct.asSlice(ok$OFFSET, ok$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * BorrowedFields ok + * } + */ + public static void ok(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, ok$OFFSET, ok$LAYOUT.byteSize()); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 48; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/ContiguousEnum_option.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/ContiguousEnum_option.java new file mode 100644 index 0000000..9a2a391 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/ContiguousEnum_option.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct ContiguousEnum_option { + * union { + * ContiguousEnum ok; + * }; + * bool is_ok; + * } + * } + */ +public class ContiguousEnum_option { + + ContiguousEnum_option() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_INT.withName("ok") + ).withName("$anon$21:39"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(3) + ).withName("ContiguousEnum_option"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt ok$LAYOUT = (OfInt)$LAYOUT.select(groupElement("$anon$21:39"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * ContiguousEnum ok + * } + */ + public static final OfInt ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * ContiguousEnum ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * ContiguousEnum ok + * } + */ + public static int ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * ContiguousEnum ok + * } + */ + public static void ok(MemorySegment struct, int fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/CyclicStructA.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/CyclicStructA.java new file mode 100644 index 0000000..ad7ef68 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/CyclicStructA.java @@ -0,0 +1,127 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct CyclicStructA { + * CyclicStructB a; + * } + * } + */ +public class CyclicStructA { + + CyclicStructA() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + CyclicStructB.layout().withName("a") + ).withName("CyclicStructA"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout a$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("a")); + + /** + * Layout for field: + * {@snippet lang=c : + * CyclicStructB a + * } + */ + public static final GroupLayout a$layout() { + return a$LAYOUT; + } + + private static final long a$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * CyclicStructB a + * } + */ + public static final long a$offset() { + return a$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * CyclicStructB a + * } + */ + public static MemorySegment a(MemorySegment struct) { + return struct.asSlice(a$OFFSET, a$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * CyclicStructB a + * } + */ + public static void a(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, a$OFFSET, a$LAYOUT.byteSize()); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/CyclicStructA_option.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/CyclicStructA_option.java new file mode 100644 index 0000000..7a58e5d --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/CyclicStructA_option.java @@ -0,0 +1,177 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct CyclicStructA_option { + * union { + * CyclicStructA ok; + * }; + * bool is_ok; + * } + * } + */ +public class CyclicStructA_option { + + CyclicStructA_option() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + CyclicStructA.layout().withName("ok") + ).withName("$anon$19:38"), + somelib_h.C_BOOL.withName("is_ok") + ).withName("CyclicStructA_option"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout ok$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$19:38"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * CyclicStructA ok + * } + */ + public static final GroupLayout ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * CyclicStructA ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * CyclicStructA ok + * } + */ + public static MemorySegment ok(MemorySegment struct) { + return struct.asSlice(ok$OFFSET, ok$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * CyclicStructA ok + * } + */ + public static void ok(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, ok$OFFSET, ok$LAYOUT.byteSize()); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/CyclicStructB.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/CyclicStructB.java new file mode 100644 index 0000000..62095d8 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/CyclicStructB.java @@ -0,0 +1,127 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct CyclicStructB { + * uint8_t field; + * } + * } + */ +public class CyclicStructB { + + CyclicStructB() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_CHAR.withName("field") + ).withName("CyclicStructB"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfByte field$LAYOUT = (OfByte)$LAYOUT.select(groupElement("field")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint8_t field + * } + */ + public static final OfByte field$layout() { + return field$LAYOUT; + } + + private static final long field$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * uint8_t field + * } + */ + public static final long field$offset() { + return field$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint8_t field + * } + */ + public static byte field(MemorySegment struct) { + return struct.get(field$LAYOUT, field$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint8_t field + * } + */ + public static void field(MemorySegment struct, byte fieldValue) { + struct.set(field$LAYOUT, field$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/CyclicStructB_option.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/CyclicStructB_option.java new file mode 100644 index 0000000..476c455 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/CyclicStructB_option.java @@ -0,0 +1,177 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct CyclicStructB_option { + * union { + * CyclicStructB ok; + * }; + * bool is_ok; + * } + * } + */ +public class CyclicStructB_option { + + CyclicStructB_option() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + CyclicStructB.layout().withName("ok") + ).withName("$anon$18:38"), + somelib_h.C_BOOL.withName("is_ok") + ).withName("CyclicStructB_option"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout ok$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$18:38"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * CyclicStructB ok + * } + */ + public static final GroupLayout ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * CyclicStructB ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * CyclicStructB ok + * } + */ + public static MemorySegment ok(MemorySegment struct) { + return struct.asSlice(ok$OFFSET, ok$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * CyclicStructB ok + * } + */ + public static void ok(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, ok$OFFSET, ok$LAYOUT.byteSize()); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatBoolArray.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatBoolArray.java new file mode 100644 index 0000000..b4d3357 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatBoolArray.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatBoolArray { + * const bool *data; + * size_t len; + * } + * } + */ +public class DiplomatBoolArray { + + DiplomatBoolArray() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatBoolArray"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const bool *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const bool *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const bool *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const bool *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatBoolView.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatBoolView.java new file mode 100644 index 0000000..f72f81b --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatBoolView.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatBoolView { + * const bool *data; + * size_t len; + * } + * } + */ +public class DiplomatBoolView { + + DiplomatBoolView() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatBoolView"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const bool *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const bool *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const bool *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const bool *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatBoolViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatBoolViewMut.java new file mode 100644 index 0000000..08bf3f4 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatBoolViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatBoolViewMut { + * bool *data; + * size_t len; + * } + * } + */ +public class DiplomatBoolViewMut { + + DiplomatBoolViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatBoolViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * bool *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatCharArray.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatCharArray.java new file mode 100644 index 0000000..ad43f41 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatCharArray.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatCharArray { + * const char32_t *data; + * size_t len; + * } + * } + */ +public class DiplomatCharArray { + + DiplomatCharArray() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatCharArray"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const char32_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const char32_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const char32_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const char32_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatCharView.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatCharView.java new file mode 100644 index 0000000..6dc3f0e --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatCharView.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatCharView { + * const char32_t *data; + * size_t len; + * } + * } + */ +public class DiplomatCharView { + + DiplomatCharView() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatCharView"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const char32_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const char32_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const char32_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const char32_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatCharViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatCharViewMut.java new file mode 100644 index 0000000..a147ed6 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatCharViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatCharViewMut { + * char32_t *data; + * size_t len; + * } + * } + */ +public class DiplomatCharViewMut { + + DiplomatCharViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatCharViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * char32_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * char32_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * char32_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * char32_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF32Array.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF32Array.java new file mode 100644 index 0000000..3483f69 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF32Array.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatF32Array { + * const float *data; + * size_t len; + * } + * } + */ +public class DiplomatF32Array { + + DiplomatF32Array() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatF32Array"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const float *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const float *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const float *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const float *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF32View.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF32View.java new file mode 100644 index 0000000..ef9439b --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF32View.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatF32View { + * const float *data; + * size_t len; + * } + * } + */ +public class DiplomatF32View { + + DiplomatF32View() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatF32View"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const float *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const float *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const float *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const float *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF32ViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF32ViewMut.java new file mode 100644 index 0000000..2c1ff7f --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF32ViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatF32ViewMut { + * float *data; + * size_t len; + * } + * } + */ +public class DiplomatF32ViewMut { + + DiplomatF32ViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatF32ViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * float *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * float *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * float *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * float *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF64Array.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF64Array.java new file mode 100644 index 0000000..f31fa2f --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF64Array.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatF64Array { + * const double *data; + * size_t len; + * } + * } + */ +public class DiplomatF64Array { + + DiplomatF64Array() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatF64Array"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const double *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const double *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const double *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const double *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF64View.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF64View.java new file mode 100644 index 0000000..d196096 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF64View.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatF64View { + * const double *data; + * size_t len; + * } + * } + */ +public class DiplomatF64View { + + DiplomatF64View() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatF64View"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const double *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const double *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const double *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const double *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF64ViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF64ViewMut.java new file mode 100644 index 0000000..b76f35e --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatF64ViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatF64ViewMut { + * double *data; + * size_t len; + * } + * } + */ +public class DiplomatF64ViewMut { + + DiplomatF64ViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatF64ViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * double *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * double *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * double *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * double *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI16Array.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI16Array.java new file mode 100644 index 0000000..08f0493 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI16Array.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatI16Array { + * const int16_t *data; + * size_t len; + * } + * } + */ +public class DiplomatI16Array { + + DiplomatI16Array() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatI16Array"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const int16_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const int16_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const int16_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const int16_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI16View.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI16View.java new file mode 100644 index 0000000..265552c --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI16View.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatI16View { + * const int16_t *data; + * size_t len; + * } + * } + */ +public class DiplomatI16View { + + DiplomatI16View() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatI16View"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const int16_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const int16_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const int16_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const int16_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI16ViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI16ViewMut.java new file mode 100644 index 0000000..54fefcc --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI16ViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatI16ViewMut { + * int16_t *data; + * size_t len; + * } + * } + */ +public class DiplomatI16ViewMut { + + DiplomatI16ViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatI16ViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * int16_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * int16_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * int16_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * int16_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI32Array.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI32Array.java new file mode 100644 index 0000000..a33abc5 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI32Array.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatI32Array { + * const int32_t *data; + * size_t len; + * } + * } + */ +public class DiplomatI32Array { + + DiplomatI32Array() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatI32Array"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const int32_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const int32_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const int32_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const int32_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI32View.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI32View.java new file mode 100644 index 0000000..d5c0eff --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI32View.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatI32View { + * const int32_t *data; + * size_t len; + * } + * } + */ +public class DiplomatI32View { + + DiplomatI32View() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatI32View"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const int32_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const int32_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const int32_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const int32_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI32ViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI32ViewMut.java new file mode 100644 index 0000000..ee22a4c --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI32ViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatI32ViewMut { + * int32_t *data; + * size_t len; + * } + * } + */ +public class DiplomatI32ViewMut { + + DiplomatI32ViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatI32ViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * int32_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * int32_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * int32_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * int32_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI64Array.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI64Array.java new file mode 100644 index 0000000..db76036 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI64Array.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatI64Array { + * const int64_t *data; + * size_t len; + * } + * } + */ +public class DiplomatI64Array { + + DiplomatI64Array() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatI64Array"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const int64_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const int64_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const int64_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const int64_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI64View.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI64View.java new file mode 100644 index 0000000..2ae01c5 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI64View.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatI64View { + * const int64_t *data; + * size_t len; + * } + * } + */ +public class DiplomatI64View { + + DiplomatI64View() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatI64View"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const int64_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const int64_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const int64_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const int64_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI64ViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI64ViewMut.java new file mode 100644 index 0000000..44ffdab --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI64ViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatI64ViewMut { + * int64_t *data; + * size_t len; + * } + * } + */ +public class DiplomatI64ViewMut { + + DiplomatI64ViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatI64ViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * int64_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * int64_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * int64_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * int64_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI8Array.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI8Array.java new file mode 100644 index 0000000..cea362b --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI8Array.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatI8Array { + * const int8_t *data; + * size_t len; + * } + * } + */ +public class DiplomatI8Array { + + DiplomatI8Array() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatI8Array"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const int8_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const int8_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const int8_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const int8_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI8View.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI8View.java new file mode 100644 index 0000000..c8240e1 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI8View.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatI8View { + * const int8_t *data; + * size_t len; + * } + * } + */ +public class DiplomatI8View { + + DiplomatI8View() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatI8View"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const int8_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const int8_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const int8_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const int8_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI8ViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI8ViewMut.java new file mode 100644 index 0000000..3f93021 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatI8ViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatI8ViewMut { + * int8_t *data; + * size_t len; + * } + * } + */ +public class DiplomatI8ViewMut { + + DiplomatI8ViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatI8ViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * int8_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * int8_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * int8_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * int8_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatIsizeArray.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatIsizeArray.java new file mode 100644 index 0000000..4e4b5a2 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatIsizeArray.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatIsizeArray { + * const intptr_t *data; + * size_t len; + * } + * } + */ +public class DiplomatIsizeArray { + + DiplomatIsizeArray() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatIsizeArray"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const intptr_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const intptr_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const intptr_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const intptr_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatIsizeView.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatIsizeView.java new file mode 100644 index 0000000..953f1aa --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatIsizeView.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatIsizeView { + * const intptr_t *data; + * size_t len; + * } + * } + */ +public class DiplomatIsizeView { + + DiplomatIsizeView() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatIsizeView"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const intptr_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const intptr_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const intptr_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const intptr_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatIsizeViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatIsizeViewMut.java new file mode 100644 index 0000000..baa2ddd --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatIsizeViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatIsizeViewMut { + * intptr_t *data; + * size_t len; + * } + * } + */ +public class DiplomatIsizeViewMut { + + DiplomatIsizeViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatIsizeViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * intptr_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * intptr_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * intptr_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * intptr_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatString16Array.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatString16Array.java new file mode 100644 index 0000000..d69cc5c --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatString16Array.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatString16Array { + * const char16_t *data; + * size_t len; + * } + * } + */ +public class DiplomatString16Array { + + DiplomatString16Array() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatString16Array"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const char16_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const char16_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const char16_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const char16_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatString16View.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatString16View.java new file mode 100644 index 0000000..192de99 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatString16View.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatString16View { + * const char16_t *data; + * size_t len; + * } + * } + */ +public class DiplomatString16View { + + DiplomatString16View() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatString16View"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const char16_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const char16_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const char16_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const char16_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatString16ViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatString16ViewMut.java new file mode 100644 index 0000000..c2da631 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatString16ViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatString16ViewMut { + * char16_t *data; + * size_t len; + * } + * } + */ +public class DiplomatString16ViewMut { + + DiplomatString16ViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatString16ViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * char16_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * char16_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * char16_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * char16_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringArray.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringArray.java new file mode 100644 index 0000000..d7aa9f6 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringArray.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatStringArray { + * const char *data; + * size_t len; + * } + * } + */ +public class DiplomatStringArray { + + DiplomatStringArray() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatStringArray"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const char *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const char *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const char *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const char *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringView.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringView.java new file mode 100644 index 0000000..185d5af --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringView.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatStringView { + * const char *data; + * size_t len; + * } + * } + */ +public class DiplomatStringView { + + DiplomatStringView() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatStringView"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const char *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const char *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const char *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const char *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringViewMut.java new file mode 100644 index 0000000..676f124 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatStringViewMut { + * char *data; + * size_t len; + * } + * } + */ +public class DiplomatStringViewMut { + + DiplomatStringViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatStringViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * char *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * char *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * char *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * char *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStrings16Array.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStrings16Array.java new file mode 100644 index 0000000..b2c9354 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStrings16Array.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatStrings16Array { + * const DiplomatString16View *data; + * size_t len; + * } + * } + */ +public class DiplomatStrings16Array { + + DiplomatStrings16Array() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatStrings16Array"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const DiplomatString16View *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const DiplomatString16View *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const DiplomatString16View *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const DiplomatString16View *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStrings16View.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStrings16View.java new file mode 100644 index 0000000..3e10bbe --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStrings16View.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatStrings16View { + * const DiplomatString16View *data; + * size_t len; + * } + * } + */ +public class DiplomatStrings16View { + + DiplomatStrings16View() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatStrings16View"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const DiplomatString16View *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const DiplomatString16View *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const DiplomatString16View *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const DiplomatString16View *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStrings16ViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStrings16ViewMut.java new file mode 100644 index 0000000..bf9559f --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStrings16ViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatStrings16ViewMut { + * DiplomatString16View *data; + * size_t len; + * } + * } + */ +public class DiplomatStrings16ViewMut { + + DiplomatStrings16ViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatStrings16ViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * DiplomatString16View *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * DiplomatString16View *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * DiplomatString16View *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * DiplomatString16View *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringsArray.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringsArray.java new file mode 100644 index 0000000..bef36d3 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringsArray.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatStringsArray { + * const DiplomatStringView *data; + * size_t len; + * } + * } + */ +public class DiplomatStringsArray { + + DiplomatStringsArray() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatStringsArray"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const DiplomatStringView *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const DiplomatStringView *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const DiplomatStringView *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const DiplomatStringView *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringsView.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringsView.java new file mode 100644 index 0000000..9e16e26 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringsView.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatStringsView { + * const DiplomatStringView *data; + * size_t len; + * } + * } + */ +public class DiplomatStringsView { + + DiplomatStringsView() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatStringsView"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const DiplomatStringView *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const DiplomatStringView *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const DiplomatStringView *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const DiplomatStringView *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringsViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringsViewMut.java new file mode 100644 index 0000000..df60856 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatStringsViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatStringsViewMut { + * DiplomatStringView *data; + * size_t len; + * } + * } + */ +public class DiplomatStringsViewMut { + + DiplomatStringsViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatStringsViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * DiplomatStringView *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * DiplomatStringView *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * DiplomatStringView *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * DiplomatStringView *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU16Array.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU16Array.java new file mode 100644 index 0000000..482eea7 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU16Array.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatU16Array { + * const uint16_t *data; + * size_t len; + * } + * } + */ +public class DiplomatU16Array { + + DiplomatU16Array() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatU16Array"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const uint16_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const uint16_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const uint16_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const uint16_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU16View.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU16View.java new file mode 100644 index 0000000..a8c75ea --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU16View.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatU16View { + * const uint16_t *data; + * size_t len; + * } + * } + */ +public class DiplomatU16View { + + DiplomatU16View() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatU16View"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const uint16_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const uint16_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const uint16_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const uint16_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU16ViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU16ViewMut.java new file mode 100644 index 0000000..f4c4051 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU16ViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatU16ViewMut { + * uint16_t *data; + * size_t len; + * } + * } + */ +public class DiplomatU16ViewMut { + + DiplomatU16ViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatU16ViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint16_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * uint16_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint16_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint16_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU32Array.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU32Array.java new file mode 100644 index 0000000..8ecc93d --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU32Array.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatU32Array { + * const uint32_t *data; + * size_t len; + * } + * } + */ +public class DiplomatU32Array { + + DiplomatU32Array() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatU32Array"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const uint32_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const uint32_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const uint32_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const uint32_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU32View.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU32View.java new file mode 100644 index 0000000..5b0e57b --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU32View.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatU32View { + * const uint32_t *data; + * size_t len; + * } + * } + */ +public class DiplomatU32View { + + DiplomatU32View() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatU32View"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const uint32_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const uint32_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const uint32_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const uint32_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU32ViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU32ViewMut.java new file mode 100644 index 0000000..e516c6b --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU32ViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatU32ViewMut { + * uint32_t *data; + * size_t len; + * } + * } + */ +public class DiplomatU32ViewMut { + + DiplomatU32ViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatU32ViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint32_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * uint32_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint32_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint32_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU64Array.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU64Array.java new file mode 100644 index 0000000..5b407a9 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU64Array.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatU64Array { + * const uint64_t *data; + * size_t len; + * } + * } + */ +public class DiplomatU64Array { + + DiplomatU64Array() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatU64Array"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const uint64_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const uint64_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const uint64_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const uint64_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU64View.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU64View.java new file mode 100644 index 0000000..2ec76ae --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU64View.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatU64View { + * const uint64_t *data; + * size_t len; + * } + * } + */ +public class DiplomatU64View { + + DiplomatU64View() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatU64View"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const uint64_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const uint64_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const uint64_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const uint64_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU64ViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU64ViewMut.java new file mode 100644 index 0000000..7e0d0b0 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU64ViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatU64ViewMut { + * uint64_t *data; + * size_t len; + * } + * } + */ +public class DiplomatU64ViewMut { + + DiplomatU64ViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatU64ViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint64_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * uint64_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint64_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint64_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU8Array.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU8Array.java new file mode 100644 index 0000000..66872b9 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU8Array.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatU8Array { + * const uint8_t *data; + * size_t len; + * } + * } + */ +public class DiplomatU8Array { + + DiplomatU8Array() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatU8Array"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const uint8_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const uint8_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const uint8_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const uint8_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU8View.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU8View.java new file mode 100644 index 0000000..3c66711 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU8View.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatU8View { + * const uint8_t *data; + * size_t len; + * } + * } + */ +public class DiplomatU8View { + + DiplomatU8View() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatU8View"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const uint8_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const uint8_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const uint8_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const uint8_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU8ViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU8ViewMut.java new file mode 100644 index 0000000..f04cc0c --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatU8ViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatU8ViewMut { + * uint8_t *data; + * size_t len; + * } + * } + */ +public class DiplomatU8ViewMut { + + DiplomatU8ViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatU8ViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint8_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * uint8_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint8_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint8_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatUsizeArray.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatUsizeArray.java new file mode 100644 index 0000000..21b119c --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatUsizeArray.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatUsizeArray { + * const size_t *data; + * size_t len; + * } + * } + */ +public class DiplomatUsizeArray { + + DiplomatUsizeArray() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatUsizeArray"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const size_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const size_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const size_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const size_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatUsizeView.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatUsizeView.java new file mode 100644 index 0000000..ba9b410 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatUsizeView.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatUsizeView { + * const size_t *data; + * size_t len; + * } + * } + */ +public class DiplomatUsizeView { + + DiplomatUsizeView() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatUsizeView"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * const size_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * const size_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * const size_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * const size_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatUsizeViewMut.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatUsizeViewMut.java new file mode 100644 index 0000000..99c1929 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatUsizeViewMut.java @@ -0,0 +1,173 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatUsizeViewMut { + * size_t *data; + * size_t len; + * } + * } + */ +public class DiplomatUsizeViewMut { + + DiplomatUsizeViewMut() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("data"), + somelib_h.C_LONG.withName("len") + ).withName("DiplomatUsizeViewMut"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout data$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("data")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t *data + * } + */ + public static final AddressLayout data$layout() { + return data$LAYOUT; + } + + private static final long data$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t *data + * } + */ + public static final long data$offset() { + return data$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t *data + * } + */ + public static MemorySegment data(MemorySegment struct) { + return struct.get(data$LAYOUT, data$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t *data + * } + */ + public static void data(MemorySegment struct, MemorySegment fieldValue) { + struct.set(data$LAYOUT, data$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatWrite.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatWrite.java new file mode 100644 index 0000000..6da2825 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/DiplomatWrite.java @@ -0,0 +1,512 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct DiplomatWrite { + * void *context; + * char *buf; + * size_t len; + * size_t cap; + * bool grow_failed; + * void (*flush)(struct DiplomatWrite *); + * bool (*grow)(struct DiplomatWrite *, size_t); + * } + * } + */ +public class DiplomatWrite { + + DiplomatWrite() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_POINTER.withName("context"), + somelib_h.C_POINTER.withName("buf"), + somelib_h.C_LONG.withName("len"), + somelib_h.C_LONG.withName("cap"), + somelib_h.C_BOOL.withName("grow_failed"), + MemoryLayout.paddingLayout(7), + somelib_h.C_POINTER.withName("flush"), + somelib_h.C_POINTER.withName("grow") + ).withName("DiplomatWrite"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final AddressLayout context$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("context")); + + /** + * Layout for field: + * {@snippet lang=c : + * void *context + * } + */ + public static final AddressLayout context$layout() { + return context$LAYOUT; + } + + private static final long context$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * void *context + * } + */ + public static final long context$offset() { + return context$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * void *context + * } + */ + public static MemorySegment context(MemorySegment struct) { + return struct.get(context$LAYOUT, context$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * void *context + * } + */ + public static void context(MemorySegment struct, MemorySegment fieldValue) { + struct.set(context$LAYOUT, context$OFFSET, fieldValue); + } + + private static final AddressLayout buf$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("buf")); + + /** + * Layout for field: + * {@snippet lang=c : + * char *buf + * } + */ + public static final AddressLayout buf$layout() { + return buf$LAYOUT; + } + + private static final long buf$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * char *buf + * } + */ + public static final long buf$offset() { + return buf$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * char *buf + * } + */ + public static MemorySegment buf(MemorySegment struct) { + return struct.get(buf$LAYOUT, buf$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * char *buf + * } + */ + public static void buf(MemorySegment struct, MemorySegment fieldValue) { + struct.set(buf$LAYOUT, buf$OFFSET, fieldValue); + } + + private static final OfLong len$LAYOUT = (OfLong)$LAYOUT.select(groupElement("len")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final OfLong len$layout() { + return len$LAYOUT; + } + + private static final long len$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static final long len$offset() { + return len$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static long len(MemorySegment struct) { + return struct.get(len$LAYOUT, len$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t len + * } + */ + public static void len(MemorySegment struct, long fieldValue) { + struct.set(len$LAYOUT, len$OFFSET, fieldValue); + } + + private static final OfLong cap$LAYOUT = (OfLong)$LAYOUT.select(groupElement("cap")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t cap + * } + */ + public static final OfLong cap$layout() { + return cap$LAYOUT; + } + + private static final long cap$OFFSET = 24; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t cap + * } + */ + public static final long cap$offset() { + return cap$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t cap + * } + */ + public static long cap(MemorySegment struct) { + return struct.get(cap$LAYOUT, cap$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t cap + * } + */ + public static void cap(MemorySegment struct, long fieldValue) { + struct.set(cap$LAYOUT, cap$OFFSET, fieldValue); + } + + private static final OfBoolean grow_failed$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("grow_failed")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool grow_failed + * } + */ + public static final OfBoolean grow_failed$layout() { + return grow_failed$LAYOUT; + } + + private static final long grow_failed$OFFSET = 32; + + /** + * Offset for field: + * {@snippet lang=c : + * bool grow_failed + * } + */ + public static final long grow_failed$offset() { + return grow_failed$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool grow_failed + * } + */ + public static boolean grow_failed(MemorySegment struct) { + return struct.get(grow_failed$LAYOUT, grow_failed$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool grow_failed + * } + */ + public static void grow_failed(MemorySegment struct, boolean fieldValue) { + struct.set(grow_failed$LAYOUT, grow_failed$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * void (*flush)(struct DiplomatWrite *) + * } + */ + public static class flush { + + flush() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + void apply(MemorySegment _x0); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = somelib_h.upcallHandle(flush.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(flush.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static void invoke(MemorySegment funcPtr,MemorySegment _x0) { + try { + DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout flush$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("flush")); + + /** + * Layout for field: + * {@snippet lang=c : + * void (*flush)(struct DiplomatWrite *) + * } + */ + public static final AddressLayout flush$layout() { + return flush$LAYOUT; + } + + private static final long flush$OFFSET = 40; + + /** + * Offset for field: + * {@snippet lang=c : + * void (*flush)(struct DiplomatWrite *) + * } + */ + public static final long flush$offset() { + return flush$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * void (*flush)(struct DiplomatWrite *) + * } + */ + public static MemorySegment flush(MemorySegment struct) { + return struct.get(flush$LAYOUT, flush$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * void (*flush)(struct DiplomatWrite *) + * } + */ + public static void flush(MemorySegment struct, MemorySegment fieldValue) { + struct.set(flush$LAYOUT, flush$OFFSET, fieldValue); + } + + /** + * {@snippet lang=c : + * bool (*grow)(struct DiplomatWrite *, size_t) + * } + */ + public static class grow { + + grow() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + boolean apply(MemorySegment _x0, long _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + somelib_h.C_BOOL, + somelib_h.C_POINTER, + somelib_h.C_LONG + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = somelib_h.upcallHandle(grow.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(grow.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static boolean invoke(MemorySegment funcPtr,MemorySegment _x0, long _x1) { + try { + return (boolean) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout grow$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("grow")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool (*grow)(struct DiplomatWrite *, size_t) + * } + */ + public static final AddressLayout grow$layout() { + return grow$LAYOUT; + } + + private static final long grow$OFFSET = 48; + + /** + * Offset for field: + * {@snippet lang=c : + * bool (*grow)(struct DiplomatWrite *, size_t) + * } + */ + public static final long grow$offset() { + return grow$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool (*grow)(struct DiplomatWrite *, size_t) + * } + */ + public static MemorySegment grow(MemorySegment struct) { + return struct.get(grow$LAYOUT, grow$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool (*grow)(struct DiplomatWrite *, size_t) + * } + */ + public static void grow(MemorySegment struct, MemorySegment fieldValue) { + struct.set(grow$LAYOUT, grow$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/ImportedStruct.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/ImportedStruct.java new file mode 100644 index 0000000..0ef6656 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/ImportedStruct.java @@ -0,0 +1,174 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct ImportedStruct { + * UnimportedEnum foo; + * uint8_t count; + * } + * } + */ +public class ImportedStruct { + + ImportedStruct() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_INT.withName("foo"), + somelib_h.C_CHAR.withName("count"), + MemoryLayout.paddingLayout(3) + ).withName("ImportedStruct"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt foo$LAYOUT = (OfInt)$LAYOUT.select(groupElement("foo")); + + /** + * Layout for field: + * {@snippet lang=c : + * UnimportedEnum foo + * } + */ + public static final OfInt foo$layout() { + return foo$LAYOUT; + } + + private static final long foo$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * UnimportedEnum foo + * } + */ + public static final long foo$offset() { + return foo$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UnimportedEnum foo + * } + */ + public static int foo(MemorySegment struct) { + return struct.get(foo$LAYOUT, foo$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UnimportedEnum foo + * } + */ + public static void foo(MemorySegment struct, int fieldValue) { + struct.set(foo$LAYOUT, foo$OFFSET, fieldValue); + } + + private static final OfByte count$LAYOUT = (OfByte)$LAYOUT.select(groupElement("count")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint8_t count + * } + */ + public static final OfByte count$layout() { + return count$LAYOUT; + } + + private static final long count$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * uint8_t count + * } + */ + public static final long count$offset() { + return count$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint8_t count + * } + */ + public static byte count(MemorySegment struct) { + return struct.get(count$LAYOUT, count$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint8_t count + * } + */ + public static void count(MemorySegment struct, byte fieldValue) { + struct.set(count$LAYOUT, count$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/ImportedStruct_option.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/ImportedStruct_option.java new file mode 100644 index 0000000..37243ec --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/ImportedStruct_option.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct ImportedStruct_option { + * union { + * ImportedStruct ok; + * }; + * bool is_ok; + * } + * } + */ +public class ImportedStruct_option { + + ImportedStruct_option() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + ImportedStruct.layout().withName("ok") + ).withName("$anon$20:39"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(3) + ).withName("ImportedStruct_option"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout ok$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$20:39"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * ImportedStruct ok + * } + */ + public static final GroupLayout ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * ImportedStruct ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * ImportedStruct ok + * } + */ + public static MemorySegment ok(MemorySegment struct) { + return struct.asSlice(ok$OFFSET, ok$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * ImportedStruct ok + * } + */ + public static void ok(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, ok$OFFSET, ok$LAYOUT.byteSize()); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/MyEnum_option.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/MyEnum_option.java new file mode 100644 index 0000000..69c0811 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/MyEnum_option.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct MyEnum_option { + * union { + * MyEnum ok; + * }; + * bool is_ok; + * } + * } + */ +public class MyEnum_option { + + MyEnum_option() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_INT.withName("ok") + ).withName("$anon$23:31"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(3) + ).withName("MyEnum_option"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt ok$LAYOUT = (OfInt)$LAYOUT.select(groupElement("$anon$23:31"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * MyEnum ok + * } + */ + public static final OfInt ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * MyEnum ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * MyEnum ok + * } + */ + public static int ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * MyEnum ok + * } + */ + public static void ok(MemorySegment struct, int fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/MyStruct.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/MyStruct.java new file mode 100644 index 0000000..4cd6b64 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/MyStruct.java @@ -0,0 +1,405 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct MyStruct { + * uint8_t a; + * bool b; + * uint8_t c; + * uint64_t d; + * int32_t e; + * char32_t f; + * MyEnum g; + * } + * } + */ +public class MyStruct { + + MyStruct() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + somelib_h.C_CHAR.withName("a"), + somelib_h.C_BOOL.withName("b"), + somelib_h.C_CHAR.withName("c"), + MemoryLayout.paddingLayout(5), + somelib_h.C_LONG_LONG.withName("d"), + somelib_h.C_INT.withName("e"), + somelib_h.C_INT.withName("f"), + somelib_h.C_INT.withName("g"), + MemoryLayout.paddingLayout(4) + ).withName("MyStruct"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfByte a$LAYOUT = (OfByte)$LAYOUT.select(groupElement("a")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint8_t a + * } + */ + public static final OfByte a$layout() { + return a$LAYOUT; + } + + private static final long a$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * uint8_t a + * } + */ + public static final long a$offset() { + return a$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint8_t a + * } + */ + public static byte a(MemorySegment struct) { + return struct.get(a$LAYOUT, a$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint8_t a + * } + */ + public static void a(MemorySegment struct, byte fieldValue) { + struct.set(a$LAYOUT, a$OFFSET, fieldValue); + } + + private static final OfBoolean b$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("b")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool b + * } + */ + public static final OfBoolean b$layout() { + return b$LAYOUT; + } + + private static final long b$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * bool b + * } + */ + public static final long b$offset() { + return b$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool b + * } + */ + public static boolean b(MemorySegment struct) { + return struct.get(b$LAYOUT, b$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool b + * } + */ + public static void b(MemorySegment struct, boolean fieldValue) { + struct.set(b$LAYOUT, b$OFFSET, fieldValue); + } + + private static final OfByte c$LAYOUT = (OfByte)$LAYOUT.select(groupElement("c")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint8_t c + * } + */ + public static final OfByte c$layout() { + return c$LAYOUT; + } + + private static final long c$OFFSET = 2; + + /** + * Offset for field: + * {@snippet lang=c : + * uint8_t c + * } + */ + public static final long c$offset() { + return c$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint8_t c + * } + */ + public static byte c(MemorySegment struct) { + return struct.get(c$LAYOUT, c$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint8_t c + * } + */ + public static void c(MemorySegment struct, byte fieldValue) { + struct.set(c$LAYOUT, c$OFFSET, fieldValue); + } + + private static final OfLong d$LAYOUT = (OfLong)$LAYOUT.select(groupElement("d")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint64_t d + * } + */ + public static final OfLong d$layout() { + return d$LAYOUT; + } + + private static final long d$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * uint64_t d + * } + */ + public static final long d$offset() { + return d$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint64_t d + * } + */ + public static long d(MemorySegment struct) { + return struct.get(d$LAYOUT, d$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint64_t d + * } + */ + public static void d(MemorySegment struct, long fieldValue) { + struct.set(d$LAYOUT, d$OFFSET, fieldValue); + } + + private static final OfInt e$LAYOUT = (OfInt)$LAYOUT.select(groupElement("e")); + + /** + * Layout for field: + * {@snippet lang=c : + * int32_t e + * } + */ + public static final OfInt e$layout() { + return e$LAYOUT; + } + + private static final long e$OFFSET = 16; + + /** + * Offset for field: + * {@snippet lang=c : + * int32_t e + * } + */ + public static final long e$offset() { + return e$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * int32_t e + * } + */ + public static int e(MemorySegment struct) { + return struct.get(e$LAYOUT, e$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * int32_t e + * } + */ + public static void e(MemorySegment struct, int fieldValue) { + struct.set(e$LAYOUT, e$OFFSET, fieldValue); + } + + private static final OfInt f$LAYOUT = (OfInt)$LAYOUT.select(groupElement("f")); + + /** + * Layout for field: + * {@snippet lang=c : + * char32_t f + * } + */ + public static final OfInt f$layout() { + return f$LAYOUT; + } + + private static final long f$OFFSET = 20; + + /** + * Offset for field: + * {@snippet lang=c : + * char32_t f + * } + */ + public static final long f$offset() { + return f$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * char32_t f + * } + */ + public static int f(MemorySegment struct) { + return struct.get(f$LAYOUT, f$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * char32_t f + * } + */ + public static void f(MemorySegment struct, int fieldValue) { + struct.set(f$LAYOUT, f$OFFSET, fieldValue); + } + + private static final OfInt g$LAYOUT = (OfInt)$LAYOUT.select(groupElement("g")); + + /** + * Layout for field: + * {@snippet lang=c : + * MyEnum g + * } + */ + public static final OfInt g$layout() { + return g$LAYOUT; + } + + private static final long g$OFFSET = 24; + + /** + * Offset for field: + * {@snippet lang=c : + * MyEnum g + * } + */ + public static final long g$offset() { + return g$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * MyEnum g + * } + */ + public static int g(MemorySegment struct) { + return struct.get(g$LAYOUT, g$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * MyEnum g + * } + */ + public static void g(MemorySegment struct, int fieldValue) { + struct.set(g$LAYOUT, g$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/MyStruct_option.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/MyStruct_option.java new file mode 100644 index 0000000..25582a4 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/MyStruct_option.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct MyStruct_option { + * union { + * MyStruct ok; + * }; + * bool is_ok; + * } + * } + */ +public class MyStruct_option { + + MyStruct_option() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + MyStruct.layout().withName("ok") + ).withName("$anon$25:33"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(7) + ).withName("MyStruct_option"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout ok$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$25:33"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * MyStruct ok + * } + */ + public static final GroupLayout ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * MyStruct ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * MyStruct ok + * } + */ + public static MemorySegment ok(MemorySegment struct) { + return struct.asSlice(ok$OFFSET, ok$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * MyStruct ok + * } + */ + public static void ok(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, ok$OFFSET, ok$LAYOUT.byteSize()); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 32; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/NestedBorrowedFields.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/NestedBorrowedFields.java new file mode 100644 index 0000000..f543e06 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/NestedBorrowedFields.java @@ -0,0 +1,219 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct NestedBorrowedFields { + * BorrowedFields fields; + * BorrowedFieldsWithBounds bounds; + * BorrowedFieldsWithBounds bounds2; + * } + * } + */ +public class NestedBorrowedFields { + + NestedBorrowedFields() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + BorrowedFields.layout().withName("fields"), + BorrowedFieldsWithBounds.layout().withName("bounds"), + BorrowedFieldsWithBounds.layout().withName("bounds2") + ).withName("NestedBorrowedFields"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout fields$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("fields")); + + /** + * Layout for field: + * {@snippet lang=c : + * BorrowedFields fields + * } + */ + public static final GroupLayout fields$layout() { + return fields$LAYOUT; + } + + private static final long fields$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * BorrowedFields fields + * } + */ + public static final long fields$offset() { + return fields$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * BorrowedFields fields + * } + */ + public static MemorySegment fields(MemorySegment struct) { + return struct.asSlice(fields$OFFSET, fields$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * BorrowedFields fields + * } + */ + public static void fields(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, fields$OFFSET, fields$LAYOUT.byteSize()); + } + + private static final GroupLayout bounds$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("bounds")); + + /** + * Layout for field: + * {@snippet lang=c : + * BorrowedFieldsWithBounds bounds + * } + */ + public static final GroupLayout bounds$layout() { + return bounds$LAYOUT; + } + + private static final long bounds$OFFSET = 48; + + /** + * Offset for field: + * {@snippet lang=c : + * BorrowedFieldsWithBounds bounds + * } + */ + public static final long bounds$offset() { + return bounds$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * BorrowedFieldsWithBounds bounds + * } + */ + public static MemorySegment bounds(MemorySegment struct) { + return struct.asSlice(bounds$OFFSET, bounds$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * BorrowedFieldsWithBounds bounds + * } + */ + public static void bounds(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, bounds$OFFSET, bounds$LAYOUT.byteSize()); + } + + private static final GroupLayout bounds2$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("bounds2")); + + /** + * Layout for field: + * {@snippet lang=c : + * BorrowedFieldsWithBounds bounds2 + * } + */ + public static final GroupLayout bounds2$layout() { + return bounds2$LAYOUT; + } + + private static final long bounds2$OFFSET = 96; + + /** + * Offset for field: + * {@snippet lang=c : + * BorrowedFieldsWithBounds bounds2 + * } + */ + public static final long bounds2$offset() { + return bounds2$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * BorrowedFieldsWithBounds bounds2 + * } + */ + public static MemorySegment bounds2(MemorySegment struct) { + return struct.asSlice(bounds2$OFFSET, bounds2$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * BorrowedFieldsWithBounds bounds2 + * } + */ + public static void bounds2(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, bounds2$OFFSET, bounds2$LAYOUT.byteSize()); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/NestedBorrowedFields_option.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/NestedBorrowedFields_option.java new file mode 100644 index 0000000..519f9bd --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/NestedBorrowedFields_option.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct NestedBorrowedFields_option { + * union { + * NestedBorrowedFields ok; + * }; + * bool is_ok; + * } + * } + */ +public class NestedBorrowedFields_option { + + NestedBorrowedFields_option() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + NestedBorrowedFields.layout().withName("ok") + ).withName("$anon$22:45"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(7) + ).withName("NestedBorrowedFields_option"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final GroupLayout ok$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("$anon$22:45"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * NestedBorrowedFields ok + * } + */ + public static final GroupLayout ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * NestedBorrowedFields ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * NestedBorrowedFields ok + * } + */ + public static MemorySegment ok(MemorySegment struct) { + return struct.asSlice(ok$OFFSET, ok$LAYOUT.byteSize()); + } + + /** + * Setter for field: + * {@snippet lang=c : + * NestedBorrowedFields ok + * } + */ + public static void ok(MemorySegment struct, MemorySegment fieldValue) { + MemorySegment.copy(fieldValue, 0L, struct, ok$OFFSET, ok$LAYOUT.byteSize()); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 144; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionBool.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionBool.java new file mode 100644 index 0000000..d5b76f4 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionBool.java @@ -0,0 +1,177 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionBool { + * union { + * bool ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionBool { + + OptionBool() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_BOOL.withName("ok") + ).withName("$anon$65:1"), + somelib_h.C_BOOL.withName("is_ok") + ).withName("OptionBool"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfBoolean ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("$anon$65:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool ok + * } + */ + public static final OfBoolean ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * bool ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool ok + * } + */ + public static boolean ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool ok + * } + */ + public static void ok(MemorySegment struct, boolean fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionChar.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionChar.java new file mode 100644 index 0000000..725e7a3 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionChar.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionChar { + * union { + * char32_t ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionChar { + + OptionChar() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_INT.withName("ok") + ).withName("$anon$66:1"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(3) + ).withName("OptionChar"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt ok$LAYOUT = (OfInt)$LAYOUT.select(groupElement("$anon$66:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * char32_t ok + * } + */ + public static final OfInt ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * char32_t ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * char32_t ok + * } + */ + public static int ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * char32_t ok + * } + */ + public static void ok(MemorySegment struct, int fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionF32.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionF32.java new file mode 100644 index 0000000..3676aad --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionF32.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionF32 { + * union { + * float ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionF32 { + + OptionF32() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_FLOAT.withName("ok") + ).withName("$anon$63:1"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(3) + ).withName("OptionF32"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfFloat ok$LAYOUT = (OfFloat)$LAYOUT.select(groupElement("$anon$63:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * float ok + * } + */ + public static final OfFloat ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * float ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * float ok + * } + */ + public static float ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * float ok + * } + */ + public static void ok(MemorySegment struct, float fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionF64.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionF64.java new file mode 100644 index 0000000..c229899 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionF64.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionF64 { + * union { + * double ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionF64 { + + OptionF64() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_DOUBLE.withName("ok") + ).withName("$anon$64:1"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(7) + ).withName("OptionF64"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfDouble ok$LAYOUT = (OfDouble)$LAYOUT.select(groupElement("$anon$64:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * double ok + * } + */ + public static final OfDouble ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * double ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * double ok + * } + */ + public static double ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * double ok + * } + */ + public static void ok(MemorySegment struct, double fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionI16.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionI16.java new file mode 100644 index 0000000..05771e5 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionI16.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionI16 { + * union { + * int16_t ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionI16 { + + OptionI16() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_SHORT.withName("ok") + ).withName("$anon$55:1"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(1) + ).withName("OptionI16"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfShort ok$LAYOUT = (OfShort)$LAYOUT.select(groupElement("$anon$55:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * int16_t ok + * } + */ + public static final OfShort ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * int16_t ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * int16_t ok + * } + */ + public static short ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * int16_t ok + * } + */ + public static void ok(MemorySegment struct, short fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 2; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionI32.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionI32.java new file mode 100644 index 0000000..e551c46 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionI32.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionI32 { + * union { + * int32_t ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionI32 { + + OptionI32() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_INT.withName("ok") + ).withName("$anon$57:1"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(3) + ).withName("OptionI32"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt ok$LAYOUT = (OfInt)$LAYOUT.select(groupElement("$anon$57:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * int32_t ok + * } + */ + public static final OfInt ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * int32_t ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * int32_t ok + * } + */ + public static int ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * int32_t ok + * } + */ + public static void ok(MemorySegment struct, int fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionI64.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionI64.java new file mode 100644 index 0000000..df7b61d --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionI64.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionI64 { + * union { + * int64_t ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionI64 { + + OptionI64() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_LONG_LONG.withName("ok") + ).withName("$anon$59:1"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(7) + ).withName("OptionI64"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfLong ok$LAYOUT = (OfLong)$LAYOUT.select(groupElement("$anon$59:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * int64_t ok + * } + */ + public static final OfLong ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * int64_t ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * int64_t ok + * } + */ + public static long ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * int64_t ok + * } + */ + public static void ok(MemorySegment struct, long fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionI8.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionI8.java new file mode 100644 index 0000000..b7326e6 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionI8.java @@ -0,0 +1,177 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionI8 { + * union { + * int8_t ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionI8 { + + OptionI8() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_CHAR.withName("ok") + ).withName("$anon$53:1"), + somelib_h.C_BOOL.withName("is_ok") + ).withName("OptionI8"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfByte ok$LAYOUT = (OfByte)$LAYOUT.select(groupElement("$anon$53:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * int8_t ok + * } + */ + public static final OfByte ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * int8_t ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * int8_t ok + * } + */ + public static byte ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * int8_t ok + * } + */ + public static void ok(MemorySegment struct, byte fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionIsize.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionIsize.java new file mode 100644 index 0000000..14b7355 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionIsize.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionIsize { + * union { + * intptr_t ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionIsize { + + OptionIsize() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_LONG.withName("ok") + ).withName("$anon$61:1"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(7) + ).withName("OptionIsize"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfLong ok$LAYOUT = (OfLong)$LAYOUT.select(groupElement("$anon$61:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * intptr_t ok + * } + */ + public static final OfLong ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * intptr_t ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * intptr_t ok + * } + */ + public static long ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * intptr_t ok + * } + */ + public static void ok(MemorySegment struct, long fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionU16.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionU16.java new file mode 100644 index 0000000..9e96cb0 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionU16.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionU16 { + * union { + * uint16_t ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionU16 { + + OptionU16() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_SHORT.withName("ok") + ).withName("$anon$56:1"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(1) + ).withName("OptionU16"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfShort ok$LAYOUT = (OfShort)$LAYOUT.select(groupElement("$anon$56:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint16_t ok + * } + */ + public static final OfShort ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * uint16_t ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint16_t ok + * } + */ + public static short ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint16_t ok + * } + */ + public static void ok(MemorySegment struct, short fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 2; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionU32.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionU32.java new file mode 100644 index 0000000..cbf82c4 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionU32.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionU32 { + * union { + * uint32_t ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionU32 { + + OptionU32() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_INT.withName("ok") + ).withName("$anon$58:1"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(3) + ).withName("OptionU32"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt ok$LAYOUT = (OfInt)$LAYOUT.select(groupElement("$anon$58:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint32_t ok + * } + */ + public static final OfInt ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * uint32_t ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint32_t ok + * } + */ + public static int ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint32_t ok + * } + */ + public static void ok(MemorySegment struct, int fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionU64.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionU64.java new file mode 100644 index 0000000..612971f --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionU64.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionU64 { + * union { + * uint64_t ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionU64 { + + OptionU64() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_LONG_LONG.withName("ok") + ).withName("$anon$60:1"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(7) + ).withName("OptionU64"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfLong ok$LAYOUT = (OfLong)$LAYOUT.select(groupElement("$anon$60:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint64_t ok + * } + */ + public static final OfLong ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * uint64_t ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint64_t ok + * } + */ + public static long ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint64_t ok + * } + */ + public static void ok(MemorySegment struct, long fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionU8.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionU8.java new file mode 100644 index 0000000..e4878a0 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionU8.java @@ -0,0 +1,177 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionU8 { + * union { + * uint8_t ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionU8 { + + OptionU8() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_CHAR.withName("ok") + ).withName("$anon$54:1"), + somelib_h.C_BOOL.withName("is_ok") + ).withName("OptionU8"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfByte ok$LAYOUT = (OfByte)$LAYOUT.select(groupElement("$anon$54:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * uint8_t ok + * } + */ + public static final OfByte ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * uint8_t ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * uint8_t ok + * } + */ + public static byte ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * uint8_t ok + * } + */ + public static void ok(MemorySegment struct, byte fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 1; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionUsize.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionUsize.java new file mode 100644 index 0000000..d88ea49 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/OptionUsize.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct OptionUsize { + * union { + * size_t ok; + * }; + * bool is_ok; + * } + * } + */ +public class OptionUsize { + + OptionUsize() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_LONG.withName("ok") + ).withName("$anon$62:1"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(7) + ).withName("OptionUsize"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfLong ok$LAYOUT = (OfLong)$LAYOUT.select(groupElement("$anon$62:1"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * size_t ok + * } + */ + public static final OfLong ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * size_t ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * size_t ok + * } + */ + public static long ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * size_t ok + * } + */ + public static void ok(MemorySegment struct, long fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 8; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/UnimportedEnum_option.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/UnimportedEnum_option.java new file mode 100644 index 0000000..5a204c6 --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/UnimportedEnum_option.java @@ -0,0 +1,178 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +/** + * {@snippet lang=c : + * struct UnimportedEnum_option { + * union { + * UnimportedEnum ok; + * }; + * bool is_ok; + * } + * } + */ +public class UnimportedEnum_option { + + UnimportedEnum_option() { + // Should not be called directly + } + + private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( + MemoryLayout.unionLayout( + somelib_h.C_INT.withName("ok") + ).withName("$anon$20:39"), + somelib_h.C_BOOL.withName("is_ok"), + MemoryLayout.paddingLayout(3) + ).withName("UnimportedEnum_option"); + + /** + * The layout of this struct + */ + public static final GroupLayout layout() { + return $LAYOUT; + } + + private static final OfInt ok$LAYOUT = (OfInt)$LAYOUT.select(groupElement("$anon$20:39"), groupElement("ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * UnimportedEnum ok + * } + */ + public static final OfInt ok$layout() { + return ok$LAYOUT; + } + + private static final long ok$OFFSET = 0; + + /** + * Offset for field: + * {@snippet lang=c : + * UnimportedEnum ok + * } + */ + public static final long ok$offset() { + return ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * UnimportedEnum ok + * } + */ + public static int ok(MemorySegment struct) { + return struct.get(ok$LAYOUT, ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * UnimportedEnum ok + * } + */ + public static void ok(MemorySegment struct, int fieldValue) { + struct.set(ok$LAYOUT, ok$OFFSET, fieldValue); + } + + private static final OfBoolean is_ok$LAYOUT = (OfBoolean)$LAYOUT.select(groupElement("is_ok")); + + /** + * Layout for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final OfBoolean is_ok$layout() { + return is_ok$LAYOUT; + } + + private static final long is_ok$OFFSET = 4; + + /** + * Offset for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static final long is_ok$offset() { + return is_ok$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static boolean is_ok(MemorySegment struct) { + return struct.get(is_ok$LAYOUT, is_ok$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * bool is_ok + * } + */ + public static void is_ok(MemorySegment struct, boolean fieldValue) { + struct.set(is_ok$LAYOUT, is_ok$OFFSET, fieldValue); + } + + /** + * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}. + * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()} + */ + public static MemorySegment asSlice(MemorySegment array, long index) { + return array.asSlice(layout().byteSize() * index); + } + + /** + * The size (in bytes) of this struct + */ + public static long sizeof() { return layout().byteSize(); } + + /** + * Allocate a segment of size {@code layout().byteSize()} using {@code allocator} + */ + public static MemorySegment allocate(SegmentAllocator allocator) { + return allocator.allocate(layout()); + } + + /** + * Allocate an array of size {@code elementCount} using {@code allocator}. + * The returned segment has size {@code elementCount * layout().byteSize()}. + */ + public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) { + return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout())); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { + return reinterpret(addr, 1, arena, cleanup); + } + + /** + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). + * The returned segment has size {@code elementCount * layout().byteSize()} + */ + public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { + return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup); + } +} + diff --git a/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/somelib_h.java b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/somelib_h.java new file mode 100644 index 0000000..f78f36b --- /dev/null +++ b/feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv/somelib_h.java @@ -0,0 +1,15429 @@ +// Generated by jextract + +package dev.diplomattest.somelib.ntv; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class somelib_h { + + somelib_h() { + // Should not be called directly + } + + static final Arena LIBRARY_ARENA = Arena.ofAuto(); + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MemorySegment findOrThrow(String symbol) { + return SYMBOL_LOOKUP.find(symbol) + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } + + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup(System.mapLibraryName("somelib"), LIBRARY_ARENA) + .or(SymbolLookup.loaderLookup()) + .or(Linker.nativeLinker().defaultLookup()); + + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); + public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; + private static final int __has_safe_buffers = (int)0L; + /** + * {@snippet lang=c : + * #define __has_safe_buffers 0 + * } + */ + public static int __has_safe_buffers() { + return __has_safe_buffers; + } + private static final int __DARWIN_ONLY_64_BIT_INO_T = (int)1L; + /** + * {@snippet lang=c : + * #define __DARWIN_ONLY_64_BIT_INO_T 1 + * } + */ + public static int __DARWIN_ONLY_64_BIT_INO_T() { + return __DARWIN_ONLY_64_BIT_INO_T; + } + private static final int __DARWIN_ONLY_UNIX_CONFORMANCE = (int)1L; + /** + * {@snippet lang=c : + * #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 + * } + */ + public static int __DARWIN_ONLY_UNIX_CONFORMANCE() { + return __DARWIN_ONLY_UNIX_CONFORMANCE; + } + private static final int __DARWIN_ONLY_VERS_1050 = (int)1L; + /** + * {@snippet lang=c : + * #define __DARWIN_ONLY_VERS_1050 1 + * } + */ + public static int __DARWIN_ONLY_VERS_1050() { + return __DARWIN_ONLY_VERS_1050; + } + private static final int __DARWIN_UNIX03 = (int)1L; + /** + * {@snippet lang=c : + * #define __DARWIN_UNIX03 1 + * } + */ + public static int __DARWIN_UNIX03() { + return __DARWIN_UNIX03; + } + private static final int __DARWIN_64_BIT_INO_T = (int)1L; + /** + * {@snippet lang=c : + * #define __DARWIN_64_BIT_INO_T 1 + * } + */ + public static int __DARWIN_64_BIT_INO_T() { + return __DARWIN_64_BIT_INO_T; + } + private static final int __DARWIN_VERS_1050 = (int)1L; + /** + * {@snippet lang=c : + * #define __DARWIN_VERS_1050 1 + * } + */ + public static int __DARWIN_VERS_1050() { + return __DARWIN_VERS_1050; + } + private static final int __DARWIN_NON_CANCELABLE = (int)0L; + /** + * {@snippet lang=c : + * #define __DARWIN_NON_CANCELABLE 0 + * } + */ + public static int __DARWIN_NON_CANCELABLE() { + return __DARWIN_NON_CANCELABLE; + } + private static final int __STDC_WANT_LIB_EXT1__ = (int)1L; + /** + * {@snippet lang=c : + * #define __STDC_WANT_LIB_EXT1__ 1 + * } + */ + public static int __STDC_WANT_LIB_EXT1__() { + return __STDC_WANT_LIB_EXT1__; + } + private static final int __DARWIN_NO_LONG_LONG = (int)0L; + /** + * {@snippet lang=c : + * #define __DARWIN_NO_LONG_LONG 0 + * } + */ + public static int __DARWIN_NO_LONG_LONG() { + return __DARWIN_NO_LONG_LONG; + } + private static final int _DARWIN_FEATURE_64_BIT_INODE = (int)1L; + /** + * {@snippet lang=c : + * #define _DARWIN_FEATURE_64_BIT_INODE 1 + * } + */ + public static int _DARWIN_FEATURE_64_BIT_INODE() { + return _DARWIN_FEATURE_64_BIT_INODE; + } + private static final int _DARWIN_FEATURE_ONLY_64_BIT_INODE = (int)1L; + /** + * {@snippet lang=c : + * #define _DARWIN_FEATURE_ONLY_64_BIT_INODE 1 + * } + */ + public static int _DARWIN_FEATURE_ONLY_64_BIT_INODE() { + return _DARWIN_FEATURE_ONLY_64_BIT_INODE; + } + private static final int _DARWIN_FEATURE_ONLY_VERS_1050 = (int)1L; + /** + * {@snippet lang=c : + * #define _DARWIN_FEATURE_ONLY_VERS_1050 1 + * } + */ + public static int _DARWIN_FEATURE_ONLY_VERS_1050() { + return _DARWIN_FEATURE_ONLY_VERS_1050; + } + private static final int _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE = (int)1L; + /** + * {@snippet lang=c : + * #define _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE 1 + * } + */ + public static int _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE() { + return _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE; + } + private static final int _DARWIN_FEATURE_UNIX_CONFORMANCE = (int)3L; + /** + * {@snippet lang=c : + * #define _DARWIN_FEATURE_UNIX_CONFORMANCE 3 + * } + */ + public static int _DARWIN_FEATURE_UNIX_CONFORMANCE() { + return _DARWIN_FEATURE_UNIX_CONFORMANCE; + } + private static final int __has_ptrcheck = (int)0L; + /** + * {@snippet lang=c : + * #define __has_ptrcheck 0 + * } + */ + public static int __has_ptrcheck() { + return __has_ptrcheck; + } + private static final int true_ = (int)1L; + /** + * {@snippet lang=c : + * #define true 1 + * } + */ + public static int true_() { + return true_; + } + private static final int false_ = (int)0L; + /** + * {@snippet lang=c : + * #define false 0 + * } + */ + public static int false_() { + return false_; + } + private static final int __bool_true_false_are_defined = (int)1L; + /** + * {@snippet lang=c : + * #define __bool_true_false_are_defined 1 + * } + */ + public static int __bool_true_false_are_defined() { + return __bool_true_false_are_defined; + } + private static final int __WORDSIZE = (int)64L; + /** + * {@snippet lang=c : + * #define __WORDSIZE 64 + * } + */ + public static int __WORDSIZE() { + return __WORDSIZE; + } + private static final int __PTHREAD_SIZE__ = (int)8176L; + /** + * {@snippet lang=c : + * #define __PTHREAD_SIZE__ 8176 + * } + */ + public static int __PTHREAD_SIZE__() { + return __PTHREAD_SIZE__; + } + private static final int __PTHREAD_ATTR_SIZE__ = (int)56L; + /** + * {@snippet lang=c : + * #define __PTHREAD_ATTR_SIZE__ 56 + * } + */ + public static int __PTHREAD_ATTR_SIZE__() { + return __PTHREAD_ATTR_SIZE__; + } + private static final int __PTHREAD_MUTEXATTR_SIZE__ = (int)8L; + /** + * {@snippet lang=c : + * #define __PTHREAD_MUTEXATTR_SIZE__ 8 + * } + */ + public static int __PTHREAD_MUTEXATTR_SIZE__() { + return __PTHREAD_MUTEXATTR_SIZE__; + } + private static final int __PTHREAD_MUTEX_SIZE__ = (int)56L; + /** + * {@snippet lang=c : + * #define __PTHREAD_MUTEX_SIZE__ 56 + * } + */ + public static int __PTHREAD_MUTEX_SIZE__() { + return __PTHREAD_MUTEX_SIZE__; + } + private static final int __PTHREAD_CONDATTR_SIZE__ = (int)8L; + /** + * {@snippet lang=c : + * #define __PTHREAD_CONDATTR_SIZE__ 8 + * } + */ + public static int __PTHREAD_CONDATTR_SIZE__() { + return __PTHREAD_CONDATTR_SIZE__; + } + private static final int __PTHREAD_COND_SIZE__ = (int)40L; + /** + * {@snippet lang=c : + * #define __PTHREAD_COND_SIZE__ 40 + * } + */ + public static int __PTHREAD_COND_SIZE__() { + return __PTHREAD_COND_SIZE__; + } + private static final int __PTHREAD_ONCE_SIZE__ = (int)8L; + /** + * {@snippet lang=c : + * #define __PTHREAD_ONCE_SIZE__ 8 + * } + */ + public static int __PTHREAD_ONCE_SIZE__() { + return __PTHREAD_ONCE_SIZE__; + } + private static final int __PTHREAD_RWLOCK_SIZE__ = (int)192L; + /** + * {@snippet lang=c : + * #define __PTHREAD_RWLOCK_SIZE__ 192 + * } + */ + public static int __PTHREAD_RWLOCK_SIZE__() { + return __PTHREAD_RWLOCK_SIZE__; + } + private static final int __PTHREAD_RWLOCKATTR_SIZE__ = (int)16L; + /** + * {@snippet lang=c : + * #define __PTHREAD_RWLOCKATTR_SIZE__ 16 + * } + */ + public static int __PTHREAD_RWLOCKATTR_SIZE__() { + return __PTHREAD_RWLOCKATTR_SIZE__; + } + private static final int INT8_MAX = (int)127L; + /** + * {@snippet lang=c : + * #define INT8_MAX 127 + * } + */ + public static int INT8_MAX() { + return INT8_MAX; + } + private static final int INT16_MAX = (int)32767L; + /** + * {@snippet lang=c : + * #define INT16_MAX 32767 + * } + */ + public static int INT16_MAX() { + return INT16_MAX; + } + private static final int INT32_MAX = (int)2147483647L; + /** + * {@snippet lang=c : + * #define INT32_MAX 2147483647 + * } + */ + public static int INT32_MAX() { + return INT32_MAX; + } + private static final int UINT8_MAX = (int)255L; + /** + * {@snippet lang=c : + * #define UINT8_MAX 255 + * } + */ + public static int UINT8_MAX() { + return UINT8_MAX; + } + private static final int UINT16_MAX = (int)65535L; + /** + * {@snippet lang=c : + * #define UINT16_MAX 65535 + * } + */ + public static int UINT16_MAX() { + return UINT16_MAX; + } + private static final int __API_TO_BE_DEPRECATED = (int)100000L; + /** + * {@snippet lang=c : + * #define __API_TO_BE_DEPRECATED 100000 + * } + */ + public static int __API_TO_BE_DEPRECATED() { + return __API_TO_BE_DEPRECATED; + } + private static final int __API_TO_BE_DEPRECATED_MACOS = (int)100000L; + /** + * {@snippet lang=c : + * #define __API_TO_BE_DEPRECATED_MACOS 100000 + * } + */ + public static int __API_TO_BE_DEPRECATED_MACOS() { + return __API_TO_BE_DEPRECATED_MACOS; + } + private static final int __API_TO_BE_DEPRECATED_IOS = (int)100000L; + /** + * {@snippet lang=c : + * #define __API_TO_BE_DEPRECATED_IOS 100000 + * } + */ + public static int __API_TO_BE_DEPRECATED_IOS() { + return __API_TO_BE_DEPRECATED_IOS; + } + private static final int __API_TO_BE_DEPRECATED_MACCATALYST = (int)100000L; + /** + * {@snippet lang=c : + * #define __API_TO_BE_DEPRECATED_MACCATALYST 100000 + * } + */ + public static int __API_TO_BE_DEPRECATED_MACCATALYST() { + return __API_TO_BE_DEPRECATED_MACCATALYST; + } + private static final int __API_TO_BE_DEPRECATED_WATCHOS = (int)100000L; + /** + * {@snippet lang=c : + * #define __API_TO_BE_DEPRECATED_WATCHOS 100000 + * } + */ + public static int __API_TO_BE_DEPRECATED_WATCHOS() { + return __API_TO_BE_DEPRECATED_WATCHOS; + } + private static final int __API_TO_BE_DEPRECATED_TVOS = (int)100000L; + /** + * {@snippet lang=c : + * #define __API_TO_BE_DEPRECATED_TVOS 100000 + * } + */ + public static int __API_TO_BE_DEPRECATED_TVOS() { + return __API_TO_BE_DEPRECATED_TVOS; + } + private static final int __API_TO_BE_DEPRECATED_DRIVERKIT = (int)100000L; + /** + * {@snippet lang=c : + * #define __API_TO_BE_DEPRECATED_DRIVERKIT 100000 + * } + */ + public static int __API_TO_BE_DEPRECATED_DRIVERKIT() { + return __API_TO_BE_DEPRECATED_DRIVERKIT; + } + private static final int __API_TO_BE_DEPRECATED_VISIONOS = (int)100000L; + /** + * {@snippet lang=c : + * #define __API_TO_BE_DEPRECATED_VISIONOS 100000 + * } + */ + public static int __API_TO_BE_DEPRECATED_VISIONOS() { + return __API_TO_BE_DEPRECATED_VISIONOS; + } + private static final int __MAC_10_0 = (int)1000L; + /** + * {@snippet lang=c : + * #define __MAC_10_0 1000 + * } + */ + public static int __MAC_10_0() { + return __MAC_10_0; + } + private static final int __MAC_10_1 = (int)1010L; + /** + * {@snippet lang=c : + * #define __MAC_10_1 1010 + * } + */ + public static int __MAC_10_1() { + return __MAC_10_1; + } + private static final int __MAC_10_2 = (int)1020L; + /** + * {@snippet lang=c : + * #define __MAC_10_2 1020 + * } + */ + public static int __MAC_10_2() { + return __MAC_10_2; + } + private static final int __MAC_10_3 = (int)1030L; + /** + * {@snippet lang=c : + * #define __MAC_10_3 1030 + * } + */ + public static int __MAC_10_3() { + return __MAC_10_3; + } + private static final int __MAC_10_4 = (int)1040L; + /** + * {@snippet lang=c : + * #define __MAC_10_4 1040 + * } + */ + public static int __MAC_10_4() { + return __MAC_10_4; + } + private static final int __MAC_10_5 = (int)1050L; + /** + * {@snippet lang=c : + * #define __MAC_10_5 1050 + * } + */ + public static int __MAC_10_5() { + return __MAC_10_5; + } + private static final int __MAC_10_6 = (int)1060L; + /** + * {@snippet lang=c : + * #define __MAC_10_6 1060 + * } + */ + public static int __MAC_10_6() { + return __MAC_10_6; + } + private static final int __MAC_10_7 = (int)1070L; + /** + * {@snippet lang=c : + * #define __MAC_10_7 1070 + * } + */ + public static int __MAC_10_7() { + return __MAC_10_7; + } + private static final int __MAC_10_8 = (int)1080L; + /** + * {@snippet lang=c : + * #define __MAC_10_8 1080 + * } + */ + public static int __MAC_10_8() { + return __MAC_10_8; + } + private static final int __MAC_10_9 = (int)1090L; + /** + * {@snippet lang=c : + * #define __MAC_10_9 1090 + * } + */ + public static int __MAC_10_9() { + return __MAC_10_9; + } + private static final int __MAC_10_10 = (int)101000L; + /** + * {@snippet lang=c : + * #define __MAC_10_10 101000 + * } + */ + public static int __MAC_10_10() { + return __MAC_10_10; + } + private static final int __MAC_10_10_2 = (int)101002L; + /** + * {@snippet lang=c : + * #define __MAC_10_10_2 101002 + * } + */ + public static int __MAC_10_10_2() { + return __MAC_10_10_2; + } + private static final int __MAC_10_10_3 = (int)101003L; + /** + * {@snippet lang=c : + * #define __MAC_10_10_3 101003 + * } + */ + public static int __MAC_10_10_3() { + return __MAC_10_10_3; + } + private static final int __MAC_10_11 = (int)101100L; + /** + * {@snippet lang=c : + * #define __MAC_10_11 101100 + * } + */ + public static int __MAC_10_11() { + return __MAC_10_11; + } + private static final int __MAC_10_11_2 = (int)101102L; + /** + * {@snippet lang=c : + * #define __MAC_10_11_2 101102 + * } + */ + public static int __MAC_10_11_2() { + return __MAC_10_11_2; + } + private static final int __MAC_10_11_3 = (int)101103L; + /** + * {@snippet lang=c : + * #define __MAC_10_11_3 101103 + * } + */ + public static int __MAC_10_11_3() { + return __MAC_10_11_3; + } + private static final int __MAC_10_11_4 = (int)101104L; + /** + * {@snippet lang=c : + * #define __MAC_10_11_4 101104 + * } + */ + public static int __MAC_10_11_4() { + return __MAC_10_11_4; + } + private static final int __MAC_10_12 = (int)101200L; + /** + * {@snippet lang=c : + * #define __MAC_10_12 101200 + * } + */ + public static int __MAC_10_12() { + return __MAC_10_12; + } + private static final int __MAC_10_12_1 = (int)101201L; + /** + * {@snippet lang=c : + * #define __MAC_10_12_1 101201 + * } + */ + public static int __MAC_10_12_1() { + return __MAC_10_12_1; + } + private static final int __MAC_10_12_2 = (int)101202L; + /** + * {@snippet lang=c : + * #define __MAC_10_12_2 101202 + * } + */ + public static int __MAC_10_12_2() { + return __MAC_10_12_2; + } + private static final int __MAC_10_12_4 = (int)101204L; + /** + * {@snippet lang=c : + * #define __MAC_10_12_4 101204 + * } + */ + public static int __MAC_10_12_4() { + return __MAC_10_12_4; + } + private static final int __MAC_10_13 = (int)101300L; + /** + * {@snippet lang=c : + * #define __MAC_10_13 101300 + * } + */ + public static int __MAC_10_13() { + return __MAC_10_13; + } + private static final int __MAC_10_13_1 = (int)101301L; + /** + * {@snippet lang=c : + * #define __MAC_10_13_1 101301 + * } + */ + public static int __MAC_10_13_1() { + return __MAC_10_13_1; + } + private static final int __MAC_10_13_2 = (int)101302L; + /** + * {@snippet lang=c : + * #define __MAC_10_13_2 101302 + * } + */ + public static int __MAC_10_13_2() { + return __MAC_10_13_2; + } + private static final int __MAC_10_13_4 = (int)101304L; + /** + * {@snippet lang=c : + * #define __MAC_10_13_4 101304 + * } + */ + public static int __MAC_10_13_4() { + return __MAC_10_13_4; + } + private static final int __MAC_10_14 = (int)101400L; + /** + * {@snippet lang=c : + * #define __MAC_10_14 101400 + * } + */ + public static int __MAC_10_14() { + return __MAC_10_14; + } + private static final int __MAC_10_14_1 = (int)101401L; + /** + * {@snippet lang=c : + * #define __MAC_10_14_1 101401 + * } + */ + public static int __MAC_10_14_1() { + return __MAC_10_14_1; + } + private static final int __MAC_10_14_4 = (int)101404L; + /** + * {@snippet lang=c : + * #define __MAC_10_14_4 101404 + * } + */ + public static int __MAC_10_14_4() { + return __MAC_10_14_4; + } + private static final int __MAC_10_14_5 = (int)101405L; + /** + * {@snippet lang=c : + * #define __MAC_10_14_5 101405 + * } + */ + public static int __MAC_10_14_5() { + return __MAC_10_14_5; + } + private static final int __MAC_10_14_6 = (int)101406L; + /** + * {@snippet lang=c : + * #define __MAC_10_14_6 101406 + * } + */ + public static int __MAC_10_14_6() { + return __MAC_10_14_6; + } + private static final int __MAC_10_15 = (int)101500L; + /** + * {@snippet lang=c : + * #define __MAC_10_15 101500 + * } + */ + public static int __MAC_10_15() { + return __MAC_10_15; + } + private static final int __MAC_10_15_1 = (int)101501L; + /** + * {@snippet lang=c : + * #define __MAC_10_15_1 101501 + * } + */ + public static int __MAC_10_15_1() { + return __MAC_10_15_1; + } + private static final int __MAC_10_15_4 = (int)101504L; + /** + * {@snippet lang=c : + * #define __MAC_10_15_4 101504 + * } + */ + public static int __MAC_10_15_4() { + return __MAC_10_15_4; + } + private static final int __MAC_10_16 = (int)101600L; + /** + * {@snippet lang=c : + * #define __MAC_10_16 101600 + * } + */ + public static int __MAC_10_16() { + return __MAC_10_16; + } + private static final int __MAC_11_0 = (int)110000L; + /** + * {@snippet lang=c : + * #define __MAC_11_0 110000 + * } + */ + public static int __MAC_11_0() { + return __MAC_11_0; + } + private static final int __MAC_11_1 = (int)110100L; + /** + * {@snippet lang=c : + * #define __MAC_11_1 110100 + * } + */ + public static int __MAC_11_1() { + return __MAC_11_1; + } + private static final int __MAC_11_3 = (int)110300L; + /** + * {@snippet lang=c : + * #define __MAC_11_3 110300 + * } + */ + public static int __MAC_11_3() { + return __MAC_11_3; + } + private static final int __MAC_11_4 = (int)110400L; + /** + * {@snippet lang=c : + * #define __MAC_11_4 110400 + * } + */ + public static int __MAC_11_4() { + return __MAC_11_4; + } + private static final int __MAC_11_5 = (int)110500L; + /** + * {@snippet lang=c : + * #define __MAC_11_5 110500 + * } + */ + public static int __MAC_11_5() { + return __MAC_11_5; + } + private static final int __MAC_11_6 = (int)110600L; + /** + * {@snippet lang=c : + * #define __MAC_11_6 110600 + * } + */ + public static int __MAC_11_6() { + return __MAC_11_6; + } + private static final int __MAC_12_0 = (int)120000L; + /** + * {@snippet lang=c : + * #define __MAC_12_0 120000 + * } + */ + public static int __MAC_12_0() { + return __MAC_12_0; + } + private static final int __MAC_12_1 = (int)120100L; + /** + * {@snippet lang=c : + * #define __MAC_12_1 120100 + * } + */ + public static int __MAC_12_1() { + return __MAC_12_1; + } + private static final int __MAC_12_2 = (int)120200L; + /** + * {@snippet lang=c : + * #define __MAC_12_2 120200 + * } + */ + public static int __MAC_12_2() { + return __MAC_12_2; + } + private static final int __MAC_12_3 = (int)120300L; + /** + * {@snippet lang=c : + * #define __MAC_12_3 120300 + * } + */ + public static int __MAC_12_3() { + return __MAC_12_3; + } + private static final int __MAC_12_4 = (int)120400L; + /** + * {@snippet lang=c : + * #define __MAC_12_4 120400 + * } + */ + public static int __MAC_12_4() { + return __MAC_12_4; + } + private static final int __MAC_12_5 = (int)120500L; + /** + * {@snippet lang=c : + * #define __MAC_12_5 120500 + * } + */ + public static int __MAC_12_5() { + return __MAC_12_5; + } + private static final int __MAC_12_6 = (int)120600L; + /** + * {@snippet lang=c : + * #define __MAC_12_6 120600 + * } + */ + public static int __MAC_12_6() { + return __MAC_12_6; + } + private static final int __MAC_12_7 = (int)120700L; + /** + * {@snippet lang=c : + * #define __MAC_12_7 120700 + * } + */ + public static int __MAC_12_7() { + return __MAC_12_7; + } + private static final int __MAC_13_0 = (int)130000L; + /** + * {@snippet lang=c : + * #define __MAC_13_0 130000 + * } + */ + public static int __MAC_13_0() { + return __MAC_13_0; + } + private static final int __MAC_13_1 = (int)130100L; + /** + * {@snippet lang=c : + * #define __MAC_13_1 130100 + * } + */ + public static int __MAC_13_1() { + return __MAC_13_1; + } + private static final int __MAC_13_2 = (int)130200L; + /** + * {@snippet lang=c : + * #define __MAC_13_2 130200 + * } + */ + public static int __MAC_13_2() { + return __MAC_13_2; + } + private static final int __MAC_13_3 = (int)130300L; + /** + * {@snippet lang=c : + * #define __MAC_13_3 130300 + * } + */ + public static int __MAC_13_3() { + return __MAC_13_3; + } + private static final int __MAC_13_4 = (int)130400L; + /** + * {@snippet lang=c : + * #define __MAC_13_4 130400 + * } + */ + public static int __MAC_13_4() { + return __MAC_13_4; + } + private static final int __MAC_13_5 = (int)130500L; + /** + * {@snippet lang=c : + * #define __MAC_13_5 130500 + * } + */ + public static int __MAC_13_5() { + return __MAC_13_5; + } + private static final int __MAC_13_6 = (int)130600L; + /** + * {@snippet lang=c : + * #define __MAC_13_6 130600 + * } + */ + public static int __MAC_13_6() { + return __MAC_13_6; + } + private static final int __MAC_14_0 = (int)140000L; + /** + * {@snippet lang=c : + * #define __MAC_14_0 140000 + * } + */ + public static int __MAC_14_0() { + return __MAC_14_0; + } + private static final int __MAC_14_1 = (int)140100L; + /** + * {@snippet lang=c : + * #define __MAC_14_1 140100 + * } + */ + public static int __MAC_14_1() { + return __MAC_14_1; + } + private static final int __MAC_14_2 = (int)140200L; + /** + * {@snippet lang=c : + * #define __MAC_14_2 140200 + * } + */ + public static int __MAC_14_2() { + return __MAC_14_2; + } + private static final int __MAC_14_3 = (int)140300L; + /** + * {@snippet lang=c : + * #define __MAC_14_3 140300 + * } + */ + public static int __MAC_14_3() { + return __MAC_14_3; + } + private static final int __MAC_14_4 = (int)140400L; + /** + * {@snippet lang=c : + * #define __MAC_14_4 140400 + * } + */ + public static int __MAC_14_4() { + return __MAC_14_4; + } + private static final int __MAC_14_5 = (int)140500L; + /** + * {@snippet lang=c : + * #define __MAC_14_5 140500 + * } + */ + public static int __MAC_14_5() { + return __MAC_14_5; + } + private static final int __IPHONE_2_0 = (int)20000L; + /** + * {@snippet lang=c : + * #define __IPHONE_2_0 20000 + * } + */ + public static int __IPHONE_2_0() { + return __IPHONE_2_0; + } + private static final int __IPHONE_2_1 = (int)20100L; + /** + * {@snippet lang=c : + * #define __IPHONE_2_1 20100 + * } + */ + public static int __IPHONE_2_1() { + return __IPHONE_2_1; + } + private static final int __IPHONE_2_2 = (int)20200L; + /** + * {@snippet lang=c : + * #define __IPHONE_2_2 20200 + * } + */ + public static int __IPHONE_2_2() { + return __IPHONE_2_2; + } + private static final int __IPHONE_3_0 = (int)30000L; + /** + * {@snippet lang=c : + * #define __IPHONE_3_0 30000 + * } + */ + public static int __IPHONE_3_0() { + return __IPHONE_3_0; + } + private static final int __IPHONE_3_1 = (int)30100L; + /** + * {@snippet lang=c : + * #define __IPHONE_3_1 30100 + * } + */ + public static int __IPHONE_3_1() { + return __IPHONE_3_1; + } + private static final int __IPHONE_3_2 = (int)30200L; + /** + * {@snippet lang=c : + * #define __IPHONE_3_2 30200 + * } + */ + public static int __IPHONE_3_2() { + return __IPHONE_3_2; + } + private static final int __IPHONE_4_0 = (int)40000L; + /** + * {@snippet lang=c : + * #define __IPHONE_4_0 40000 + * } + */ + public static int __IPHONE_4_0() { + return __IPHONE_4_0; + } + private static final int __IPHONE_4_1 = (int)40100L; + /** + * {@snippet lang=c : + * #define __IPHONE_4_1 40100 + * } + */ + public static int __IPHONE_4_1() { + return __IPHONE_4_1; + } + private static final int __IPHONE_4_2 = (int)40200L; + /** + * {@snippet lang=c : + * #define __IPHONE_4_2 40200 + * } + */ + public static int __IPHONE_4_2() { + return __IPHONE_4_2; + } + private static final int __IPHONE_4_3 = (int)40300L; + /** + * {@snippet lang=c : + * #define __IPHONE_4_3 40300 + * } + */ + public static int __IPHONE_4_3() { + return __IPHONE_4_3; + } + private static final int __IPHONE_5_0 = (int)50000L; + /** + * {@snippet lang=c : + * #define __IPHONE_5_0 50000 + * } + */ + public static int __IPHONE_5_0() { + return __IPHONE_5_0; + } + private static final int __IPHONE_5_1 = (int)50100L; + /** + * {@snippet lang=c : + * #define __IPHONE_5_1 50100 + * } + */ + public static int __IPHONE_5_1() { + return __IPHONE_5_1; + } + private static final int __IPHONE_6_0 = (int)60000L; + /** + * {@snippet lang=c : + * #define __IPHONE_6_0 60000 + * } + */ + public static int __IPHONE_6_0() { + return __IPHONE_6_0; + } + private static final int __IPHONE_6_1 = (int)60100L; + /** + * {@snippet lang=c : + * #define __IPHONE_6_1 60100 + * } + */ + public static int __IPHONE_6_1() { + return __IPHONE_6_1; + } + private static final int __IPHONE_7_0 = (int)70000L; + /** + * {@snippet lang=c : + * #define __IPHONE_7_0 70000 + * } + */ + public static int __IPHONE_7_0() { + return __IPHONE_7_0; + } + private static final int __IPHONE_7_1 = (int)70100L; + /** + * {@snippet lang=c : + * #define __IPHONE_7_1 70100 + * } + */ + public static int __IPHONE_7_1() { + return __IPHONE_7_1; + } + private static final int __IPHONE_8_0 = (int)80000L; + /** + * {@snippet lang=c : + * #define __IPHONE_8_0 80000 + * } + */ + public static int __IPHONE_8_0() { + return __IPHONE_8_0; + } + private static final int __IPHONE_8_1 = (int)80100L; + /** + * {@snippet lang=c : + * #define __IPHONE_8_1 80100 + * } + */ + public static int __IPHONE_8_1() { + return __IPHONE_8_1; + } + private static final int __IPHONE_8_2 = (int)80200L; + /** + * {@snippet lang=c : + * #define __IPHONE_8_2 80200 + * } + */ + public static int __IPHONE_8_2() { + return __IPHONE_8_2; + } + private static final int __IPHONE_8_3 = (int)80300L; + /** + * {@snippet lang=c : + * #define __IPHONE_8_3 80300 + * } + */ + public static int __IPHONE_8_3() { + return __IPHONE_8_3; + } + private static final int __IPHONE_8_4 = (int)80400L; + /** + * {@snippet lang=c : + * #define __IPHONE_8_4 80400 + * } + */ + public static int __IPHONE_8_4() { + return __IPHONE_8_4; + } + private static final int __IPHONE_9_0 = (int)90000L; + /** + * {@snippet lang=c : + * #define __IPHONE_9_0 90000 + * } + */ + public static int __IPHONE_9_0() { + return __IPHONE_9_0; + } + private static final int __IPHONE_9_1 = (int)90100L; + /** + * {@snippet lang=c : + * #define __IPHONE_9_1 90100 + * } + */ + public static int __IPHONE_9_1() { + return __IPHONE_9_1; + } + private static final int __IPHONE_9_2 = (int)90200L; + /** + * {@snippet lang=c : + * #define __IPHONE_9_2 90200 + * } + */ + public static int __IPHONE_9_2() { + return __IPHONE_9_2; + } + private static final int __IPHONE_9_3 = (int)90300L; + /** + * {@snippet lang=c : + * #define __IPHONE_9_3 90300 + * } + */ + public static int __IPHONE_9_3() { + return __IPHONE_9_3; + } + private static final int __IPHONE_10_0 = (int)100000L; + /** + * {@snippet lang=c : + * #define __IPHONE_10_0 100000 + * } + */ + public static int __IPHONE_10_0() { + return __IPHONE_10_0; + } + private static final int __IPHONE_10_1 = (int)100100L; + /** + * {@snippet lang=c : + * #define __IPHONE_10_1 100100 + * } + */ + public static int __IPHONE_10_1() { + return __IPHONE_10_1; + } + private static final int __IPHONE_10_2 = (int)100200L; + /** + * {@snippet lang=c : + * #define __IPHONE_10_2 100200 + * } + */ + public static int __IPHONE_10_2() { + return __IPHONE_10_2; + } + private static final int __IPHONE_10_3 = (int)100300L; + /** + * {@snippet lang=c : + * #define __IPHONE_10_3 100300 + * } + */ + public static int __IPHONE_10_3() { + return __IPHONE_10_3; + } + private static final int __IPHONE_11_0 = (int)110000L; + /** + * {@snippet lang=c : + * #define __IPHONE_11_0 110000 + * } + */ + public static int __IPHONE_11_0() { + return __IPHONE_11_0; + } + private static final int __IPHONE_11_1 = (int)110100L; + /** + * {@snippet lang=c : + * #define __IPHONE_11_1 110100 + * } + */ + public static int __IPHONE_11_1() { + return __IPHONE_11_1; + } + private static final int __IPHONE_11_2 = (int)110200L; + /** + * {@snippet lang=c : + * #define __IPHONE_11_2 110200 + * } + */ + public static int __IPHONE_11_2() { + return __IPHONE_11_2; + } + private static final int __IPHONE_11_3 = (int)110300L; + /** + * {@snippet lang=c : + * #define __IPHONE_11_3 110300 + * } + */ + public static int __IPHONE_11_3() { + return __IPHONE_11_3; + } + private static final int __IPHONE_11_4 = (int)110400L; + /** + * {@snippet lang=c : + * #define __IPHONE_11_4 110400 + * } + */ + public static int __IPHONE_11_4() { + return __IPHONE_11_4; + } + private static final int __IPHONE_12_0 = (int)120000L; + /** + * {@snippet lang=c : + * #define __IPHONE_12_0 120000 + * } + */ + public static int __IPHONE_12_0() { + return __IPHONE_12_0; + } + private static final int __IPHONE_12_1 = (int)120100L; + /** + * {@snippet lang=c : + * #define __IPHONE_12_1 120100 + * } + */ + public static int __IPHONE_12_1() { + return __IPHONE_12_1; + } + private static final int __IPHONE_12_2 = (int)120200L; + /** + * {@snippet lang=c : + * #define __IPHONE_12_2 120200 + * } + */ + public static int __IPHONE_12_2() { + return __IPHONE_12_2; + } + private static final int __IPHONE_12_3 = (int)120300L; + /** + * {@snippet lang=c : + * #define __IPHONE_12_3 120300 + * } + */ + public static int __IPHONE_12_3() { + return __IPHONE_12_3; + } + private static final int __IPHONE_12_4 = (int)120400L; + /** + * {@snippet lang=c : + * #define __IPHONE_12_4 120400 + * } + */ + public static int __IPHONE_12_4() { + return __IPHONE_12_4; + } + private static final int __IPHONE_13_0 = (int)130000L; + /** + * {@snippet lang=c : + * #define __IPHONE_13_0 130000 + * } + */ + public static int __IPHONE_13_0() { + return __IPHONE_13_0; + } + private static final int __IPHONE_13_1 = (int)130100L; + /** + * {@snippet lang=c : + * #define __IPHONE_13_1 130100 + * } + */ + public static int __IPHONE_13_1() { + return __IPHONE_13_1; + } + private static final int __IPHONE_13_2 = (int)130200L; + /** + * {@snippet lang=c : + * #define __IPHONE_13_2 130200 + * } + */ + public static int __IPHONE_13_2() { + return __IPHONE_13_2; + } + private static final int __IPHONE_13_3 = (int)130300L; + /** + * {@snippet lang=c : + * #define __IPHONE_13_3 130300 + * } + */ + public static int __IPHONE_13_3() { + return __IPHONE_13_3; + } + private static final int __IPHONE_13_4 = (int)130400L; + /** + * {@snippet lang=c : + * #define __IPHONE_13_4 130400 + * } + */ + public static int __IPHONE_13_4() { + return __IPHONE_13_4; + } + private static final int __IPHONE_13_5 = (int)130500L; + /** + * {@snippet lang=c : + * #define __IPHONE_13_5 130500 + * } + */ + public static int __IPHONE_13_5() { + return __IPHONE_13_5; + } + private static final int __IPHONE_13_6 = (int)130600L; + /** + * {@snippet lang=c : + * #define __IPHONE_13_6 130600 + * } + */ + public static int __IPHONE_13_6() { + return __IPHONE_13_6; + } + private static final int __IPHONE_13_7 = (int)130700L; + /** + * {@snippet lang=c : + * #define __IPHONE_13_7 130700 + * } + */ + public static int __IPHONE_13_7() { + return __IPHONE_13_7; + } + private static final int __IPHONE_14_0 = (int)140000L; + /** + * {@snippet lang=c : + * #define __IPHONE_14_0 140000 + * } + */ + public static int __IPHONE_14_0() { + return __IPHONE_14_0; + } + private static final int __IPHONE_14_1 = (int)140100L; + /** + * {@snippet lang=c : + * #define __IPHONE_14_1 140100 + * } + */ + public static int __IPHONE_14_1() { + return __IPHONE_14_1; + } + private static final int __IPHONE_14_2 = (int)140200L; + /** + * {@snippet lang=c : + * #define __IPHONE_14_2 140200 + * } + */ + public static int __IPHONE_14_2() { + return __IPHONE_14_2; + } + private static final int __IPHONE_14_3 = (int)140300L; + /** + * {@snippet lang=c : + * #define __IPHONE_14_3 140300 + * } + */ + public static int __IPHONE_14_3() { + return __IPHONE_14_3; + } + private static final int __IPHONE_14_5 = (int)140500L; + /** + * {@snippet lang=c : + * #define __IPHONE_14_5 140500 + * } + */ + public static int __IPHONE_14_5() { + return __IPHONE_14_5; + } + private static final int __IPHONE_14_4 = (int)140400L; + /** + * {@snippet lang=c : + * #define __IPHONE_14_4 140400 + * } + */ + public static int __IPHONE_14_4() { + return __IPHONE_14_4; + } + private static final int __IPHONE_14_6 = (int)140600L; + /** + * {@snippet lang=c : + * #define __IPHONE_14_6 140600 + * } + */ + public static int __IPHONE_14_6() { + return __IPHONE_14_6; + } + private static final int __IPHONE_14_7 = (int)140700L; + /** + * {@snippet lang=c : + * #define __IPHONE_14_7 140700 + * } + */ + public static int __IPHONE_14_7() { + return __IPHONE_14_7; + } + private static final int __IPHONE_14_8 = (int)140800L; + /** + * {@snippet lang=c : + * #define __IPHONE_14_8 140800 + * } + */ + public static int __IPHONE_14_8() { + return __IPHONE_14_8; + } + private static final int __IPHONE_15_0 = (int)150000L; + /** + * {@snippet lang=c : + * #define __IPHONE_15_0 150000 + * } + */ + public static int __IPHONE_15_0() { + return __IPHONE_15_0; + } + private static final int __IPHONE_15_1 = (int)150100L; + /** + * {@snippet lang=c : + * #define __IPHONE_15_1 150100 + * } + */ + public static int __IPHONE_15_1() { + return __IPHONE_15_1; + } + private static final int __IPHONE_15_2 = (int)150200L; + /** + * {@snippet lang=c : + * #define __IPHONE_15_2 150200 + * } + */ + public static int __IPHONE_15_2() { + return __IPHONE_15_2; + } + private static final int __IPHONE_15_3 = (int)150300L; + /** + * {@snippet lang=c : + * #define __IPHONE_15_3 150300 + * } + */ + public static int __IPHONE_15_3() { + return __IPHONE_15_3; + } + private static final int __IPHONE_15_4 = (int)150400L; + /** + * {@snippet lang=c : + * #define __IPHONE_15_4 150400 + * } + */ + public static int __IPHONE_15_4() { + return __IPHONE_15_4; + } + private static final int __IPHONE_15_5 = (int)150500L; + /** + * {@snippet lang=c : + * #define __IPHONE_15_5 150500 + * } + */ + public static int __IPHONE_15_5() { + return __IPHONE_15_5; + } + private static final int __IPHONE_15_6 = (int)150600L; + /** + * {@snippet lang=c : + * #define __IPHONE_15_6 150600 + * } + */ + public static int __IPHONE_15_6() { + return __IPHONE_15_6; + } + private static final int __IPHONE_15_7 = (int)150700L; + /** + * {@snippet lang=c : + * #define __IPHONE_15_7 150700 + * } + */ + public static int __IPHONE_15_7() { + return __IPHONE_15_7; + } + private static final int __IPHONE_15_8 = (int)150800L; + /** + * {@snippet lang=c : + * #define __IPHONE_15_8 150800 + * } + */ + public static int __IPHONE_15_8() { + return __IPHONE_15_8; + } + private static final int __IPHONE_16_0 = (int)160000L; + /** + * {@snippet lang=c : + * #define __IPHONE_16_0 160000 + * } + */ + public static int __IPHONE_16_0() { + return __IPHONE_16_0; + } + private static final int __IPHONE_16_1 = (int)160100L; + /** + * {@snippet lang=c : + * #define __IPHONE_16_1 160100 + * } + */ + public static int __IPHONE_16_1() { + return __IPHONE_16_1; + } + private static final int __IPHONE_16_2 = (int)160200L; + /** + * {@snippet lang=c : + * #define __IPHONE_16_2 160200 + * } + */ + public static int __IPHONE_16_2() { + return __IPHONE_16_2; + } + private static final int __IPHONE_16_3 = (int)160300L; + /** + * {@snippet lang=c : + * #define __IPHONE_16_3 160300 + * } + */ + public static int __IPHONE_16_3() { + return __IPHONE_16_3; + } + private static final int __IPHONE_16_4 = (int)160400L; + /** + * {@snippet lang=c : + * #define __IPHONE_16_4 160400 + * } + */ + public static int __IPHONE_16_4() { + return __IPHONE_16_4; + } + private static final int __IPHONE_16_5 = (int)160500L; + /** + * {@snippet lang=c : + * #define __IPHONE_16_5 160500 + * } + */ + public static int __IPHONE_16_5() { + return __IPHONE_16_5; + } + private static final int __IPHONE_16_6 = (int)160600L; + /** + * {@snippet lang=c : + * #define __IPHONE_16_6 160600 + * } + */ + public static int __IPHONE_16_6() { + return __IPHONE_16_6; + } + private static final int __IPHONE_16_7 = (int)160700L; + /** + * {@snippet lang=c : + * #define __IPHONE_16_7 160700 + * } + */ + public static int __IPHONE_16_7() { + return __IPHONE_16_7; + } + private static final int __IPHONE_17_0 = (int)170000L; + /** + * {@snippet lang=c : + * #define __IPHONE_17_0 170000 + * } + */ + public static int __IPHONE_17_0() { + return __IPHONE_17_0; + } + private static final int __IPHONE_17_1 = (int)170100L; + /** + * {@snippet lang=c : + * #define __IPHONE_17_1 170100 + * } + */ + public static int __IPHONE_17_1() { + return __IPHONE_17_1; + } + private static final int __IPHONE_17_2 = (int)170200L; + /** + * {@snippet lang=c : + * #define __IPHONE_17_2 170200 + * } + */ + public static int __IPHONE_17_2() { + return __IPHONE_17_2; + } + private static final int __IPHONE_17_3 = (int)170300L; + /** + * {@snippet lang=c : + * #define __IPHONE_17_3 170300 + * } + */ + public static int __IPHONE_17_3() { + return __IPHONE_17_3; + } + private static final int __IPHONE_17_4 = (int)170400L; + /** + * {@snippet lang=c : + * #define __IPHONE_17_4 170400 + * } + */ + public static int __IPHONE_17_4() { + return __IPHONE_17_4; + } + private static final int __IPHONE_17_5 = (int)170500L; + /** + * {@snippet lang=c : + * #define __IPHONE_17_5 170500 + * } + */ + public static int __IPHONE_17_5() { + return __IPHONE_17_5; + } + private static final int __WATCHOS_1_0 = (int)10000L; + /** + * {@snippet lang=c : + * #define __WATCHOS_1_0 10000 + * } + */ + public static int __WATCHOS_1_0() { + return __WATCHOS_1_0; + } + private static final int __WATCHOS_2_0 = (int)20000L; + /** + * {@snippet lang=c : + * #define __WATCHOS_2_0 20000 + * } + */ + public static int __WATCHOS_2_0() { + return __WATCHOS_2_0; + } + private static final int __WATCHOS_2_1 = (int)20100L; + /** + * {@snippet lang=c : + * #define __WATCHOS_2_1 20100 + * } + */ + public static int __WATCHOS_2_1() { + return __WATCHOS_2_1; + } + private static final int __WATCHOS_2_2 = (int)20200L; + /** + * {@snippet lang=c : + * #define __WATCHOS_2_2 20200 + * } + */ + public static int __WATCHOS_2_2() { + return __WATCHOS_2_2; + } + private static final int __WATCHOS_3_0 = (int)30000L; + /** + * {@snippet lang=c : + * #define __WATCHOS_3_0 30000 + * } + */ + public static int __WATCHOS_3_0() { + return __WATCHOS_3_0; + } + private static final int __WATCHOS_3_1 = (int)30100L; + /** + * {@snippet lang=c : + * #define __WATCHOS_3_1 30100 + * } + */ + public static int __WATCHOS_3_1() { + return __WATCHOS_3_1; + } + private static final int __WATCHOS_3_1_1 = (int)30101L; + /** + * {@snippet lang=c : + * #define __WATCHOS_3_1_1 30101 + * } + */ + public static int __WATCHOS_3_1_1() { + return __WATCHOS_3_1_1; + } + private static final int __WATCHOS_3_2 = (int)30200L; + /** + * {@snippet lang=c : + * #define __WATCHOS_3_2 30200 + * } + */ + public static int __WATCHOS_3_2() { + return __WATCHOS_3_2; + } + private static final int __WATCHOS_4_0 = (int)40000L; + /** + * {@snippet lang=c : + * #define __WATCHOS_4_0 40000 + * } + */ + public static int __WATCHOS_4_0() { + return __WATCHOS_4_0; + } + private static final int __WATCHOS_4_1 = (int)40100L; + /** + * {@snippet lang=c : + * #define __WATCHOS_4_1 40100 + * } + */ + public static int __WATCHOS_4_1() { + return __WATCHOS_4_1; + } + private static final int __WATCHOS_4_2 = (int)40200L; + /** + * {@snippet lang=c : + * #define __WATCHOS_4_2 40200 + * } + */ + public static int __WATCHOS_4_2() { + return __WATCHOS_4_2; + } + private static final int __WATCHOS_4_3 = (int)40300L; + /** + * {@snippet lang=c : + * #define __WATCHOS_4_3 40300 + * } + */ + public static int __WATCHOS_4_3() { + return __WATCHOS_4_3; + } + private static final int __WATCHOS_5_0 = (int)50000L; + /** + * {@snippet lang=c : + * #define __WATCHOS_5_0 50000 + * } + */ + public static int __WATCHOS_5_0() { + return __WATCHOS_5_0; + } + private static final int __WATCHOS_5_1 = (int)50100L; + /** + * {@snippet lang=c : + * #define __WATCHOS_5_1 50100 + * } + */ + public static int __WATCHOS_5_1() { + return __WATCHOS_5_1; + } + private static final int __WATCHOS_5_2 = (int)50200L; + /** + * {@snippet lang=c : + * #define __WATCHOS_5_2 50200 + * } + */ + public static int __WATCHOS_5_2() { + return __WATCHOS_5_2; + } + private static final int __WATCHOS_5_3 = (int)50300L; + /** + * {@snippet lang=c : + * #define __WATCHOS_5_3 50300 + * } + */ + public static int __WATCHOS_5_3() { + return __WATCHOS_5_3; + } + private static final int __WATCHOS_6_0 = (int)60000L; + /** + * {@snippet lang=c : + * #define __WATCHOS_6_0 60000 + * } + */ + public static int __WATCHOS_6_0() { + return __WATCHOS_6_0; + } + private static final int __WATCHOS_6_1 = (int)60100L; + /** + * {@snippet lang=c : + * #define __WATCHOS_6_1 60100 + * } + */ + public static int __WATCHOS_6_1() { + return __WATCHOS_6_1; + } + private static final int __WATCHOS_6_2 = (int)60200L; + /** + * {@snippet lang=c : + * #define __WATCHOS_6_2 60200 + * } + */ + public static int __WATCHOS_6_2() { + return __WATCHOS_6_2; + } + private static final int __WATCHOS_7_0 = (int)70000L; + /** + * {@snippet lang=c : + * #define __WATCHOS_7_0 70000 + * } + */ + public static int __WATCHOS_7_0() { + return __WATCHOS_7_0; + } + private static final int __WATCHOS_7_1 = (int)70100L; + /** + * {@snippet lang=c : + * #define __WATCHOS_7_1 70100 + * } + */ + public static int __WATCHOS_7_1() { + return __WATCHOS_7_1; + } + private static final int __WATCHOS_7_2 = (int)70200L; + /** + * {@snippet lang=c : + * #define __WATCHOS_7_2 70200 + * } + */ + public static int __WATCHOS_7_2() { + return __WATCHOS_7_2; + } + private static final int __WATCHOS_7_3 = (int)70300L; + /** + * {@snippet lang=c : + * #define __WATCHOS_7_3 70300 + * } + */ + public static int __WATCHOS_7_3() { + return __WATCHOS_7_3; + } + private static final int __WATCHOS_7_4 = (int)70400L; + /** + * {@snippet lang=c : + * #define __WATCHOS_7_4 70400 + * } + */ + public static int __WATCHOS_7_4() { + return __WATCHOS_7_4; + } + private static final int __WATCHOS_7_5 = (int)70500L; + /** + * {@snippet lang=c : + * #define __WATCHOS_7_5 70500 + * } + */ + public static int __WATCHOS_7_5() { + return __WATCHOS_7_5; + } + private static final int __WATCHOS_7_6 = (int)70600L; + /** + * {@snippet lang=c : + * #define __WATCHOS_7_6 70600 + * } + */ + public static int __WATCHOS_7_6() { + return __WATCHOS_7_6; + } + private static final int __WATCHOS_8_0 = (int)80000L; + /** + * {@snippet lang=c : + * #define __WATCHOS_8_0 80000 + * } + */ + public static int __WATCHOS_8_0() { + return __WATCHOS_8_0; + } + private static final int __WATCHOS_8_1 = (int)80100L; + /** + * {@snippet lang=c : + * #define __WATCHOS_8_1 80100 + * } + */ + public static int __WATCHOS_8_1() { + return __WATCHOS_8_1; + } + private static final int __WATCHOS_8_3 = (int)80300L; + /** + * {@snippet lang=c : + * #define __WATCHOS_8_3 80300 + * } + */ + public static int __WATCHOS_8_3() { + return __WATCHOS_8_3; + } + private static final int __WATCHOS_8_4 = (int)80400L; + /** + * {@snippet lang=c : + * #define __WATCHOS_8_4 80400 + * } + */ + public static int __WATCHOS_8_4() { + return __WATCHOS_8_4; + } + private static final int __WATCHOS_8_5 = (int)80500L; + /** + * {@snippet lang=c : + * #define __WATCHOS_8_5 80500 + * } + */ + public static int __WATCHOS_8_5() { + return __WATCHOS_8_5; + } + private static final int __WATCHOS_8_6 = (int)80600L; + /** + * {@snippet lang=c : + * #define __WATCHOS_8_6 80600 + * } + */ + public static int __WATCHOS_8_6() { + return __WATCHOS_8_6; + } + private static final int __WATCHOS_8_7 = (int)80700L; + /** + * {@snippet lang=c : + * #define __WATCHOS_8_7 80700 + * } + */ + public static int __WATCHOS_8_7() { + return __WATCHOS_8_7; + } + private static final int __WATCHOS_8_8 = (int)80800L; + /** + * {@snippet lang=c : + * #define __WATCHOS_8_8 80800 + * } + */ + public static int __WATCHOS_8_8() { + return __WATCHOS_8_8; + } + private static final int __WATCHOS_9_0 = (int)90000L; + /** + * {@snippet lang=c : + * #define __WATCHOS_9_0 90000 + * } + */ + public static int __WATCHOS_9_0() { + return __WATCHOS_9_0; + } + private static final int __WATCHOS_9_1 = (int)90100L; + /** + * {@snippet lang=c : + * #define __WATCHOS_9_1 90100 + * } + */ + public static int __WATCHOS_9_1() { + return __WATCHOS_9_1; + } + private static final int __WATCHOS_9_2 = (int)90200L; + /** + * {@snippet lang=c : + * #define __WATCHOS_9_2 90200 + * } + */ + public static int __WATCHOS_9_2() { + return __WATCHOS_9_2; + } + private static final int __WATCHOS_9_3 = (int)90300L; + /** + * {@snippet lang=c : + * #define __WATCHOS_9_3 90300 + * } + */ + public static int __WATCHOS_9_3() { + return __WATCHOS_9_3; + } + private static final int __WATCHOS_9_4 = (int)90400L; + /** + * {@snippet lang=c : + * #define __WATCHOS_9_4 90400 + * } + */ + public static int __WATCHOS_9_4() { + return __WATCHOS_9_4; + } + private static final int __WATCHOS_9_5 = (int)90500L; + /** + * {@snippet lang=c : + * #define __WATCHOS_9_5 90500 + * } + */ + public static int __WATCHOS_9_5() { + return __WATCHOS_9_5; + } + private static final int __WATCHOS_9_6 = (int)90600L; + /** + * {@snippet lang=c : + * #define __WATCHOS_9_6 90600 + * } + */ + public static int __WATCHOS_9_6() { + return __WATCHOS_9_6; + } + private static final int __WATCHOS_10_0 = (int)100000L; + /** + * {@snippet lang=c : + * #define __WATCHOS_10_0 100000 + * } + */ + public static int __WATCHOS_10_0() { + return __WATCHOS_10_0; + } + private static final int __WATCHOS_10_1 = (int)100100L; + /** + * {@snippet lang=c : + * #define __WATCHOS_10_1 100100 + * } + */ + public static int __WATCHOS_10_1() { + return __WATCHOS_10_1; + } + private static final int __WATCHOS_10_2 = (int)100200L; + /** + * {@snippet lang=c : + * #define __WATCHOS_10_2 100200 + * } + */ + public static int __WATCHOS_10_2() { + return __WATCHOS_10_2; + } + private static final int __WATCHOS_10_3 = (int)100300L; + /** + * {@snippet lang=c : + * #define __WATCHOS_10_3 100300 + * } + */ + public static int __WATCHOS_10_3() { + return __WATCHOS_10_3; + } + private static final int __WATCHOS_10_4 = (int)100400L; + /** + * {@snippet lang=c : + * #define __WATCHOS_10_4 100400 + * } + */ + public static int __WATCHOS_10_4() { + return __WATCHOS_10_4; + } + private static final int __WATCHOS_10_5 = (int)100500L; + /** + * {@snippet lang=c : + * #define __WATCHOS_10_5 100500 + * } + */ + public static int __WATCHOS_10_5() { + return __WATCHOS_10_5; + } + private static final int __TVOS_9_0 = (int)90000L; + /** + * {@snippet lang=c : + * #define __TVOS_9_0 90000 + * } + */ + public static int __TVOS_9_0() { + return __TVOS_9_0; + } + private static final int __TVOS_9_1 = (int)90100L; + /** + * {@snippet lang=c : + * #define __TVOS_9_1 90100 + * } + */ + public static int __TVOS_9_1() { + return __TVOS_9_1; + } + private static final int __TVOS_9_2 = (int)90200L; + /** + * {@snippet lang=c : + * #define __TVOS_9_2 90200 + * } + */ + public static int __TVOS_9_2() { + return __TVOS_9_2; + } + private static final int __TVOS_10_0 = (int)100000L; + /** + * {@snippet lang=c : + * #define __TVOS_10_0 100000 + * } + */ + public static int __TVOS_10_0() { + return __TVOS_10_0; + } + private static final int __TVOS_10_0_1 = (int)100001L; + /** + * {@snippet lang=c : + * #define __TVOS_10_0_1 100001 + * } + */ + public static int __TVOS_10_0_1() { + return __TVOS_10_0_1; + } + private static final int __TVOS_10_1 = (int)100100L; + /** + * {@snippet lang=c : + * #define __TVOS_10_1 100100 + * } + */ + public static int __TVOS_10_1() { + return __TVOS_10_1; + } + private static final int __TVOS_10_2 = (int)100200L; + /** + * {@snippet lang=c : + * #define __TVOS_10_2 100200 + * } + */ + public static int __TVOS_10_2() { + return __TVOS_10_2; + } + private static final int __TVOS_11_0 = (int)110000L; + /** + * {@snippet lang=c : + * #define __TVOS_11_0 110000 + * } + */ + public static int __TVOS_11_0() { + return __TVOS_11_0; + } + private static final int __TVOS_11_1 = (int)110100L; + /** + * {@snippet lang=c : + * #define __TVOS_11_1 110100 + * } + */ + public static int __TVOS_11_1() { + return __TVOS_11_1; + } + private static final int __TVOS_11_2 = (int)110200L; + /** + * {@snippet lang=c : + * #define __TVOS_11_2 110200 + * } + */ + public static int __TVOS_11_2() { + return __TVOS_11_2; + } + private static final int __TVOS_11_3 = (int)110300L; + /** + * {@snippet lang=c : + * #define __TVOS_11_3 110300 + * } + */ + public static int __TVOS_11_3() { + return __TVOS_11_3; + } + private static final int __TVOS_11_4 = (int)110400L; + /** + * {@snippet lang=c : + * #define __TVOS_11_4 110400 + * } + */ + public static int __TVOS_11_4() { + return __TVOS_11_4; + } + private static final int __TVOS_12_0 = (int)120000L; + /** + * {@snippet lang=c : + * #define __TVOS_12_0 120000 + * } + */ + public static int __TVOS_12_0() { + return __TVOS_12_0; + } + private static final int __TVOS_12_1 = (int)120100L; + /** + * {@snippet lang=c : + * #define __TVOS_12_1 120100 + * } + */ + public static int __TVOS_12_1() { + return __TVOS_12_1; + } + private static final int __TVOS_12_2 = (int)120200L; + /** + * {@snippet lang=c : + * #define __TVOS_12_2 120200 + * } + */ + public static int __TVOS_12_2() { + return __TVOS_12_2; + } + private static final int __TVOS_12_3 = (int)120300L; + /** + * {@snippet lang=c : + * #define __TVOS_12_3 120300 + * } + */ + public static int __TVOS_12_3() { + return __TVOS_12_3; + } + private static final int __TVOS_12_4 = (int)120400L; + /** + * {@snippet lang=c : + * #define __TVOS_12_4 120400 + * } + */ + public static int __TVOS_12_4() { + return __TVOS_12_4; + } + private static final int __TVOS_13_0 = (int)130000L; + /** + * {@snippet lang=c : + * #define __TVOS_13_0 130000 + * } + */ + public static int __TVOS_13_0() { + return __TVOS_13_0; + } + private static final int __TVOS_13_2 = (int)130200L; + /** + * {@snippet lang=c : + * #define __TVOS_13_2 130200 + * } + */ + public static int __TVOS_13_2() { + return __TVOS_13_2; + } + private static final int __TVOS_13_3 = (int)130300L; + /** + * {@snippet lang=c : + * #define __TVOS_13_3 130300 + * } + */ + public static int __TVOS_13_3() { + return __TVOS_13_3; + } + private static final int __TVOS_13_4 = (int)130400L; + /** + * {@snippet lang=c : + * #define __TVOS_13_4 130400 + * } + */ + public static int __TVOS_13_4() { + return __TVOS_13_4; + } + private static final int __TVOS_14_0 = (int)140000L; + /** + * {@snippet lang=c : + * #define __TVOS_14_0 140000 + * } + */ + public static int __TVOS_14_0() { + return __TVOS_14_0; + } + private static final int __TVOS_14_1 = (int)140100L; + /** + * {@snippet lang=c : + * #define __TVOS_14_1 140100 + * } + */ + public static int __TVOS_14_1() { + return __TVOS_14_1; + } + private static final int __TVOS_14_2 = (int)140200L; + /** + * {@snippet lang=c : + * #define __TVOS_14_2 140200 + * } + */ + public static int __TVOS_14_2() { + return __TVOS_14_2; + } + private static final int __TVOS_14_3 = (int)140300L; + /** + * {@snippet lang=c : + * #define __TVOS_14_3 140300 + * } + */ + public static int __TVOS_14_3() { + return __TVOS_14_3; + } + private static final int __TVOS_14_5 = (int)140500L; + /** + * {@snippet lang=c : + * #define __TVOS_14_5 140500 + * } + */ + public static int __TVOS_14_5() { + return __TVOS_14_5; + } + private static final int __TVOS_14_6 = (int)140600L; + /** + * {@snippet lang=c : + * #define __TVOS_14_6 140600 + * } + */ + public static int __TVOS_14_6() { + return __TVOS_14_6; + } + private static final int __TVOS_14_7 = (int)140700L; + /** + * {@snippet lang=c : + * #define __TVOS_14_7 140700 + * } + */ + public static int __TVOS_14_7() { + return __TVOS_14_7; + } + private static final int __TVOS_15_0 = (int)150000L; + /** + * {@snippet lang=c : + * #define __TVOS_15_0 150000 + * } + */ + public static int __TVOS_15_0() { + return __TVOS_15_0; + } + private static final int __TVOS_15_1 = (int)150100L; + /** + * {@snippet lang=c : + * #define __TVOS_15_1 150100 + * } + */ + public static int __TVOS_15_1() { + return __TVOS_15_1; + } + private static final int __TVOS_15_2 = (int)150200L; + /** + * {@snippet lang=c : + * #define __TVOS_15_2 150200 + * } + */ + public static int __TVOS_15_2() { + return __TVOS_15_2; + } + private static final int __TVOS_15_3 = (int)150300L; + /** + * {@snippet lang=c : + * #define __TVOS_15_3 150300 + * } + */ + public static int __TVOS_15_3() { + return __TVOS_15_3; + } + private static final int __TVOS_15_4 = (int)150400L; + /** + * {@snippet lang=c : + * #define __TVOS_15_4 150400 + * } + */ + public static int __TVOS_15_4() { + return __TVOS_15_4; + } + private static final int __TVOS_15_5 = (int)150500L; + /** + * {@snippet lang=c : + * #define __TVOS_15_5 150500 + * } + */ + public static int __TVOS_15_5() { + return __TVOS_15_5; + } + private static final int __TVOS_15_6 = (int)150600L; + /** + * {@snippet lang=c : + * #define __TVOS_15_6 150600 + * } + */ + public static int __TVOS_15_6() { + return __TVOS_15_6; + } + private static final int __TVOS_16_0 = (int)160000L; + /** + * {@snippet lang=c : + * #define __TVOS_16_0 160000 + * } + */ + public static int __TVOS_16_0() { + return __TVOS_16_0; + } + private static final int __TVOS_16_1 = (int)160100L; + /** + * {@snippet lang=c : + * #define __TVOS_16_1 160100 + * } + */ + public static int __TVOS_16_1() { + return __TVOS_16_1; + } + private static final int __TVOS_16_2 = (int)160200L; + /** + * {@snippet lang=c : + * #define __TVOS_16_2 160200 + * } + */ + public static int __TVOS_16_2() { + return __TVOS_16_2; + } + private static final int __TVOS_16_3 = (int)160300L; + /** + * {@snippet lang=c : + * #define __TVOS_16_3 160300 + * } + */ + public static int __TVOS_16_3() { + return __TVOS_16_3; + } + private static final int __TVOS_16_4 = (int)160400L; + /** + * {@snippet lang=c : + * #define __TVOS_16_4 160400 + * } + */ + public static int __TVOS_16_4() { + return __TVOS_16_4; + } + private static final int __TVOS_16_5 = (int)160500L; + /** + * {@snippet lang=c : + * #define __TVOS_16_5 160500 + * } + */ + public static int __TVOS_16_5() { + return __TVOS_16_5; + } + private static final int __TVOS_16_6 = (int)160600L; + /** + * {@snippet lang=c : + * #define __TVOS_16_6 160600 + * } + */ + public static int __TVOS_16_6() { + return __TVOS_16_6; + } + private static final int __TVOS_17_0 = (int)170000L; + /** + * {@snippet lang=c : + * #define __TVOS_17_0 170000 + * } + */ + public static int __TVOS_17_0() { + return __TVOS_17_0; + } + private static final int __TVOS_17_1 = (int)170100L; + /** + * {@snippet lang=c : + * #define __TVOS_17_1 170100 + * } + */ + public static int __TVOS_17_1() { + return __TVOS_17_1; + } + private static final int __TVOS_17_2 = (int)170200L; + /** + * {@snippet lang=c : + * #define __TVOS_17_2 170200 + * } + */ + public static int __TVOS_17_2() { + return __TVOS_17_2; + } + private static final int __TVOS_17_3 = (int)170300L; + /** + * {@snippet lang=c : + * #define __TVOS_17_3 170300 + * } + */ + public static int __TVOS_17_3() { + return __TVOS_17_3; + } + private static final int __TVOS_17_4 = (int)170400L; + /** + * {@snippet lang=c : + * #define __TVOS_17_4 170400 + * } + */ + public static int __TVOS_17_4() { + return __TVOS_17_4; + } + private static final int __TVOS_17_5 = (int)170500L; + /** + * {@snippet lang=c : + * #define __TVOS_17_5 170500 + * } + */ + public static int __TVOS_17_5() { + return __TVOS_17_5; + } + private static final int __BRIDGEOS_2_0 = (int)20000L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_2_0 20000 + * } + */ + public static int __BRIDGEOS_2_0() { + return __BRIDGEOS_2_0; + } + private static final int __BRIDGEOS_3_0 = (int)30000L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_3_0 30000 + * } + */ + public static int __BRIDGEOS_3_0() { + return __BRIDGEOS_3_0; + } + private static final int __BRIDGEOS_3_1 = (int)30100L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_3_1 30100 + * } + */ + public static int __BRIDGEOS_3_1() { + return __BRIDGEOS_3_1; + } + private static final int __BRIDGEOS_3_4 = (int)30400L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_3_4 30400 + * } + */ + public static int __BRIDGEOS_3_4() { + return __BRIDGEOS_3_4; + } + private static final int __BRIDGEOS_4_0 = (int)40000L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_4_0 40000 + * } + */ + public static int __BRIDGEOS_4_0() { + return __BRIDGEOS_4_0; + } + private static final int __BRIDGEOS_4_1 = (int)40100L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_4_1 40100 + * } + */ + public static int __BRIDGEOS_4_1() { + return __BRIDGEOS_4_1; + } + private static final int __BRIDGEOS_5_0 = (int)50000L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_5_0 50000 + * } + */ + public static int __BRIDGEOS_5_0() { + return __BRIDGEOS_5_0; + } + private static final int __BRIDGEOS_5_1 = (int)50100L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_5_1 50100 + * } + */ + public static int __BRIDGEOS_5_1() { + return __BRIDGEOS_5_1; + } + private static final int __BRIDGEOS_5_3 = (int)50300L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_5_3 50300 + * } + */ + public static int __BRIDGEOS_5_3() { + return __BRIDGEOS_5_3; + } + private static final int __BRIDGEOS_6_0 = (int)60000L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_6_0 60000 + * } + */ + public static int __BRIDGEOS_6_0() { + return __BRIDGEOS_6_0; + } + private static final int __BRIDGEOS_6_2 = (int)60200L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_6_2 60200 + * } + */ + public static int __BRIDGEOS_6_2() { + return __BRIDGEOS_6_2; + } + private static final int __BRIDGEOS_6_4 = (int)60400L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_6_4 60400 + * } + */ + public static int __BRIDGEOS_6_4() { + return __BRIDGEOS_6_4; + } + private static final int __BRIDGEOS_6_5 = (int)60500L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_6_5 60500 + * } + */ + public static int __BRIDGEOS_6_5() { + return __BRIDGEOS_6_5; + } + private static final int __BRIDGEOS_6_6 = (int)60600L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_6_6 60600 + * } + */ + public static int __BRIDGEOS_6_6() { + return __BRIDGEOS_6_6; + } + private static final int __BRIDGEOS_7_0 = (int)70000L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_7_0 70000 + * } + */ + public static int __BRIDGEOS_7_0() { + return __BRIDGEOS_7_0; + } + private static final int __BRIDGEOS_7_1 = (int)70100L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_7_1 70100 + * } + */ + public static int __BRIDGEOS_7_1() { + return __BRIDGEOS_7_1; + } + private static final int __BRIDGEOS_7_2 = (int)70200L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_7_2 70200 + * } + */ + public static int __BRIDGEOS_7_2() { + return __BRIDGEOS_7_2; + } + private static final int __BRIDGEOS_7_3 = (int)70300L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_7_3 70300 + * } + */ + public static int __BRIDGEOS_7_3() { + return __BRIDGEOS_7_3; + } + private static final int __BRIDGEOS_7_4 = (int)70400L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_7_4 70400 + * } + */ + public static int __BRIDGEOS_7_4() { + return __BRIDGEOS_7_4; + } + private static final int __BRIDGEOS_7_6 = (int)70600L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_7_6 70600 + * } + */ + public static int __BRIDGEOS_7_6() { + return __BRIDGEOS_7_6; + } + private static final int __BRIDGEOS_8_0 = (int)80000L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_8_0 80000 + * } + */ + public static int __BRIDGEOS_8_0() { + return __BRIDGEOS_8_0; + } + private static final int __BRIDGEOS_8_1 = (int)80100L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_8_1 80100 + * } + */ + public static int __BRIDGEOS_8_1() { + return __BRIDGEOS_8_1; + } + private static final int __BRIDGEOS_8_2 = (int)80200L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_8_2 80200 + * } + */ + public static int __BRIDGEOS_8_2() { + return __BRIDGEOS_8_2; + } + private static final int __BRIDGEOS_8_3 = (int)80300L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_8_3 80300 + * } + */ + public static int __BRIDGEOS_8_3() { + return __BRIDGEOS_8_3; + } + private static final int __BRIDGEOS_8_4 = (int)80400L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_8_4 80400 + * } + */ + public static int __BRIDGEOS_8_4() { + return __BRIDGEOS_8_4; + } + private static final int __BRIDGEOS_8_5 = (int)80500L; + /** + * {@snippet lang=c : + * #define __BRIDGEOS_8_5 80500 + * } + */ + public static int __BRIDGEOS_8_5() { + return __BRIDGEOS_8_5; + } + private static final int __DRIVERKIT_19_0 = (int)190000L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_19_0 190000 + * } + */ + public static int __DRIVERKIT_19_0() { + return __DRIVERKIT_19_0; + } + private static final int __DRIVERKIT_20_0 = (int)200000L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_20_0 200000 + * } + */ + public static int __DRIVERKIT_20_0() { + return __DRIVERKIT_20_0; + } + private static final int __DRIVERKIT_21_0 = (int)210000L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_21_0 210000 + * } + */ + public static int __DRIVERKIT_21_0() { + return __DRIVERKIT_21_0; + } + private static final int __DRIVERKIT_22_0 = (int)220000L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_22_0 220000 + * } + */ + public static int __DRIVERKIT_22_0() { + return __DRIVERKIT_22_0; + } + private static final int __DRIVERKIT_22_4 = (int)220400L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_22_4 220400 + * } + */ + public static int __DRIVERKIT_22_4() { + return __DRIVERKIT_22_4; + } + private static final int __DRIVERKIT_22_5 = (int)220500L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_22_5 220500 + * } + */ + public static int __DRIVERKIT_22_5() { + return __DRIVERKIT_22_5; + } + private static final int __DRIVERKIT_22_6 = (int)220600L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_22_6 220600 + * } + */ + public static int __DRIVERKIT_22_6() { + return __DRIVERKIT_22_6; + } + private static final int __DRIVERKIT_23_0 = (int)230000L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_23_0 230000 + * } + */ + public static int __DRIVERKIT_23_0() { + return __DRIVERKIT_23_0; + } + private static final int __DRIVERKIT_23_1 = (int)230100L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_23_1 230100 + * } + */ + public static int __DRIVERKIT_23_1() { + return __DRIVERKIT_23_1; + } + private static final int __DRIVERKIT_23_2 = (int)230200L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_23_2 230200 + * } + */ + public static int __DRIVERKIT_23_2() { + return __DRIVERKIT_23_2; + } + private static final int __DRIVERKIT_23_3 = (int)230300L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_23_3 230300 + * } + */ + public static int __DRIVERKIT_23_3() { + return __DRIVERKIT_23_3; + } + private static final int __DRIVERKIT_23_4 = (int)230400L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_23_4 230400 + * } + */ + public static int __DRIVERKIT_23_4() { + return __DRIVERKIT_23_4; + } + private static final int __DRIVERKIT_23_5 = (int)230500L; + /** + * {@snippet lang=c : + * #define __DRIVERKIT_23_5 230500 + * } + */ + public static int __DRIVERKIT_23_5() { + return __DRIVERKIT_23_5; + } + private static final int __VISIONOS_1_0 = (int)10000L; + /** + * {@snippet lang=c : + * #define __VISIONOS_1_0 10000 + * } + */ + public static int __VISIONOS_1_0() { + return __VISIONOS_1_0; + } + private static final int __VISIONOS_1_1 = (int)10100L; + /** + * {@snippet lang=c : + * #define __VISIONOS_1_1 10100 + * } + */ + public static int __VISIONOS_1_1() { + return __VISIONOS_1_1; + } + private static final int __VISIONOS_1_2 = (int)10200L; + /** + * {@snippet lang=c : + * #define __VISIONOS_1_2 10200 + * } + */ + public static int __VISIONOS_1_2() { + return __VISIONOS_1_2; + } + private static final int __ENABLE_LEGACY_MAC_AVAILABILITY = (int)1L; + /** + * {@snippet lang=c : + * #define __ENABLE_LEGACY_MAC_AVAILABILITY 1 + * } + */ + public static int __ENABLE_LEGACY_MAC_AVAILABILITY() { + return __ENABLE_LEGACY_MAC_AVAILABILITY; + } + private static final int _FORTIFY_SOURCE = (int)2L; + /** + * {@snippet lang=c : + * #define _FORTIFY_SOURCE 2 + * } + */ + public static int _FORTIFY_SOURCE() { + return _FORTIFY_SOURCE; + } + private static final int RENAME_SECLUDE = (int)1L; + /** + * {@snippet lang=c : + * #define RENAME_SECLUDE 1 + * } + */ + public static int RENAME_SECLUDE() { + return RENAME_SECLUDE; + } + private static final int RENAME_SWAP = (int)2L; + /** + * {@snippet lang=c : + * #define RENAME_SWAP 2 + * } + */ + public static int RENAME_SWAP() { + return RENAME_SWAP; + } + private static final int RENAME_EXCL = (int)4L; + /** + * {@snippet lang=c : + * #define RENAME_EXCL 4 + * } + */ + public static int RENAME_EXCL() { + return RENAME_EXCL; + } + private static final int RENAME_RESERVED1 = (int)8L; + /** + * {@snippet lang=c : + * #define RENAME_RESERVED1 8 + * } + */ + public static int RENAME_RESERVED1() { + return RENAME_RESERVED1; + } + private static final int RENAME_NOFOLLOW_ANY = (int)16L; + /** + * {@snippet lang=c : + * #define RENAME_NOFOLLOW_ANY 16 + * } + */ + public static int RENAME_NOFOLLOW_ANY() { + return RENAME_NOFOLLOW_ANY; + } + private static final int SEEK_SET = (int)0L; + /** + * {@snippet lang=c : + * #define SEEK_SET 0 + * } + */ + public static int SEEK_SET() { + return SEEK_SET; + } + private static final int SEEK_CUR = (int)1L; + /** + * {@snippet lang=c : + * #define SEEK_CUR 1 + * } + */ + public static int SEEK_CUR() { + return SEEK_CUR; + } + private static final int SEEK_END = (int)2L; + /** + * {@snippet lang=c : + * #define SEEK_END 2 + * } + */ + public static int SEEK_END() { + return SEEK_END; + } + private static final int SEEK_HOLE = (int)3L; + /** + * {@snippet lang=c : + * #define SEEK_HOLE 3 + * } + */ + public static int SEEK_HOLE() { + return SEEK_HOLE; + } + private static final int SEEK_DATA = (int)4L; + /** + * {@snippet lang=c : + * #define SEEK_DATA 4 + * } + */ + public static int SEEK_DATA() { + return SEEK_DATA; + } + private static final int __SLBF = (int)1L; + /** + * {@snippet lang=c : + * #define __SLBF 1 + * } + */ + public static int __SLBF() { + return __SLBF; + } + private static final int __SNBF = (int)2L; + /** + * {@snippet lang=c : + * #define __SNBF 2 + * } + */ + public static int __SNBF() { + return __SNBF; + } + private static final int __SRD = (int)4L; + /** + * {@snippet lang=c : + * #define __SRD 4 + * } + */ + public static int __SRD() { + return __SRD; + } + private static final int __SWR = (int)8L; + /** + * {@snippet lang=c : + * #define __SWR 8 + * } + */ + public static int __SWR() { + return __SWR; + } + private static final int __SRW = (int)16L; + /** + * {@snippet lang=c : + * #define __SRW 16 + * } + */ + public static int __SRW() { + return __SRW; + } + private static final int __SEOF = (int)32L; + /** + * {@snippet lang=c : + * #define __SEOF 32 + * } + */ + public static int __SEOF() { + return __SEOF; + } + private static final int __SERR = (int)64L; + /** + * {@snippet lang=c : + * #define __SERR 64 + * } + */ + public static int __SERR() { + return __SERR; + } + private static final int __SMBF = (int)128L; + /** + * {@snippet lang=c : + * #define __SMBF 128 + * } + */ + public static int __SMBF() { + return __SMBF; + } + private static final int __SAPP = (int)256L; + /** + * {@snippet lang=c : + * #define __SAPP 256 + * } + */ + public static int __SAPP() { + return __SAPP; + } + private static final int __SSTR = (int)512L; + /** + * {@snippet lang=c : + * #define __SSTR 512 + * } + */ + public static int __SSTR() { + return __SSTR; + } + private static final int __SOPT = (int)1024L; + /** + * {@snippet lang=c : + * #define __SOPT 1024 + * } + */ + public static int __SOPT() { + return __SOPT; + } + private static final int __SNPT = (int)2048L; + /** + * {@snippet lang=c : + * #define __SNPT 2048 + * } + */ + public static int __SNPT() { + return __SNPT; + } + private static final int __SOFF = (int)4096L; + /** + * {@snippet lang=c : + * #define __SOFF 4096 + * } + */ + public static int __SOFF() { + return __SOFF; + } + private static final int __SMOD = (int)8192L; + /** + * {@snippet lang=c : + * #define __SMOD 8192 + * } + */ + public static int __SMOD() { + return __SMOD; + } + private static final int __SALC = (int)16384L; + /** + * {@snippet lang=c : + * #define __SALC 16384 + * } + */ + public static int __SALC() { + return __SALC; + } + private static final int __SIGN = (int)32768L; + /** + * {@snippet lang=c : + * #define __SIGN 32768 + * } + */ + public static int __SIGN() { + return __SIGN; + } + private static final int _IOFBF = (int)0L; + /** + * {@snippet lang=c : + * #define _IOFBF 0 + * } + */ + public static int _IOFBF() { + return _IOFBF; + } + private static final int _IOLBF = (int)1L; + /** + * {@snippet lang=c : + * #define _IOLBF 1 + * } + */ + public static int _IOLBF() { + return _IOLBF; + } + private static final int _IONBF = (int)2L; + /** + * {@snippet lang=c : + * #define _IONBF 2 + * } + */ + public static int _IONBF() { + return _IONBF; + } + private static final int BUFSIZ = (int)1024L; + /** + * {@snippet lang=c : + * #define BUFSIZ 1024 + * } + */ + public static int BUFSIZ() { + return BUFSIZ; + } + private static final int FOPEN_MAX = (int)20L; + /** + * {@snippet lang=c : + * #define FOPEN_MAX 20 + * } + */ + public static int FOPEN_MAX() { + return FOPEN_MAX; + } + private static final int FILENAME_MAX = (int)1024L; + /** + * {@snippet lang=c : + * #define FILENAME_MAX 1024 + * } + */ + public static int FILENAME_MAX() { + return FILENAME_MAX; + } + private static final int L_tmpnam = (int)1024L; + /** + * {@snippet lang=c : + * #define L_tmpnam 1024 + * } + */ + public static int L_tmpnam() { + return L_tmpnam; + } + private static final int TMP_MAX = (int)308915776L; + /** + * {@snippet lang=c : + * #define TMP_MAX 308915776 + * } + */ + public static int TMP_MAX() { + return TMP_MAX; + } + private static final int L_ctermid = (int)1024L; + /** + * {@snippet lang=c : + * #define L_ctermid 1024 + * } + */ + public static int L_ctermid() { + return L_ctermid; + } + private static final int _USE_FORTIFY_LEVEL = (int)2L; + /** + * {@snippet lang=c : + * #define _USE_FORTIFY_LEVEL 2 + * } + */ + public static int _USE_FORTIFY_LEVEL() { + return _USE_FORTIFY_LEVEL; + } + + private static class __assert_rtn { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("__assert_rtn"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void __assert_rtn(const char *, const char *, int, const char *) + * } + */ + public static FunctionDescriptor __assert_rtn$descriptor() { + return __assert_rtn.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void __assert_rtn(const char *, const char *, int, const char *) + * } + */ + public static MethodHandle __assert_rtn$handle() { + return __assert_rtn.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void __assert_rtn(const char *, const char *, int, const char *) + * } + */ + public static MemorySegment __assert_rtn$address() { + return __assert_rtn.ADDR; + } + + /** + * {@snippet lang=c : + * void __assert_rtn(const char *, const char *, int, const char *) + * } + */ + public static void __assert_rtn(MemorySegment x0, MemorySegment x1, int x2, MemorySegment x3) { + var mh$ = __assert_rtn.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("__assert_rtn", x0, x1, x2, x3); + } + mh$.invokeExact(x0, x1, x2, x3); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + /** + * {@snippet lang=c : + * typedef long ptrdiff_t + * } + */ + public static final OfLong ptrdiff_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef unsigned long size_t + * } + */ + public static final OfLong size_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef unsigned long rsize_t + * } + */ + public static final OfLong rsize_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef int wchar_t + * } + */ + public static final OfInt wchar_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef signed char int8_t + * } + */ + public static final OfByte int8_t = somelib_h.C_CHAR; + /** + * {@snippet lang=c : + * typedef short int16_t + * } + */ + public static final OfShort int16_t = somelib_h.C_SHORT; + /** + * {@snippet lang=c : + * typedef int int32_t + * } + */ + public static final OfInt int32_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef long long int64_t + * } + */ + public static final OfLong int64_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef unsigned char uint8_t + * } + */ + public static final OfByte uint8_t = somelib_h.C_CHAR; + /** + * {@snippet lang=c : + * typedef unsigned short uint16_t + * } + */ + public static final OfShort uint16_t = somelib_h.C_SHORT; + /** + * {@snippet lang=c : + * typedef unsigned int uint32_t + * } + */ + public static final OfInt uint32_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef unsigned long long uint64_t + * } + */ + public static final OfLong uint64_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef int8_t int_least8_t + * } + */ + public static final OfByte int_least8_t = somelib_h.C_CHAR; + /** + * {@snippet lang=c : + * typedef int16_t int_least16_t + * } + */ + public static final OfShort int_least16_t = somelib_h.C_SHORT; + /** + * {@snippet lang=c : + * typedef int32_t int_least32_t + * } + */ + public static final OfInt int_least32_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef int64_t int_least64_t + * } + */ + public static final OfLong int_least64_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef uint8_t uint_least8_t + * } + */ + public static final OfByte uint_least8_t = somelib_h.C_CHAR; + /** + * {@snippet lang=c : + * typedef uint16_t uint_least16_t + * } + */ + public static final OfShort uint_least16_t = somelib_h.C_SHORT; + /** + * {@snippet lang=c : + * typedef uint32_t uint_least32_t + * } + */ + public static final OfInt uint_least32_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef uint64_t uint_least64_t + * } + */ + public static final OfLong uint_least64_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef int8_t int_fast8_t + * } + */ + public static final OfByte int_fast8_t = somelib_h.C_CHAR; + /** + * {@snippet lang=c : + * typedef int16_t int_fast16_t + * } + */ + public static final OfShort int_fast16_t = somelib_h.C_SHORT; + /** + * {@snippet lang=c : + * typedef int32_t int_fast32_t + * } + */ + public static final OfInt int_fast32_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef int64_t int_fast64_t + * } + */ + public static final OfLong int_fast64_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef uint8_t uint_fast8_t + * } + */ + public static final OfByte uint_fast8_t = somelib_h.C_CHAR; + /** + * {@snippet lang=c : + * typedef uint16_t uint_fast16_t + * } + */ + public static final OfShort uint_fast16_t = somelib_h.C_SHORT; + /** + * {@snippet lang=c : + * typedef uint32_t uint_fast32_t + * } + */ + public static final OfInt uint_fast32_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef uint64_t uint_fast64_t + * } + */ + public static final OfLong uint_fast64_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef signed char __int8_t + * } + */ + public static final OfByte __int8_t = somelib_h.C_CHAR; + /** + * {@snippet lang=c : + * typedef unsigned char __uint8_t + * } + */ + public static final OfByte __uint8_t = somelib_h.C_CHAR; + /** + * {@snippet lang=c : + * typedef short __int16_t + * } + */ + public static final OfShort __int16_t = somelib_h.C_SHORT; + /** + * {@snippet lang=c : + * typedef unsigned short __uint16_t + * } + */ + public static final OfShort __uint16_t = somelib_h.C_SHORT; + /** + * {@snippet lang=c : + * typedef int __int32_t + * } + */ + public static final OfInt __int32_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef unsigned int __uint32_t + * } + */ + public static final OfInt __uint32_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef long long __int64_t + * } + */ + public static final OfLong __int64_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef unsigned long long __uint64_t + * } + */ + public static final OfLong __uint64_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef long __darwin_intptr_t + * } + */ + public static final OfLong __darwin_intptr_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef unsigned int __darwin_natural_t + * } + */ + public static final OfInt __darwin_natural_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef int __darwin_ct_rune_t + * } + */ + public static final OfInt __darwin_ct_rune_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef long __darwin_ptrdiff_t + * } + */ + public static final OfLong __darwin_ptrdiff_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef unsigned long __darwin_size_t + * } + */ + public static final OfLong __darwin_size_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef __builtin_va_list __darwin_va_list + * } + */ + public static final AddressLayout __darwin_va_list = somelib_h.C_POINTER; + /** + * {@snippet lang=c : + * typedef int __darwin_wchar_t + * } + */ + public static final OfInt __darwin_wchar_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __darwin_wchar_t __darwin_rune_t + * } + */ + public static final OfInt __darwin_rune_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef int __darwin_wint_t + * } + */ + public static final OfInt __darwin_wint_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef unsigned long __darwin_clock_t + * } + */ + public static final OfLong __darwin_clock_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef __uint32_t __darwin_socklen_t + * } + */ + public static final OfInt __darwin_socklen_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef long __darwin_ssize_t + * } + */ + public static final OfLong __darwin_ssize_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef long __darwin_time_t + * } + */ + public static final OfLong __darwin_time_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef __int64_t __darwin_blkcnt_t + * } + */ + public static final OfLong __darwin_blkcnt_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef __int32_t __darwin_blksize_t + * } + */ + public static final OfInt __darwin_blksize_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __int32_t __darwin_dev_t + * } + */ + public static final OfInt __darwin_dev_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef unsigned int __darwin_fsblkcnt_t + * } + */ + public static final OfInt __darwin_fsblkcnt_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef unsigned int __darwin_fsfilcnt_t + * } + */ + public static final OfInt __darwin_fsfilcnt_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __uint32_t __darwin_gid_t + * } + */ + public static final OfInt __darwin_gid_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __uint32_t __darwin_id_t + * } + */ + public static final OfInt __darwin_id_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __uint64_t __darwin_ino64_t + * } + */ + public static final OfLong __darwin_ino64_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef __darwin_ino64_t __darwin_ino_t + * } + */ + public static final OfLong __darwin_ino_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef __darwin_natural_t __darwin_mach_port_name_t + * } + */ + public static final OfInt __darwin_mach_port_name_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __darwin_mach_port_name_t __darwin_mach_port_t + * } + */ + public static final OfInt __darwin_mach_port_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __uint16_t __darwin_mode_t + * } + */ + public static final OfShort __darwin_mode_t = somelib_h.C_SHORT; + /** + * {@snippet lang=c : + * typedef __int64_t __darwin_off_t + * } + */ + public static final OfLong __darwin_off_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef __int32_t __darwin_pid_t + * } + */ + public static final OfInt __darwin_pid_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __uint32_t __darwin_sigset_t + * } + */ + public static final OfInt __darwin_sigset_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __int32_t __darwin_suseconds_t + * } + */ + public static final OfInt __darwin_suseconds_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __uint32_t __darwin_uid_t + * } + */ + public static final OfInt __darwin_uid_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __uint32_t __darwin_useconds_t + * } + */ + public static final OfInt __darwin_useconds_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef unsigned long __darwin_pthread_key_t + * } + */ + public static final OfLong __darwin_pthread_key_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef struct _opaque_pthread_t { + * long __sig; + * struct __darwin_pthread_handler_rec *__cleanup_stack; + * char __opaque[8176]; + * } *__darwin_pthread_t + * } + */ + public static final AddressLayout __darwin_pthread_t = somelib_h.C_POINTER; + /** + * {@snippet lang=c : + * typedef unsigned char u_int8_t + * } + */ + public static final OfByte u_int8_t = somelib_h.C_CHAR; + /** + * {@snippet lang=c : + * typedef unsigned short u_int16_t + * } + */ + public static final OfShort u_int16_t = somelib_h.C_SHORT; + /** + * {@snippet lang=c : + * typedef unsigned int u_int32_t + * } + */ + public static final OfInt u_int32_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef unsigned long long u_int64_t + * } + */ + public static final OfLong u_int64_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef int64_t register_t + * } + */ + public static final OfLong register_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef unsigned long uintptr_t + * } + */ + public static final OfLong uintptr_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef u_int64_t user_addr_t + * } + */ + public static final OfLong user_addr_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef u_int64_t user_size_t + * } + */ + public static final OfLong user_size_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef int64_t user_ssize_t + * } + */ + public static final OfLong user_ssize_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef int64_t user_long_t + * } + */ + public static final OfLong user_long_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef u_int64_t user_ulong_t + * } + */ + public static final OfLong user_ulong_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef int64_t user_time_t + * } + */ + public static final OfLong user_time_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef int64_t user_off_t + * } + */ + public static final OfLong user_off_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef u_int64_t syscall_arg_t + * } + */ + public static final OfLong syscall_arg_t = somelib_h.C_LONG_LONG; + /** + * {@snippet lang=c : + * typedef __darwin_intptr_t intptr_t + * } + */ + public static final OfLong intptr_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef long intmax_t + * } + */ + public static final OfLong intmax_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef unsigned long uintmax_t + * } + */ + public static final OfLong uintmax_t = somelib_h.C_LONG; + /** + * {@snippet lang=c : + * typedef uint_least16_t char16_t + * } + */ + public static final OfShort char16_t = somelib_h.C_SHORT; + /** + * {@snippet lang=c : + * typedef uint_least32_t char32_t + * } + */ + public static final OfInt char32_t = somelib_h.C_INT; + + private static class diplomat_is_str { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_BOOL, + somelib_h.C_POINTER, + somelib_h.C_LONG + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("diplomat_is_str"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * bool diplomat_is_str(const char *buf, size_t len) + * } + */ + public static FunctionDescriptor diplomat_is_str$descriptor() { + return diplomat_is_str.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * bool diplomat_is_str(const char *buf, size_t len) + * } + */ + public static MethodHandle diplomat_is_str$handle() { + return diplomat_is_str.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * bool diplomat_is_str(const char *buf, size_t len) + * } + */ + public static MemorySegment diplomat_is_str$address() { + return diplomat_is_str.ADDR; + } + + /** + * {@snippet lang=c : + * bool diplomat_is_str(const char *buf, size_t len) + * } + */ + public static boolean diplomat_is_str(MemorySegment buf, long len) { + var mh$ = diplomat_is_str.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("diplomat_is_str", buf, len); + } + return (boolean)mh$.invokeExact(buf, len); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class diplomat_simple_write { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + DiplomatWrite.layout(), + somelib_h.C_POINTER, + somelib_h.C_LONG + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("diplomat_simple_write"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * DiplomatWrite diplomat_simple_write(char *buf, size_t buf_size) + * } + */ + public static FunctionDescriptor diplomat_simple_write$descriptor() { + return diplomat_simple_write.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * DiplomatWrite diplomat_simple_write(char *buf, size_t buf_size) + * } + */ + public static MethodHandle diplomat_simple_write$handle() { + return diplomat_simple_write.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * DiplomatWrite diplomat_simple_write(char *buf, size_t buf_size) + * } + */ + public static MemorySegment diplomat_simple_write$address() { + return diplomat_simple_write.ADDR; + } + + /** + * {@snippet lang=c : + * DiplomatWrite diplomat_simple_write(char *buf, size_t buf_size) + * } + */ + public static MemorySegment diplomat_simple_write(SegmentAllocator allocator, MemorySegment buf, long buf_size) { + var mh$ = diplomat_simple_write.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("diplomat_simple_write", allocator, buf, buf_size); + } + return (MemorySegment)mh$.invokeExact(allocator, buf, buf_size); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class diplomat_buffer_write_create { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_LONG + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("diplomat_buffer_write_create"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * DiplomatWrite *diplomat_buffer_write_create(size_t cap) + * } + */ + public static FunctionDescriptor diplomat_buffer_write_create$descriptor() { + return diplomat_buffer_write_create.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * DiplomatWrite *diplomat_buffer_write_create(size_t cap) + * } + */ + public static MethodHandle diplomat_buffer_write_create$handle() { + return diplomat_buffer_write_create.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * DiplomatWrite *diplomat_buffer_write_create(size_t cap) + * } + */ + public static MemorySegment diplomat_buffer_write_create$address() { + return diplomat_buffer_write_create.ADDR; + } + + /** + * {@snippet lang=c : + * DiplomatWrite *diplomat_buffer_write_create(size_t cap) + * } + */ + public static MemorySegment diplomat_buffer_write_create(long cap) { + var mh$ = diplomat_buffer_write_create.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("diplomat_buffer_write_create", cap); + } + return (MemorySegment)mh$.invokeExact(cap); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class diplomat_buffer_write_get_bytes { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("diplomat_buffer_write_get_bytes"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * char *diplomat_buffer_write_get_bytes(DiplomatWrite *t) + * } + */ + public static FunctionDescriptor diplomat_buffer_write_get_bytes$descriptor() { + return diplomat_buffer_write_get_bytes.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * char *diplomat_buffer_write_get_bytes(DiplomatWrite *t) + * } + */ + public static MethodHandle diplomat_buffer_write_get_bytes$handle() { + return diplomat_buffer_write_get_bytes.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * char *diplomat_buffer_write_get_bytes(DiplomatWrite *t) + * } + */ + public static MemorySegment diplomat_buffer_write_get_bytes$address() { + return diplomat_buffer_write_get_bytes.ADDR; + } + + /** + * {@snippet lang=c : + * char *diplomat_buffer_write_get_bytes(DiplomatWrite *t) + * } + */ + public static MemorySegment diplomat_buffer_write_get_bytes(MemorySegment t) { + var mh$ = diplomat_buffer_write_get_bytes.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("diplomat_buffer_write_get_bytes", t); + } + return (MemorySegment)mh$.invokeExact(t); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class diplomat_buffer_write_len { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_LONG, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("diplomat_buffer_write_len"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * size_t diplomat_buffer_write_len(DiplomatWrite *t) + * } + */ + public static FunctionDescriptor diplomat_buffer_write_len$descriptor() { + return diplomat_buffer_write_len.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * size_t diplomat_buffer_write_len(DiplomatWrite *t) + * } + */ + public static MethodHandle diplomat_buffer_write_len$handle() { + return diplomat_buffer_write_len.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * size_t diplomat_buffer_write_len(DiplomatWrite *t) + * } + */ + public static MemorySegment diplomat_buffer_write_len$address() { + return diplomat_buffer_write_len.ADDR; + } + + /** + * {@snippet lang=c : + * size_t diplomat_buffer_write_len(DiplomatWrite *t) + * } + */ + public static long diplomat_buffer_write_len(MemorySegment t) { + var mh$ = diplomat_buffer_write_len.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("diplomat_buffer_write_len", t); + } + return (long)mh$.invokeExact(t); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class diplomat_buffer_write_destroy { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("diplomat_buffer_write_destroy"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void diplomat_buffer_write_destroy(DiplomatWrite *t) + * } + */ + public static FunctionDescriptor diplomat_buffer_write_destroy$descriptor() { + return diplomat_buffer_write_destroy.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void diplomat_buffer_write_destroy(DiplomatWrite *t) + * } + */ + public static MethodHandle diplomat_buffer_write_destroy$handle() { + return diplomat_buffer_write_destroy.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void diplomat_buffer_write_destroy(DiplomatWrite *t) + * } + */ + public static MemorySegment diplomat_buffer_write_destroy$address() { + return diplomat_buffer_write_destroy.ADDR; + } + + /** + * {@snippet lang=c : + * void diplomat_buffer_write_destroy(DiplomatWrite *t) + * } + */ + public static void diplomat_buffer_write_destroy(MemorySegment t) { + var mh$ = diplomat_buffer_write_destroy.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("diplomat_buffer_write_destroy", t); + } + mh$.invokeExact(t); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + /** + * {@snippet lang=c : + * typedef int __darwin_nl_item + * } + */ + public static final OfInt __darwin_nl_item = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef int __darwin_wctrans_t + * } + */ + public static final OfInt __darwin_wctrans_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __uint32_t __darwin_wctype_t + * } + */ + public static final OfInt __darwin_wctype_t = somelib_h.C_INT; + /** + * {@snippet lang=c : + * typedef __darwin_va_list va_list + * } + */ + public static final AddressLayout va_list = somelib_h.C_POINTER; + + private static class renameat { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("renameat"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int renameat(int, const char *, int, const char *) + * } + */ + public static FunctionDescriptor renameat$descriptor() { + return renameat.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int renameat(int, const char *, int, const char *) + * } + */ + public static MethodHandle renameat$handle() { + return renameat.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int renameat(int, const char *, int, const char *) + * } + */ + public static MemorySegment renameat$address() { + return renameat.ADDR; + } + + /** + * {@snippet lang=c : + * int renameat(int, const char *, int, const char *) + * } + */ + public static int renameat(int x0, MemorySegment x1, int x2, MemorySegment x3) { + var mh$ = renameat.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("renameat", x0, x1, x2, x3); + } + return (int)mh$.invokeExact(x0, x1, x2, x3); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class renamex_np { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_INT + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("renamex_np"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int renamex_np(const char *, const char *, unsigned int) + * } + */ + public static FunctionDescriptor renamex_np$descriptor() { + return renamex_np.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int renamex_np(const char *, const char *, unsigned int) + * } + */ + public static MethodHandle renamex_np$handle() { + return renamex_np.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int renamex_np(const char *, const char *, unsigned int) + * } + */ + public static MemorySegment renamex_np$address() { + return renamex_np.ADDR; + } + + /** + * {@snippet lang=c : + * int renamex_np(const char *, const char *, unsigned int) + * } + */ + public static int renamex_np(MemorySegment x0, MemorySegment x1, int x2) { + var mh$ = renamex_np.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("renamex_np", x0, x1, x2); + } + return (int)mh$.invokeExact(x0, x1, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class renameatx_np { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_INT + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("renameatx_np"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int renameatx_np(int, const char *, int, const char *, unsigned int) + * } + */ + public static FunctionDescriptor renameatx_np$descriptor() { + return renameatx_np.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int renameatx_np(int, const char *, int, const char *, unsigned int) + * } + */ + public static MethodHandle renameatx_np$handle() { + return renameatx_np.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int renameatx_np(int, const char *, int, const char *, unsigned int) + * } + */ + public static MemorySegment renameatx_np$address() { + return renameatx_np.ADDR; + } + + /** + * {@snippet lang=c : + * int renameatx_np(int, const char *, int, const char *, unsigned int) + * } + */ + public static int renameatx_np(int x0, MemorySegment x1, int x2, MemorySegment x3, int x4) { + var mh$ = renameatx_np.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("renameatx_np", x0, x1, x2, x3, x4); + } + return (int)mh$.invokeExact(x0, x1, x2, x3, x4); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + /** + * {@snippet lang=c : + * typedef __darwin_off_t fpos_t + * } + */ + public static final OfLong fpos_t = somelib_h.C_LONG_LONG; + + private static class __stdinp$constants { + public static final AddressLayout LAYOUT = somelib_h.C_POINTER; + public static final MemorySegment SEGMENT = somelib_h.findOrThrow("__stdinp").reinterpret(LAYOUT.byteSize()); + } + + /** + * Layout for variable: + * {@snippet lang=c : + * extern FILE *__stdinp + * } + */ + public static AddressLayout __stdinp$layout() { + return __stdinp$constants.LAYOUT; + } + + /** + * Segment for variable: + * {@snippet lang=c : + * extern FILE *__stdinp + * } + */ + public static MemorySegment __stdinp$segment() { + return __stdinp$constants.SEGMENT; + } + + /** + * Getter for variable: + * {@snippet lang=c : + * extern FILE *__stdinp + * } + */ + public static MemorySegment __stdinp() { + return __stdinp$constants.SEGMENT.get(__stdinp$constants.LAYOUT, 0L); + } + + /** + * Setter for variable: + * {@snippet lang=c : + * extern FILE *__stdinp + * } + */ + public static void __stdinp(MemorySegment varValue) { + __stdinp$constants.SEGMENT.set(__stdinp$constants.LAYOUT, 0L, varValue); + } + + private static class __stdoutp$constants { + public static final AddressLayout LAYOUT = somelib_h.C_POINTER; + public static final MemorySegment SEGMENT = somelib_h.findOrThrow("__stdoutp").reinterpret(LAYOUT.byteSize()); + } + + /** + * Layout for variable: + * {@snippet lang=c : + * extern FILE *__stdoutp + * } + */ + public static AddressLayout __stdoutp$layout() { + return __stdoutp$constants.LAYOUT; + } + + /** + * Segment for variable: + * {@snippet lang=c : + * extern FILE *__stdoutp + * } + */ + public static MemorySegment __stdoutp$segment() { + return __stdoutp$constants.SEGMENT; + } + + /** + * Getter for variable: + * {@snippet lang=c : + * extern FILE *__stdoutp + * } + */ + public static MemorySegment __stdoutp() { + return __stdoutp$constants.SEGMENT.get(__stdoutp$constants.LAYOUT, 0L); + } + + /** + * Setter for variable: + * {@snippet lang=c : + * extern FILE *__stdoutp + * } + */ + public static void __stdoutp(MemorySegment varValue) { + __stdoutp$constants.SEGMENT.set(__stdoutp$constants.LAYOUT, 0L, varValue); + } + + private static class __stderrp$constants { + public static final AddressLayout LAYOUT = somelib_h.C_POINTER; + public static final MemorySegment SEGMENT = somelib_h.findOrThrow("__stderrp").reinterpret(LAYOUT.byteSize()); + } + + /** + * Layout for variable: + * {@snippet lang=c : + * extern FILE *__stderrp + * } + */ + public static AddressLayout __stderrp$layout() { + return __stderrp$constants.LAYOUT; + } + + /** + * Segment for variable: + * {@snippet lang=c : + * extern FILE *__stderrp + * } + */ + public static MemorySegment __stderrp$segment() { + return __stderrp$constants.SEGMENT; + } + + /** + * Getter for variable: + * {@snippet lang=c : + * extern FILE *__stderrp + * } + */ + public static MemorySegment __stderrp() { + return __stderrp$constants.SEGMENT.get(__stderrp$constants.LAYOUT, 0L); + } + + /** + * Setter for variable: + * {@snippet lang=c : + * extern FILE *__stderrp + * } + */ + public static void __stderrp(MemorySegment varValue) { + __stderrp$constants.SEGMENT.set(__stderrp$constants.LAYOUT, 0L, varValue); + } + + private static class clearerr { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("clearerr"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void clearerr(FILE *) + * } + */ + public static FunctionDescriptor clearerr$descriptor() { + return clearerr.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void clearerr(FILE *) + * } + */ + public static MethodHandle clearerr$handle() { + return clearerr.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void clearerr(FILE *) + * } + */ + public static MemorySegment clearerr$address() { + return clearerr.ADDR; + } + + /** + * {@snippet lang=c : + * void clearerr(FILE *) + * } + */ + public static void clearerr(MemorySegment x0) { + var mh$ = clearerr.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("clearerr", x0); + } + mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fclose { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fclose"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int fclose(FILE *) + * } + */ + public static FunctionDescriptor fclose$descriptor() { + return fclose.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int fclose(FILE *) + * } + */ + public static MethodHandle fclose$handle() { + return fclose.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int fclose(FILE *) + * } + */ + public static MemorySegment fclose$address() { + return fclose.ADDR; + } + + /** + * {@snippet lang=c : + * int fclose(FILE *) + * } + */ + public static int fclose(MemorySegment x0) { + var mh$ = fclose.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fclose", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class feof { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("feof"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int feof(FILE *) + * } + */ + public static FunctionDescriptor feof$descriptor() { + return feof.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int feof(FILE *) + * } + */ + public static MethodHandle feof$handle() { + return feof.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int feof(FILE *) + * } + */ + public static MemorySegment feof$address() { + return feof.ADDR; + } + + /** + * {@snippet lang=c : + * int feof(FILE *) + * } + */ + public static int feof(MemorySegment x0) { + var mh$ = feof.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("feof", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class ferror { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("ferror"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int ferror(FILE *) + * } + */ + public static FunctionDescriptor ferror$descriptor() { + return ferror.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int ferror(FILE *) + * } + */ + public static MethodHandle ferror$handle() { + return ferror.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int ferror(FILE *) + * } + */ + public static MemorySegment ferror$address() { + return ferror.ADDR; + } + + /** + * {@snippet lang=c : + * int ferror(FILE *) + * } + */ + public static int ferror(MemorySegment x0) { + var mh$ = ferror.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("ferror", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fflush { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fflush"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int fflush(FILE *) + * } + */ + public static FunctionDescriptor fflush$descriptor() { + return fflush.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int fflush(FILE *) + * } + */ + public static MethodHandle fflush$handle() { + return fflush.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int fflush(FILE *) + * } + */ + public static MemorySegment fflush$address() { + return fflush.ADDR; + } + + /** + * {@snippet lang=c : + * int fflush(FILE *) + * } + */ + public static int fflush(MemorySegment x0) { + var mh$ = fflush.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fflush", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fgetc { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fgetc"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int fgetc(FILE *) + * } + */ + public static FunctionDescriptor fgetc$descriptor() { + return fgetc.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int fgetc(FILE *) + * } + */ + public static MethodHandle fgetc$handle() { + return fgetc.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int fgetc(FILE *) + * } + */ + public static MemorySegment fgetc$address() { + return fgetc.ADDR; + } + + /** + * {@snippet lang=c : + * int fgetc(FILE *) + * } + */ + public static int fgetc(MemorySegment x0) { + var mh$ = fgetc.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fgetc", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fgetpos { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fgetpos"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int fgetpos(FILE *restrict, fpos_t *) + * } + */ + public static FunctionDescriptor fgetpos$descriptor() { + return fgetpos.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int fgetpos(FILE *restrict, fpos_t *) + * } + */ + public static MethodHandle fgetpos$handle() { + return fgetpos.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int fgetpos(FILE *restrict, fpos_t *) + * } + */ + public static MemorySegment fgetpos$address() { + return fgetpos.ADDR; + } + + /** + * {@snippet lang=c : + * int fgetpos(FILE *restrict, fpos_t *) + * } + */ + public static int fgetpos(MemorySegment x0, MemorySegment x1) { + var mh$ = fgetpos.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fgetpos", x0, x1); + } + return (int)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fgets { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fgets"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * char *fgets(char *restrict, int, FILE *) + * } + */ + public static FunctionDescriptor fgets$descriptor() { + return fgets.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * char *fgets(char *restrict, int, FILE *) + * } + */ + public static MethodHandle fgets$handle() { + return fgets.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * char *fgets(char *restrict, int, FILE *) + * } + */ + public static MemorySegment fgets$address() { + return fgets.ADDR; + } + + /** + * {@snippet lang=c : + * char *fgets(char *restrict, int, FILE *) + * } + */ + public static MemorySegment fgets(MemorySegment x0, int x1, MemorySegment x2) { + var mh$ = fgets.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fgets", x0, x1, x2); + } + return (MemorySegment)mh$.invokeExact(x0, x1, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fopen { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fopen"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * FILE *fopen(const char *restrict __filename, const char *restrict __mode) + * } + */ + public static FunctionDescriptor fopen$descriptor() { + return fopen.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * FILE *fopen(const char *restrict __filename, const char *restrict __mode) + * } + */ + public static MethodHandle fopen$handle() { + return fopen.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * FILE *fopen(const char *restrict __filename, const char *restrict __mode) + * } + */ + public static MemorySegment fopen$address() { + return fopen.ADDR; + } + + /** + * {@snippet lang=c : + * FILE *fopen(const char *restrict __filename, const char *restrict __mode) + * } + */ + public static MemorySegment fopen(MemorySegment __filename, MemorySegment __mode) { + var mh$ = fopen.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fopen", __filename, __mode); + } + return (MemorySegment)mh$.invokeExact(__filename, __mode); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + /** + * Variadic invoker class for: + * {@snippet lang=c : + * int fprintf(FILE *restrict, const char *restrict, ...) + * } + */ + public static class fprintf { + private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + private static final MemorySegment ADDR = somelib_h.findOrThrow("fprintf"); + + private final MethodHandle handle; + private final FunctionDescriptor descriptor; + private final MethodHandle spreader; + + private fprintf(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) { + this.handle = handle; + this.descriptor = descriptor; + this.spreader = spreader; + } + + /** + * Variadic invoker factory for: + * {@snippet lang=c : + * int fprintf(FILE *restrict, const char *restrict, ...) + * } + */ + public static fprintf makeInvoker(MemoryLayout... layouts) { + FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts); + Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size()); + var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$); + var spreader$ = mh$.asSpreader(Object[].class, layouts.length); + return new fprintf(mh$, desc$, spreader$); + } + + /** + * {@return the address} + */ + public static MemorySegment address() { + return ADDR; + } + + /** + * {@return the specialized method handle} + */ + public MethodHandle handle() { + return handle; + } + + /** + * {@return the specialized descriptor} + */ + public FunctionDescriptor descriptor() { + return descriptor; + } + + public int apply(MemorySegment x0, MemorySegment x1, Object... x2) { + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fprintf", x0, x1, x2); + } + return (int)spreader.invokeExact(x0, x1, x2); + } catch(IllegalArgumentException | ClassCastException ex$) { + throw ex$; // rethrow IAE from passing wrong number/type of args + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static class fputc { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fputc"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int fputc(int, FILE *) + * } + */ + public static FunctionDescriptor fputc$descriptor() { + return fputc.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int fputc(int, FILE *) + * } + */ + public static MethodHandle fputc$handle() { + return fputc.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int fputc(int, FILE *) + * } + */ + public static MemorySegment fputc$address() { + return fputc.ADDR; + } + + /** + * {@snippet lang=c : + * int fputc(int, FILE *) + * } + */ + public static int fputc(int x0, MemorySegment x1) { + var mh$ = fputc.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fputc", x0, x1); + } + return (int)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fputs { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fputs"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int fputs(const char *restrict, FILE *restrict) + * } + */ + public static FunctionDescriptor fputs$descriptor() { + return fputs.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int fputs(const char *restrict, FILE *restrict) + * } + */ + public static MethodHandle fputs$handle() { + return fputs.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int fputs(const char *restrict, FILE *restrict) + * } + */ + public static MemorySegment fputs$address() { + return fputs.ADDR; + } + + /** + * {@snippet lang=c : + * int fputs(const char *restrict, FILE *restrict) + * } + */ + public static int fputs(MemorySegment x0, MemorySegment x1) { + var mh$ = fputs.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fputs", x0, x1); + } + return (int)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fread { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_LONG, + somelib_h.C_POINTER, + somelib_h.C_LONG, + somelib_h.C_LONG, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fread"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * unsigned long fread(void *restrict __ptr, size_t __size, size_t __nitems, FILE *restrict __stream) + * } + */ + public static FunctionDescriptor fread$descriptor() { + return fread.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * unsigned long fread(void *restrict __ptr, size_t __size, size_t __nitems, FILE *restrict __stream) + * } + */ + public static MethodHandle fread$handle() { + return fread.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * unsigned long fread(void *restrict __ptr, size_t __size, size_t __nitems, FILE *restrict __stream) + * } + */ + public static MemorySegment fread$address() { + return fread.ADDR; + } + + /** + * {@snippet lang=c : + * unsigned long fread(void *restrict __ptr, size_t __size, size_t __nitems, FILE *restrict __stream) + * } + */ + public static long fread(MemorySegment __ptr, long __size, long __nitems, MemorySegment __stream) { + var mh$ = fread.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fread", __ptr, __size, __nitems, __stream); + } + return (long)mh$.invokeExact(__ptr, __size, __nitems, __stream); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class freopen { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("freopen"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * FILE *freopen(const char *restrict, const char *restrict, FILE *restrict) + * } + */ + public static FunctionDescriptor freopen$descriptor() { + return freopen.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * FILE *freopen(const char *restrict, const char *restrict, FILE *restrict) + * } + */ + public static MethodHandle freopen$handle() { + return freopen.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * FILE *freopen(const char *restrict, const char *restrict, FILE *restrict) + * } + */ + public static MemorySegment freopen$address() { + return freopen.ADDR; + } + + /** + * {@snippet lang=c : + * FILE *freopen(const char *restrict, const char *restrict, FILE *restrict) + * } + */ + public static MemorySegment freopen(MemorySegment x0, MemorySegment x1, MemorySegment x2) { + var mh$ = freopen.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("freopen", x0, x1, x2); + } + return (MemorySegment)mh$.invokeExact(x0, x1, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + /** + * Variadic invoker class for: + * {@snippet lang=c : + * int fscanf(FILE *restrict, const char *restrict, ...) + * } + */ + public static class fscanf { + private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + private static final MemorySegment ADDR = somelib_h.findOrThrow("fscanf"); + + private final MethodHandle handle; + private final FunctionDescriptor descriptor; + private final MethodHandle spreader; + + private fscanf(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) { + this.handle = handle; + this.descriptor = descriptor; + this.spreader = spreader; + } + + /** + * Variadic invoker factory for: + * {@snippet lang=c : + * int fscanf(FILE *restrict, const char *restrict, ...) + * } + */ + public static fscanf makeInvoker(MemoryLayout... layouts) { + FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts); + Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size()); + var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$); + var spreader$ = mh$.asSpreader(Object[].class, layouts.length); + return new fscanf(mh$, desc$, spreader$); + } + + /** + * {@return the address} + */ + public static MemorySegment address() { + return ADDR; + } + + /** + * {@return the specialized method handle} + */ + public MethodHandle handle() { + return handle; + } + + /** + * {@return the specialized descriptor} + */ + public FunctionDescriptor descriptor() { + return descriptor; + } + + public int apply(MemorySegment x0, MemorySegment x1, Object... x2) { + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fscanf", x0, x1, x2); + } + return (int)spreader.invokeExact(x0, x1, x2); + } catch(IllegalArgumentException | ClassCastException ex$) { + throw ex$; // rethrow IAE from passing wrong number/type of args + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static class fseek { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_LONG, + somelib_h.C_INT + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fseek"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int fseek(FILE *, long, int) + * } + */ + public static FunctionDescriptor fseek$descriptor() { + return fseek.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int fseek(FILE *, long, int) + * } + */ + public static MethodHandle fseek$handle() { + return fseek.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int fseek(FILE *, long, int) + * } + */ + public static MemorySegment fseek$address() { + return fseek.ADDR; + } + + /** + * {@snippet lang=c : + * int fseek(FILE *, long, int) + * } + */ + public static int fseek(MemorySegment x0, long x1, int x2) { + var mh$ = fseek.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fseek", x0, x1, x2); + } + return (int)mh$.invokeExact(x0, x1, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fsetpos { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fsetpos"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int fsetpos(FILE *, const fpos_t *) + * } + */ + public static FunctionDescriptor fsetpos$descriptor() { + return fsetpos.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int fsetpos(FILE *, const fpos_t *) + * } + */ + public static MethodHandle fsetpos$handle() { + return fsetpos.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int fsetpos(FILE *, const fpos_t *) + * } + */ + public static MemorySegment fsetpos$address() { + return fsetpos.ADDR; + } + + /** + * {@snippet lang=c : + * int fsetpos(FILE *, const fpos_t *) + * } + */ + public static int fsetpos(MemorySegment x0, MemorySegment x1) { + var mh$ = fsetpos.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fsetpos", x0, x1); + } + return (int)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class ftell { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_LONG, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("ftell"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * long ftell(FILE *) + * } + */ + public static FunctionDescriptor ftell$descriptor() { + return ftell.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * long ftell(FILE *) + * } + */ + public static MethodHandle ftell$handle() { + return ftell.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * long ftell(FILE *) + * } + */ + public static MemorySegment ftell$address() { + return ftell.ADDR; + } + + /** + * {@snippet lang=c : + * long ftell(FILE *) + * } + */ + public static long ftell(MemorySegment x0) { + var mh$ = ftell.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("ftell", x0); + } + return (long)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fwrite { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_LONG, + somelib_h.C_POINTER, + somelib_h.C_LONG, + somelib_h.C_LONG, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fwrite"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * unsigned long fwrite(const void *restrict __ptr, size_t __size, size_t __nitems, FILE *restrict __stream) + * } + */ + public static FunctionDescriptor fwrite$descriptor() { + return fwrite.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * unsigned long fwrite(const void *restrict __ptr, size_t __size, size_t __nitems, FILE *restrict __stream) + * } + */ + public static MethodHandle fwrite$handle() { + return fwrite.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * unsigned long fwrite(const void *restrict __ptr, size_t __size, size_t __nitems, FILE *restrict __stream) + * } + */ + public static MemorySegment fwrite$address() { + return fwrite.ADDR; + } + + /** + * {@snippet lang=c : + * unsigned long fwrite(const void *restrict __ptr, size_t __size, size_t __nitems, FILE *restrict __stream) + * } + */ + public static long fwrite(MemorySegment __ptr, long __size, long __nitems, MemorySegment __stream) { + var mh$ = fwrite.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fwrite", __ptr, __size, __nitems, __stream); + } + return (long)mh$.invokeExact(__ptr, __size, __nitems, __stream); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class getc { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("getc"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int getc(FILE *) + * } + */ + public static FunctionDescriptor getc$descriptor() { + return getc.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int getc(FILE *) + * } + */ + public static MethodHandle getc$handle() { + return getc.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int getc(FILE *) + * } + */ + public static MemorySegment getc$address() { + return getc.ADDR; + } + + /** + * {@snippet lang=c : + * int getc(FILE *) + * } + */ + public static int getc(MemorySegment x0) { + var mh$ = getc.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("getc", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class getchar { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("getchar"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int getchar() + * } + */ + public static FunctionDescriptor getchar$descriptor() { + return getchar.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int getchar() + * } + */ + public static MethodHandle getchar$handle() { + return getchar.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int getchar() + * } + */ + public static MemorySegment getchar$address() { + return getchar.ADDR; + } + + /** + * {@snippet lang=c : + * int getchar() + * } + */ + public static int getchar() { + var mh$ = getchar.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("getchar"); + } + return (int)mh$.invokeExact(); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class gets { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("gets"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * char *gets(char *) + * } + */ + public static FunctionDescriptor gets$descriptor() { + return gets.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * char *gets(char *) + * } + */ + public static MethodHandle gets$handle() { + return gets.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * char *gets(char *) + * } + */ + public static MemorySegment gets$address() { + return gets.ADDR; + } + + /** + * {@snippet lang=c : + * char *gets(char *) + * } + */ + public static MemorySegment gets(MemorySegment x0) { + var mh$ = gets.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("gets", x0); + } + return (MemorySegment)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class perror { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("perror"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void perror(const char *) + * } + */ + public static FunctionDescriptor perror$descriptor() { + return perror.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void perror(const char *) + * } + */ + public static MethodHandle perror$handle() { + return perror.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void perror(const char *) + * } + */ + public static MemorySegment perror$address() { + return perror.ADDR; + } + + /** + * {@snippet lang=c : + * void perror(const char *) + * } + */ + public static void perror(MemorySegment x0) { + var mh$ = perror.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("perror", x0); + } + mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + /** + * Variadic invoker class for: + * {@snippet lang=c : + * int printf(const char *restrict, ...) + * } + */ + public static class printf { + private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + private static final MemorySegment ADDR = somelib_h.findOrThrow("printf"); + + private final MethodHandle handle; + private final FunctionDescriptor descriptor; + private final MethodHandle spreader; + + private printf(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) { + this.handle = handle; + this.descriptor = descriptor; + this.spreader = spreader; + } + + /** + * Variadic invoker factory for: + * {@snippet lang=c : + * int printf(const char *restrict, ...) + * } + */ + public static printf makeInvoker(MemoryLayout... layouts) { + FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts); + Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size()); + var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$); + var spreader$ = mh$.asSpreader(Object[].class, layouts.length); + return new printf(mh$, desc$, spreader$); + } + + /** + * {@return the address} + */ + public static MemorySegment address() { + return ADDR; + } + + /** + * {@return the specialized method handle} + */ + public MethodHandle handle() { + return handle; + } + + /** + * {@return the specialized descriptor} + */ + public FunctionDescriptor descriptor() { + return descriptor; + } + + public int apply(MemorySegment x0, Object... x1) { + try { + if (TRACE_DOWNCALLS) { + traceDowncall("printf", x0, x1); + } + return (int)spreader.invokeExact(x0, x1); + } catch(IllegalArgumentException | ClassCastException ex$) { + throw ex$; // rethrow IAE from passing wrong number/type of args + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static class putc { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("putc"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int putc(int, FILE *) + * } + */ + public static FunctionDescriptor putc$descriptor() { + return putc.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int putc(int, FILE *) + * } + */ + public static MethodHandle putc$handle() { + return putc.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int putc(int, FILE *) + * } + */ + public static MemorySegment putc$address() { + return putc.ADDR; + } + + /** + * {@snippet lang=c : + * int putc(int, FILE *) + * } + */ + public static int putc(int x0, MemorySegment x1) { + var mh$ = putc.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("putc", x0, x1); + } + return (int)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class putchar { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_INT + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("putchar"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int putchar(int) + * } + */ + public static FunctionDescriptor putchar$descriptor() { + return putchar.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int putchar(int) + * } + */ + public static MethodHandle putchar$handle() { + return putchar.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int putchar(int) + * } + */ + public static MemorySegment putchar$address() { + return putchar.ADDR; + } + + /** + * {@snippet lang=c : + * int putchar(int) + * } + */ + public static int putchar(int x0) { + var mh$ = putchar.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("putchar", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class puts { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("puts"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int puts(const char *) + * } + */ + public static FunctionDescriptor puts$descriptor() { + return puts.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int puts(const char *) + * } + */ + public static MethodHandle puts$handle() { + return puts.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int puts(const char *) + * } + */ + public static MemorySegment puts$address() { + return puts.ADDR; + } + + /** + * {@snippet lang=c : + * int puts(const char *) + * } + */ + public static int puts(MemorySegment x0) { + var mh$ = puts.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("puts", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class remove { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("remove"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int remove(const char *) + * } + */ + public static FunctionDescriptor remove$descriptor() { + return remove.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int remove(const char *) + * } + */ + public static MethodHandle remove$handle() { + return remove.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int remove(const char *) + * } + */ + public static MemorySegment remove$address() { + return remove.ADDR; + } + + /** + * {@snippet lang=c : + * int remove(const char *) + * } + */ + public static int remove(MemorySegment x0) { + var mh$ = remove.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("remove", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class rename { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("rename"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int rename(const char *__old, const char *__new) + * } + */ + public static FunctionDescriptor rename$descriptor() { + return rename.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int rename(const char *__old, const char *__new) + * } + */ + public static MethodHandle rename$handle() { + return rename.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int rename(const char *__old, const char *__new) + * } + */ + public static MemorySegment rename$address() { + return rename.ADDR; + } + + /** + * {@snippet lang=c : + * int rename(const char *__old, const char *__new) + * } + */ + public static int rename(MemorySegment __old, MemorySegment __new) { + var mh$ = rename.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("rename", __old, __new); + } + return (int)mh$.invokeExact(__old, __new); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class rewind { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("rewind"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void rewind(FILE *) + * } + */ + public static FunctionDescriptor rewind$descriptor() { + return rewind.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void rewind(FILE *) + * } + */ + public static MethodHandle rewind$handle() { + return rewind.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void rewind(FILE *) + * } + */ + public static MemorySegment rewind$address() { + return rewind.ADDR; + } + + /** + * {@snippet lang=c : + * void rewind(FILE *) + * } + */ + public static void rewind(MemorySegment x0) { + var mh$ = rewind.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("rewind", x0); + } + mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + /** + * Variadic invoker class for: + * {@snippet lang=c : + * int scanf(const char *restrict, ...) + * } + */ + public static class scanf { + private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + private static final MemorySegment ADDR = somelib_h.findOrThrow("scanf"); + + private final MethodHandle handle; + private final FunctionDescriptor descriptor; + private final MethodHandle spreader; + + private scanf(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) { + this.handle = handle; + this.descriptor = descriptor; + this.spreader = spreader; + } + + /** + * Variadic invoker factory for: + * {@snippet lang=c : + * int scanf(const char *restrict, ...) + * } + */ + public static scanf makeInvoker(MemoryLayout... layouts) { + FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts); + Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size()); + var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$); + var spreader$ = mh$.asSpreader(Object[].class, layouts.length); + return new scanf(mh$, desc$, spreader$); + } + + /** + * {@return the address} + */ + public static MemorySegment address() { + return ADDR; + } + + /** + * {@return the specialized method handle} + */ + public MethodHandle handle() { + return handle; + } + + /** + * {@return the specialized descriptor} + */ + public FunctionDescriptor descriptor() { + return descriptor; + } + + public int apply(MemorySegment x0, Object... x1) { + try { + if (TRACE_DOWNCALLS) { + traceDowncall("scanf", x0, x1); + } + return (int)spreader.invokeExact(x0, x1); + } catch(IllegalArgumentException | ClassCastException ex$) { + throw ex$; // rethrow IAE from passing wrong number/type of args + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static class setbuf { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("setbuf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void setbuf(FILE *restrict, char *restrict) + * } + */ + public static FunctionDescriptor setbuf$descriptor() { + return setbuf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void setbuf(FILE *restrict, char *restrict) + * } + */ + public static MethodHandle setbuf$handle() { + return setbuf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void setbuf(FILE *restrict, char *restrict) + * } + */ + public static MemorySegment setbuf$address() { + return setbuf.ADDR; + } + + /** + * {@snippet lang=c : + * void setbuf(FILE *restrict, char *restrict) + * } + */ + public static void setbuf(MemorySegment x0, MemorySegment x1) { + var mh$ = setbuf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("setbuf", x0, x1); + } + mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class setvbuf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_INT, + somelib_h.C_LONG + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("setvbuf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int setvbuf(FILE *restrict, char *restrict, int, size_t) + * } + */ + public static FunctionDescriptor setvbuf$descriptor() { + return setvbuf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int setvbuf(FILE *restrict, char *restrict, int, size_t) + * } + */ + public static MethodHandle setvbuf$handle() { + return setvbuf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int setvbuf(FILE *restrict, char *restrict, int, size_t) + * } + */ + public static MemorySegment setvbuf$address() { + return setvbuf.ADDR; + } + + /** + * {@snippet lang=c : + * int setvbuf(FILE *restrict, char *restrict, int, size_t) + * } + */ + public static int setvbuf(MemorySegment x0, MemorySegment x1, int x2, long x3) { + var mh$ = setvbuf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("setvbuf", x0, x1, x2, x3); + } + return (int)mh$.invokeExact(x0, x1, x2, x3); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + /** + * Variadic invoker class for: + * {@snippet lang=c : + * int sprintf(char *restrict, const char *restrict, ...) + * } + */ + public static class sprintf { + private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + private static final MemorySegment ADDR = somelib_h.findOrThrow("sprintf"); + + private final MethodHandle handle; + private final FunctionDescriptor descriptor; + private final MethodHandle spreader; + + private sprintf(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) { + this.handle = handle; + this.descriptor = descriptor; + this.spreader = spreader; + } + + /** + * Variadic invoker factory for: + * {@snippet lang=c : + * int sprintf(char *restrict, const char *restrict, ...) + * } + */ + public static sprintf makeInvoker(MemoryLayout... layouts) { + FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts); + Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size()); + var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$); + var spreader$ = mh$.asSpreader(Object[].class, layouts.length); + return new sprintf(mh$, desc$, spreader$); + } + + /** + * {@return the address} + */ + public static MemorySegment address() { + return ADDR; + } + + /** + * {@return the specialized method handle} + */ + public MethodHandle handle() { + return handle; + } + + /** + * {@return the specialized descriptor} + */ + public FunctionDescriptor descriptor() { + return descriptor; + } + + public int apply(MemorySegment x0, MemorySegment x1, Object... x2) { + try { + if (TRACE_DOWNCALLS) { + traceDowncall("sprintf", x0, x1, x2); + } + return (int)spreader.invokeExact(x0, x1, x2); + } catch(IllegalArgumentException | ClassCastException ex$) { + throw ex$; // rethrow IAE from passing wrong number/type of args + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + /** + * Variadic invoker class for: + * {@snippet lang=c : + * int sscanf(const char *restrict, const char *restrict, ...) + * } + */ + public static class sscanf { + private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + private static final MemorySegment ADDR = somelib_h.findOrThrow("sscanf"); + + private final MethodHandle handle; + private final FunctionDescriptor descriptor; + private final MethodHandle spreader; + + private sscanf(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) { + this.handle = handle; + this.descriptor = descriptor; + this.spreader = spreader; + } + + /** + * Variadic invoker factory for: + * {@snippet lang=c : + * int sscanf(const char *restrict, const char *restrict, ...) + * } + */ + public static sscanf makeInvoker(MemoryLayout... layouts) { + FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts); + Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size()); + var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$); + var spreader$ = mh$.asSpreader(Object[].class, layouts.length); + return new sscanf(mh$, desc$, spreader$); + } + + /** + * {@return the address} + */ + public static MemorySegment address() { + return ADDR; + } + + /** + * {@return the specialized method handle} + */ + public MethodHandle handle() { + return handle; + } + + /** + * {@return the specialized descriptor} + */ + public FunctionDescriptor descriptor() { + return descriptor; + } + + public int apply(MemorySegment x0, MemorySegment x1, Object... x2) { + try { + if (TRACE_DOWNCALLS) { + traceDowncall("sscanf", x0, x1, x2); + } + return (int)spreader.invokeExact(x0, x1, x2); + } catch(IllegalArgumentException | ClassCastException ex$) { + throw ex$; // rethrow IAE from passing wrong number/type of args + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static class tmpfile { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("tmpfile"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * FILE *tmpfile() + * } + */ + public static FunctionDescriptor tmpfile$descriptor() { + return tmpfile.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * FILE *tmpfile() + * } + */ + public static MethodHandle tmpfile$handle() { + return tmpfile.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * FILE *tmpfile() + * } + */ + public static MemorySegment tmpfile$address() { + return tmpfile.ADDR; + } + + /** + * {@snippet lang=c : + * FILE *tmpfile() + * } + */ + public static MemorySegment tmpfile() { + var mh$ = tmpfile.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("tmpfile"); + } + return (MemorySegment)mh$.invokeExact(); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class tmpnam { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("tmpnam"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * char *tmpnam(char *) + * } + */ + public static FunctionDescriptor tmpnam$descriptor() { + return tmpnam.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * char *tmpnam(char *) + * } + */ + public static MethodHandle tmpnam$handle() { + return tmpnam.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * char *tmpnam(char *) + * } + */ + public static MemorySegment tmpnam$address() { + return tmpnam.ADDR; + } + + /** + * {@snippet lang=c : + * char *tmpnam(char *) + * } + */ + public static MemorySegment tmpnam(MemorySegment x0) { + var mh$ = tmpnam.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("tmpnam", x0); + } + return (MemorySegment)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class ungetc { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("ungetc"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int ungetc(int, FILE *) + * } + */ + public static FunctionDescriptor ungetc$descriptor() { + return ungetc.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int ungetc(int, FILE *) + * } + */ + public static MethodHandle ungetc$handle() { + return ungetc.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int ungetc(int, FILE *) + * } + */ + public static MemorySegment ungetc$address() { + return ungetc.ADDR; + } + + /** + * {@snippet lang=c : + * int ungetc(int, FILE *) + * } + */ + public static int ungetc(int x0, MemorySegment x1) { + var mh$ = ungetc.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("ungetc", x0, x1); + } + return (int)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class vfprintf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("vfprintf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int vfprintf(FILE *restrict, const char *restrict, va_list) + * } + */ + public static FunctionDescriptor vfprintf$descriptor() { + return vfprintf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int vfprintf(FILE *restrict, const char *restrict, va_list) + * } + */ + public static MethodHandle vfprintf$handle() { + return vfprintf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int vfprintf(FILE *restrict, const char *restrict, va_list) + * } + */ + public static MemorySegment vfprintf$address() { + return vfprintf.ADDR; + } + + /** + * {@snippet lang=c : + * int vfprintf(FILE *restrict, const char *restrict, va_list) + * } + */ + public static int vfprintf(MemorySegment x0, MemorySegment x1, MemorySegment x2) { + var mh$ = vfprintf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("vfprintf", x0, x1, x2); + } + return (int)mh$.invokeExact(x0, x1, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class vprintf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("vprintf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int vprintf(const char *restrict, va_list) + * } + */ + public static FunctionDescriptor vprintf$descriptor() { + return vprintf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int vprintf(const char *restrict, va_list) + * } + */ + public static MethodHandle vprintf$handle() { + return vprintf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int vprintf(const char *restrict, va_list) + * } + */ + public static MemorySegment vprintf$address() { + return vprintf.ADDR; + } + + /** + * {@snippet lang=c : + * int vprintf(const char *restrict, va_list) + * } + */ + public static int vprintf(MemorySegment x0, MemorySegment x1) { + var mh$ = vprintf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("vprintf", x0, x1); + } + return (int)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class vsprintf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("vsprintf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int vsprintf(char *restrict, const char *restrict, va_list) + * } + */ + public static FunctionDescriptor vsprintf$descriptor() { + return vsprintf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int vsprintf(char *restrict, const char *restrict, va_list) + * } + */ + public static MethodHandle vsprintf$handle() { + return vsprintf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int vsprintf(char *restrict, const char *restrict, va_list) + * } + */ + public static MemorySegment vsprintf$address() { + return vsprintf.ADDR; + } + + /** + * {@snippet lang=c : + * int vsprintf(char *restrict, const char *restrict, va_list) + * } + */ + public static int vsprintf(MemorySegment x0, MemorySegment x1, MemorySegment x2) { + var mh$ = vsprintf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("vsprintf", x0, x1, x2); + } + return (int)mh$.invokeExact(x0, x1, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class ctermid { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("ctermid"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * char *ctermid(char *) + * } + */ + public static FunctionDescriptor ctermid$descriptor() { + return ctermid.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * char *ctermid(char *) + * } + */ + public static MethodHandle ctermid$handle() { + return ctermid.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * char *ctermid(char *) + * } + */ + public static MemorySegment ctermid$address() { + return ctermid.ADDR; + } + + /** + * {@snippet lang=c : + * char *ctermid(char *) + * } + */ + public static MemorySegment ctermid(MemorySegment x0) { + var mh$ = ctermid.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("ctermid", x0); + } + return (MemorySegment)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fdopen { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fdopen"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * FILE *fdopen(int, const char *) + * } + */ + public static FunctionDescriptor fdopen$descriptor() { + return fdopen.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * FILE *fdopen(int, const char *) + * } + */ + public static MethodHandle fdopen$handle() { + return fdopen.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * FILE *fdopen(int, const char *) + * } + */ + public static MemorySegment fdopen$address() { + return fdopen.ADDR; + } + + /** + * {@snippet lang=c : + * FILE *fdopen(int, const char *) + * } + */ + public static MemorySegment fdopen(int x0, MemorySegment x1) { + var mh$ = fdopen.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fdopen", x0, x1); + } + return (MemorySegment)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fileno { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fileno"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int fileno(FILE *) + * } + */ + public static FunctionDescriptor fileno$descriptor() { + return fileno.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int fileno(FILE *) + * } + */ + public static MethodHandle fileno$handle() { + return fileno.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int fileno(FILE *) + * } + */ + public static MemorySegment fileno$address() { + return fileno.ADDR; + } + + /** + * {@snippet lang=c : + * int fileno(FILE *) + * } + */ + public static int fileno(MemorySegment x0) { + var mh$ = fileno.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fileno", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class pclose { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("pclose"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int pclose(FILE *) + * } + */ + public static FunctionDescriptor pclose$descriptor() { + return pclose.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int pclose(FILE *) + * } + */ + public static MethodHandle pclose$handle() { + return pclose.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int pclose(FILE *) + * } + */ + public static MemorySegment pclose$address() { + return pclose.ADDR; + } + + /** + * {@snippet lang=c : + * int pclose(FILE *) + * } + */ + public static int pclose(MemorySegment x0) { + var mh$ = pclose.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("pclose", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class popen { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("popen"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * FILE *popen(const char *, const char *) + * } + */ + public static FunctionDescriptor popen$descriptor() { + return popen.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * FILE *popen(const char *, const char *) + * } + */ + public static MethodHandle popen$handle() { + return popen.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * FILE *popen(const char *, const char *) + * } + */ + public static MemorySegment popen$address() { + return popen.ADDR; + } + + /** + * {@snippet lang=c : + * FILE *popen(const char *, const char *) + * } + */ + public static MemorySegment popen(MemorySegment x0, MemorySegment x1) { + var mh$ = popen.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("popen", x0, x1); + } + return (MemorySegment)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class __srget { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("__srget"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int __srget(FILE *) + * } + */ + public static FunctionDescriptor __srget$descriptor() { + return __srget.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int __srget(FILE *) + * } + */ + public static MethodHandle __srget$handle() { + return __srget.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int __srget(FILE *) + * } + */ + public static MemorySegment __srget$address() { + return __srget.ADDR; + } + + /** + * {@snippet lang=c : + * int __srget(FILE *) + * } + */ + public static int __srget(MemorySegment x0) { + var mh$ = __srget.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("__srget", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class __svfscanf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("__svfscanf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int __svfscanf(FILE *, const char *, va_list) + * } + */ + public static FunctionDescriptor __svfscanf$descriptor() { + return __svfscanf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int __svfscanf(FILE *, const char *, va_list) + * } + */ + public static MethodHandle __svfscanf$handle() { + return __svfscanf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int __svfscanf(FILE *, const char *, va_list) + * } + */ + public static MemorySegment __svfscanf$address() { + return __svfscanf.ADDR; + } + + /** + * {@snippet lang=c : + * int __svfscanf(FILE *, const char *, va_list) + * } + */ + public static int __svfscanf(MemorySegment x0, MemorySegment x1, MemorySegment x2) { + var mh$ = __svfscanf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("__svfscanf", x0, x1, x2); + } + return (int)mh$.invokeExact(x0, x1, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class __swbuf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("__swbuf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int __swbuf(int, FILE *) + * } + */ + public static FunctionDescriptor __swbuf$descriptor() { + return __swbuf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int __swbuf(int, FILE *) + * } + */ + public static MethodHandle __swbuf$handle() { + return __swbuf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int __swbuf(int, FILE *) + * } + */ + public static MemorySegment __swbuf$address() { + return __swbuf.ADDR; + } + + /** + * {@snippet lang=c : + * int __swbuf(int, FILE *) + * } + */ + public static int __swbuf(int x0, MemorySegment x1) { + var mh$ = __swbuf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("__swbuf", x0, x1); + } + return (int)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class flockfile { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("flockfile"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void flockfile(FILE *) + * } + */ + public static FunctionDescriptor flockfile$descriptor() { + return flockfile.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void flockfile(FILE *) + * } + */ + public static MethodHandle flockfile$handle() { + return flockfile.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void flockfile(FILE *) + * } + */ + public static MemorySegment flockfile$address() { + return flockfile.ADDR; + } + + /** + * {@snippet lang=c : + * void flockfile(FILE *) + * } + */ + public static void flockfile(MemorySegment x0) { + var mh$ = flockfile.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("flockfile", x0); + } + mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class ftrylockfile { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("ftrylockfile"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int ftrylockfile(FILE *) + * } + */ + public static FunctionDescriptor ftrylockfile$descriptor() { + return ftrylockfile.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int ftrylockfile(FILE *) + * } + */ + public static MethodHandle ftrylockfile$handle() { + return ftrylockfile.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int ftrylockfile(FILE *) + * } + */ + public static MemorySegment ftrylockfile$address() { + return ftrylockfile.ADDR; + } + + /** + * {@snippet lang=c : + * int ftrylockfile(FILE *) + * } + */ + public static int ftrylockfile(MemorySegment x0) { + var mh$ = ftrylockfile.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("ftrylockfile", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class funlockfile { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("funlockfile"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void funlockfile(FILE *) + * } + */ + public static FunctionDescriptor funlockfile$descriptor() { + return funlockfile.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void funlockfile(FILE *) + * } + */ + public static MethodHandle funlockfile$handle() { + return funlockfile.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void funlockfile(FILE *) + * } + */ + public static MemorySegment funlockfile$address() { + return funlockfile.ADDR; + } + + /** + * {@snippet lang=c : + * void funlockfile(FILE *) + * } + */ + public static void funlockfile(MemorySegment x0) { + var mh$ = funlockfile.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("funlockfile", x0); + } + mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class getc_unlocked { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("getc_unlocked"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int getc_unlocked(FILE *) + * } + */ + public static FunctionDescriptor getc_unlocked$descriptor() { + return getc_unlocked.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int getc_unlocked(FILE *) + * } + */ + public static MethodHandle getc_unlocked$handle() { + return getc_unlocked.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int getc_unlocked(FILE *) + * } + */ + public static MemorySegment getc_unlocked$address() { + return getc_unlocked.ADDR; + } + + /** + * {@snippet lang=c : + * int getc_unlocked(FILE *) + * } + */ + public static int getc_unlocked(MemorySegment x0) { + var mh$ = getc_unlocked.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("getc_unlocked", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class getchar_unlocked { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("getchar_unlocked"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int getchar_unlocked() + * } + */ + public static FunctionDescriptor getchar_unlocked$descriptor() { + return getchar_unlocked.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int getchar_unlocked() + * } + */ + public static MethodHandle getchar_unlocked$handle() { + return getchar_unlocked.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int getchar_unlocked() + * } + */ + public static MemorySegment getchar_unlocked$address() { + return getchar_unlocked.ADDR; + } + + /** + * {@snippet lang=c : + * int getchar_unlocked() + * } + */ + public static int getchar_unlocked() { + var mh$ = getchar_unlocked.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("getchar_unlocked"); + } + return (int)mh$.invokeExact(); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class putc_unlocked { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("putc_unlocked"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int putc_unlocked(int, FILE *) + * } + */ + public static FunctionDescriptor putc_unlocked$descriptor() { + return putc_unlocked.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int putc_unlocked(int, FILE *) + * } + */ + public static MethodHandle putc_unlocked$handle() { + return putc_unlocked.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int putc_unlocked(int, FILE *) + * } + */ + public static MemorySegment putc_unlocked$address() { + return putc_unlocked.ADDR; + } + + /** + * {@snippet lang=c : + * int putc_unlocked(int, FILE *) + * } + */ + public static int putc_unlocked(int x0, MemorySegment x1) { + var mh$ = putc_unlocked.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("putc_unlocked", x0, x1); + } + return (int)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class putchar_unlocked { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_INT + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("putchar_unlocked"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int putchar_unlocked(int) + * } + */ + public static FunctionDescriptor putchar_unlocked$descriptor() { + return putchar_unlocked.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int putchar_unlocked(int) + * } + */ + public static MethodHandle putchar_unlocked$handle() { + return putchar_unlocked.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int putchar_unlocked(int) + * } + */ + public static MemorySegment putchar_unlocked$address() { + return putchar_unlocked.ADDR; + } + + /** + * {@snippet lang=c : + * int putchar_unlocked(int) + * } + */ + public static int putchar_unlocked(int x0) { + var mh$ = putchar_unlocked.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("putchar_unlocked", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class getw { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("getw"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int getw(FILE *) + * } + */ + public static FunctionDescriptor getw$descriptor() { + return getw.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int getw(FILE *) + * } + */ + public static MethodHandle getw$handle() { + return getw.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int getw(FILE *) + * } + */ + public static MemorySegment getw$address() { + return getw.ADDR; + } + + /** + * {@snippet lang=c : + * int getw(FILE *) + * } + */ + public static int getw(MemorySegment x0) { + var mh$ = getw.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("getw", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class putw { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("putw"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int putw(int, FILE *) + * } + */ + public static FunctionDescriptor putw$descriptor() { + return putw.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int putw(int, FILE *) + * } + */ + public static MethodHandle putw$handle() { + return putw.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int putw(int, FILE *) + * } + */ + public static MemorySegment putw$address() { + return putw.ADDR; + } + + /** + * {@snippet lang=c : + * int putw(int, FILE *) + * } + */ + public static int putw(int x0, MemorySegment x1) { + var mh$ = putw.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("putw", x0, x1); + } + return (int)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class tempnam { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("tempnam"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * char *tempnam(const char *__dir, const char *__prefix) + * } + */ + public static FunctionDescriptor tempnam$descriptor() { + return tempnam.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * char *tempnam(const char *__dir, const char *__prefix) + * } + */ + public static MethodHandle tempnam$handle() { + return tempnam.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * char *tempnam(const char *__dir, const char *__prefix) + * } + */ + public static MemorySegment tempnam$address() { + return tempnam.ADDR; + } + + /** + * {@snippet lang=c : + * char *tempnam(const char *__dir, const char *__prefix) + * } + */ + public static MemorySegment tempnam(MemorySegment __dir, MemorySegment __prefix) { + var mh$ = tempnam.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("tempnam", __dir, __prefix); + } + return (MemorySegment)mh$.invokeExact(__dir, __prefix); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + /** + * {@snippet lang=c : + * typedef __darwin_off_t off_t + * } + */ + public static final OfLong off_t = somelib_h.C_LONG_LONG; + + private static class fseeko { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_LONG_LONG, + somelib_h.C_INT + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fseeko"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int fseeko(FILE *__stream, off_t __offset, int __whence) + * } + */ + public static FunctionDescriptor fseeko$descriptor() { + return fseeko.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int fseeko(FILE *__stream, off_t __offset, int __whence) + * } + */ + public static MethodHandle fseeko$handle() { + return fseeko.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int fseeko(FILE *__stream, off_t __offset, int __whence) + * } + */ + public static MemorySegment fseeko$address() { + return fseeko.ADDR; + } + + /** + * {@snippet lang=c : + * int fseeko(FILE *__stream, off_t __offset, int __whence) + * } + */ + public static int fseeko(MemorySegment __stream, long __offset, int __whence) { + var mh$ = fseeko.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fseeko", __stream, __offset, __whence); + } + return (int)mh$.invokeExact(__stream, __offset, __whence); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class ftello { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_LONG_LONG, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("ftello"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * off_t ftello(FILE *__stream) + * } + */ + public static FunctionDescriptor ftello$descriptor() { + return ftello.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * off_t ftello(FILE *__stream) + * } + */ + public static MethodHandle ftello$handle() { + return ftello.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * off_t ftello(FILE *__stream) + * } + */ + public static MemorySegment ftello$address() { + return ftello.ADDR; + } + + /** + * {@snippet lang=c : + * off_t ftello(FILE *__stream) + * } + */ + public static long ftello(MemorySegment __stream) { + var mh$ = ftello.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("ftello", __stream); + } + return (long)mh$.invokeExact(__stream); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + /** + * Variadic invoker class for: + * {@snippet lang=c : + * int snprintf(char *restrict __str, size_t __size, const char *restrict __format, ...) + * } + */ + public static class snprintf { + private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_LONG, + somelib_h.C_POINTER + ); + private static final MemorySegment ADDR = somelib_h.findOrThrow("snprintf"); + + private final MethodHandle handle; + private final FunctionDescriptor descriptor; + private final MethodHandle spreader; + + private snprintf(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) { + this.handle = handle; + this.descriptor = descriptor; + this.spreader = spreader; + } + + /** + * Variadic invoker factory for: + * {@snippet lang=c : + * int snprintf(char *restrict __str, size_t __size, const char *restrict __format, ...) + * } + */ + public static snprintf makeInvoker(MemoryLayout... layouts) { + FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts); + Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size()); + var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$); + var spreader$ = mh$.asSpreader(Object[].class, layouts.length); + return new snprintf(mh$, desc$, spreader$); + } + + /** + * {@return the address} + */ + public static MemorySegment address() { + return ADDR; + } + + /** + * {@return the specialized method handle} + */ + public MethodHandle handle() { + return handle; + } + + /** + * {@return the specialized descriptor} + */ + public FunctionDescriptor descriptor() { + return descriptor; + } + + public int apply(MemorySegment __str, long __size, MemorySegment __format, Object... x3) { + try { + if (TRACE_DOWNCALLS) { + traceDowncall("snprintf", __str, __size, __format, x3); + } + return (int)spreader.invokeExact(__str, __size, __format, x3); + } catch(IllegalArgumentException | ClassCastException ex$) { + throw ex$; // rethrow IAE from passing wrong number/type of args + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static class vfscanf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("vfscanf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int vfscanf(FILE *restrict __stream, const char *restrict __format, va_list) + * } + */ + public static FunctionDescriptor vfscanf$descriptor() { + return vfscanf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int vfscanf(FILE *restrict __stream, const char *restrict __format, va_list) + * } + */ + public static MethodHandle vfscanf$handle() { + return vfscanf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int vfscanf(FILE *restrict __stream, const char *restrict __format, va_list) + * } + */ + public static MemorySegment vfscanf$address() { + return vfscanf.ADDR; + } + + /** + * {@snippet lang=c : + * int vfscanf(FILE *restrict __stream, const char *restrict __format, va_list) + * } + */ + public static int vfscanf(MemorySegment __stream, MemorySegment __format, MemorySegment x2) { + var mh$ = vfscanf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("vfscanf", __stream, __format, x2); + } + return (int)mh$.invokeExact(__stream, __format, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class vscanf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("vscanf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int vscanf(const char *restrict __format, va_list) + * } + */ + public static FunctionDescriptor vscanf$descriptor() { + return vscanf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int vscanf(const char *restrict __format, va_list) + * } + */ + public static MethodHandle vscanf$handle() { + return vscanf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int vscanf(const char *restrict __format, va_list) + * } + */ + public static MemorySegment vscanf$address() { + return vscanf.ADDR; + } + + /** + * {@snippet lang=c : + * int vscanf(const char *restrict __format, va_list) + * } + */ + public static int vscanf(MemorySegment __format, MemorySegment x1) { + var mh$ = vscanf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("vscanf", __format, x1); + } + return (int)mh$.invokeExact(__format, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class vsnprintf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_LONG, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("vsnprintf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int vsnprintf(char *restrict __str, size_t __size, const char *restrict __format, va_list) + * } + */ + public static FunctionDescriptor vsnprintf$descriptor() { + return vsnprintf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int vsnprintf(char *restrict __str, size_t __size, const char *restrict __format, va_list) + * } + */ + public static MethodHandle vsnprintf$handle() { + return vsnprintf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int vsnprintf(char *restrict __str, size_t __size, const char *restrict __format, va_list) + * } + */ + public static MemorySegment vsnprintf$address() { + return vsnprintf.ADDR; + } + + /** + * {@snippet lang=c : + * int vsnprintf(char *restrict __str, size_t __size, const char *restrict __format, va_list) + * } + */ + public static int vsnprintf(MemorySegment __str, long __size, MemorySegment __format, MemorySegment x3) { + var mh$ = vsnprintf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("vsnprintf", __str, __size, __format, x3); + } + return (int)mh$.invokeExact(__str, __size, __format, x3); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class vsscanf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("vsscanf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int vsscanf(const char *restrict __str, const char *restrict __format, va_list) + * } + */ + public static FunctionDescriptor vsscanf$descriptor() { + return vsscanf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int vsscanf(const char *restrict __str, const char *restrict __format, va_list) + * } + */ + public static MethodHandle vsscanf$handle() { + return vsscanf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int vsscanf(const char *restrict __str, const char *restrict __format, va_list) + * } + */ + public static MemorySegment vsscanf$address() { + return vsscanf.ADDR; + } + + /** + * {@snippet lang=c : + * int vsscanf(const char *restrict __str, const char *restrict __format, va_list) + * } + */ + public static int vsscanf(MemorySegment __str, MemorySegment __format, MemorySegment x2) { + var mh$ = vsscanf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("vsscanf", __str, __format, x2); + } + return (int)mh$.invokeExact(__str, __format, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + /** + * {@snippet lang=c : + * typedef __darwin_ssize_t ssize_t + * } + */ + public static final OfLong ssize_t = somelib_h.C_LONG; + + /** + * Variadic invoker class for: + * {@snippet lang=c : + * int dprintf(int, const char *restrict, ...) + * } + */ + public static class dprintf { + private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_INT, + somelib_h.C_POINTER + ); + private static final MemorySegment ADDR = somelib_h.findOrThrow("dprintf"); + + private final MethodHandle handle; + private final FunctionDescriptor descriptor; + private final MethodHandle spreader; + + private dprintf(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) { + this.handle = handle; + this.descriptor = descriptor; + this.spreader = spreader; + } + + /** + * Variadic invoker factory for: + * {@snippet lang=c : + * int dprintf(int, const char *restrict, ...) + * } + */ + public static dprintf makeInvoker(MemoryLayout... layouts) { + FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts); + Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size()); + var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$); + var spreader$ = mh$.asSpreader(Object[].class, layouts.length); + return new dprintf(mh$, desc$, spreader$); + } + + /** + * {@return the address} + */ + public static MemorySegment address() { + return ADDR; + } + + /** + * {@return the specialized method handle} + */ + public MethodHandle handle() { + return handle; + } + + /** + * {@return the specialized descriptor} + */ + public FunctionDescriptor descriptor() { + return descriptor; + } + + public int apply(int x0, MemorySegment x1, Object... x2) { + try { + if (TRACE_DOWNCALLS) { + traceDowncall("dprintf", x0, x1, x2); + } + return (int)spreader.invokeExact(x0, x1, x2); + } catch(IllegalArgumentException | ClassCastException ex$) { + throw ex$; // rethrow IAE from passing wrong number/type of args + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static class vdprintf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("vdprintf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int vdprintf(int, const char *restrict, va_list) + * } + */ + public static FunctionDescriptor vdprintf$descriptor() { + return vdprintf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int vdprintf(int, const char *restrict, va_list) + * } + */ + public static MethodHandle vdprintf$handle() { + return vdprintf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int vdprintf(int, const char *restrict, va_list) + * } + */ + public static MemorySegment vdprintf$address() { + return vdprintf.ADDR; + } + + /** + * {@snippet lang=c : + * int vdprintf(int, const char *restrict, va_list) + * } + */ + public static int vdprintf(int x0, MemorySegment x1, MemorySegment x2) { + var mh$ = vdprintf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("vdprintf", x0, x1, x2); + } + return (int)mh$.invokeExact(x0, x1, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class getdelim { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_LONG, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("getdelim"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * ssize_t getdelim(char **restrict __linep, size_t *restrict __linecapp, int __delimiter, FILE *restrict __stream) + * } + */ + public static FunctionDescriptor getdelim$descriptor() { + return getdelim.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * ssize_t getdelim(char **restrict __linep, size_t *restrict __linecapp, int __delimiter, FILE *restrict __stream) + * } + */ + public static MethodHandle getdelim$handle() { + return getdelim.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * ssize_t getdelim(char **restrict __linep, size_t *restrict __linecapp, int __delimiter, FILE *restrict __stream) + * } + */ + public static MemorySegment getdelim$address() { + return getdelim.ADDR; + } + + /** + * {@snippet lang=c : + * ssize_t getdelim(char **restrict __linep, size_t *restrict __linecapp, int __delimiter, FILE *restrict __stream) + * } + */ + public static long getdelim(MemorySegment __linep, MemorySegment __linecapp, int __delimiter, MemorySegment __stream) { + var mh$ = getdelim.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("getdelim", __linep, __linecapp, __delimiter, __stream); + } + return (long)mh$.invokeExact(__linep, __linecapp, __delimiter, __stream); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class getline { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_LONG, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("getline"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * ssize_t getline(char **restrict __linep, size_t *restrict __linecapp, FILE *restrict __stream) + * } + */ + public static FunctionDescriptor getline$descriptor() { + return getline.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * ssize_t getline(char **restrict __linep, size_t *restrict __linecapp, FILE *restrict __stream) + * } + */ + public static MethodHandle getline$handle() { + return getline.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * ssize_t getline(char **restrict __linep, size_t *restrict __linecapp, FILE *restrict __stream) + * } + */ + public static MemorySegment getline$address() { + return getline.ADDR; + } + + /** + * {@snippet lang=c : + * ssize_t getline(char **restrict __linep, size_t *restrict __linecapp, FILE *restrict __stream) + * } + */ + public static long getline(MemorySegment __linep, MemorySegment __linecapp, MemorySegment __stream) { + var mh$ = getline.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("getline", __linep, __linecapp, __stream); + } + return (long)mh$.invokeExact(__linep, __linecapp, __stream); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fmemopen { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_LONG, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fmemopen"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * FILE *fmemopen(void *restrict __buf, size_t __size, const char *restrict __mode) + * } + */ + public static FunctionDescriptor fmemopen$descriptor() { + return fmemopen.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * FILE *fmemopen(void *restrict __buf, size_t __size, const char *restrict __mode) + * } + */ + public static MethodHandle fmemopen$handle() { + return fmemopen.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * FILE *fmemopen(void *restrict __buf, size_t __size, const char *restrict __mode) + * } + */ + public static MemorySegment fmemopen$address() { + return fmemopen.ADDR; + } + + /** + * {@snippet lang=c : + * FILE *fmemopen(void *restrict __buf, size_t __size, const char *restrict __mode) + * } + */ + public static MemorySegment fmemopen(MemorySegment __buf, long __size, MemorySegment __mode) { + var mh$ = fmemopen.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fmemopen", __buf, __size, __mode); + } + return (MemorySegment)mh$.invokeExact(__buf, __size, __mode); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class open_memstream { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("open_memstream"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * FILE *open_memstream(char **__bufp, size_t *__sizep) + * } + */ + public static FunctionDescriptor open_memstream$descriptor() { + return open_memstream.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * FILE *open_memstream(char **__bufp, size_t *__sizep) + * } + */ + public static MethodHandle open_memstream$handle() { + return open_memstream.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * FILE *open_memstream(char **__bufp, size_t *__sizep) + * } + */ + public static MemorySegment open_memstream$address() { + return open_memstream.ADDR; + } + + /** + * {@snippet lang=c : + * FILE *open_memstream(char **__bufp, size_t *__sizep) + * } + */ + public static MemorySegment open_memstream(MemorySegment __bufp, MemorySegment __sizep) { + var mh$ = open_memstream.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("open_memstream", __bufp, __sizep); + } + return (MemorySegment)mh$.invokeExact(__bufp, __sizep); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class sys_nerr$constants { + public static final OfInt LAYOUT = somelib_h.C_INT; + public static final MemorySegment SEGMENT = somelib_h.findOrThrow("sys_nerr").reinterpret(LAYOUT.byteSize()); + } + + /** + * Layout for variable: + * {@snippet lang=c : + * extern const int sys_nerr + * } + */ + public static OfInt sys_nerr$layout() { + return sys_nerr$constants.LAYOUT; + } + + /** + * Segment for variable: + * {@snippet lang=c : + * extern const int sys_nerr + * } + */ + public static MemorySegment sys_nerr$segment() { + return sys_nerr$constants.SEGMENT; + } + + /** + * Getter for variable: + * {@snippet lang=c : + * extern const int sys_nerr + * } + */ + public static int sys_nerr() { + return sys_nerr$constants.SEGMENT.get(sys_nerr$constants.LAYOUT, 0L); + } + + /** + * Setter for variable: + * {@snippet lang=c : + * extern const int sys_nerr + * } + */ + public static void sys_nerr(int varValue) { + sys_nerr$constants.SEGMENT.set(sys_nerr$constants.LAYOUT, 0L, varValue); + } + + private static class sys_errlist$constants { + public static final SequenceLayout LAYOUT = MemoryLayout.sequenceLayout(0, somelib_h.C_POINTER); + public static final MemorySegment SEGMENT = somelib_h.findOrThrow("sys_errlist").reinterpret(LAYOUT.byteSize()); + public static final VarHandle HANDLE = LAYOUT.varHandle(); + + public static final long[] DIMS = { }; + } + + /** + * Layout for variable: + * {@snippet lang=c : + * extern const char *const sys_errlist[] + * } + */ + public static SequenceLayout sys_errlist$layout() { + return sys_errlist$constants.LAYOUT; + } + + /** + * Dimensions for array variable: + * {@snippet lang=c : + * extern const char *const sys_errlist[] + * } + */ + public static long[] sys_errlist$dimensions() { + return sys_errlist$constants.DIMS; + } + + /** + * Getter for variable: + * {@snippet lang=c : + * extern const char *const sys_errlist[] + * } + */ + public static MemorySegment sys_errlist() { + return sys_errlist$constants.SEGMENT; + } + + /** + * Setter for variable: + * {@snippet lang=c : + * extern const char *const sys_errlist[] + * } + */ + public static void sys_errlist(MemorySegment varValue) { + MemorySegment.copy(varValue, 0L, sys_errlist$constants.SEGMENT, 0L, sys_errlist$constants.LAYOUT.byteSize()); + } + + /** + * Variadic invoker class for: + * {@snippet lang=c : + * int asprintf(char **restrict, const char *restrict, ...) + * } + */ + public static class asprintf { + private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + private static final MemorySegment ADDR = somelib_h.findOrThrow("asprintf"); + + private final MethodHandle handle; + private final FunctionDescriptor descriptor; + private final MethodHandle spreader; + + private asprintf(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) { + this.handle = handle; + this.descriptor = descriptor; + this.spreader = spreader; + } + + /** + * Variadic invoker factory for: + * {@snippet lang=c : + * int asprintf(char **restrict, const char *restrict, ...) + * } + */ + public static asprintf makeInvoker(MemoryLayout... layouts) { + FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts); + Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size()); + var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$); + var spreader$ = mh$.asSpreader(Object[].class, layouts.length); + return new asprintf(mh$, desc$, spreader$); + } + + /** + * {@return the address} + */ + public static MemorySegment address() { + return ADDR; + } + + /** + * {@return the specialized method handle} + */ + public MethodHandle handle() { + return handle; + } + + /** + * {@return the specialized descriptor} + */ + public FunctionDescriptor descriptor() { + return descriptor; + } + + public int apply(MemorySegment x0, MemorySegment x1, Object... x2) { + try { + if (TRACE_DOWNCALLS) { + traceDowncall("asprintf", x0, x1, x2); + } + return (int)spreader.invokeExact(x0, x1, x2); + } catch(IllegalArgumentException | ClassCastException ex$) { + throw ex$; // rethrow IAE from passing wrong number/type of args + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static class ctermid_r { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("ctermid_r"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * char *ctermid_r(char *) + * } + */ + public static FunctionDescriptor ctermid_r$descriptor() { + return ctermid_r.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * char *ctermid_r(char *) + * } + */ + public static MethodHandle ctermid_r$handle() { + return ctermid_r.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * char *ctermid_r(char *) + * } + */ + public static MemorySegment ctermid_r$address() { + return ctermid_r.ADDR; + } + + /** + * {@snippet lang=c : + * char *ctermid_r(char *) + * } + */ + public static MemorySegment ctermid_r(MemorySegment x0) { + var mh$ = ctermid_r.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("ctermid_r", x0); + } + return (MemorySegment)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fgetln { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fgetln"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * char *fgetln(FILE *, size_t *) + * } + */ + public static FunctionDescriptor fgetln$descriptor() { + return fgetln.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * char *fgetln(FILE *, size_t *) + * } + */ + public static MethodHandle fgetln$handle() { + return fgetln.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * char *fgetln(FILE *, size_t *) + * } + */ + public static MemorySegment fgetln$address() { + return fgetln.ADDR; + } + + /** + * {@snippet lang=c : + * char *fgetln(FILE *, size_t *) + * } + */ + public static MemorySegment fgetln(MemorySegment x0, MemorySegment x1) { + var mh$ = fgetln.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fgetln", x0, x1); + } + return (MemorySegment)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fmtcheck { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fmtcheck"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * const char *fmtcheck(const char *, const char *) + * } + */ + public static FunctionDescriptor fmtcheck$descriptor() { + return fmtcheck.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * const char *fmtcheck(const char *, const char *) + * } + */ + public static MethodHandle fmtcheck$handle() { + return fmtcheck.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * const char *fmtcheck(const char *, const char *) + * } + */ + public static MemorySegment fmtcheck$address() { + return fmtcheck.ADDR; + } + + /** + * {@snippet lang=c : + * const char *fmtcheck(const char *, const char *) + * } + */ + public static MemorySegment fmtcheck(MemorySegment x0, MemorySegment x1) { + var mh$ = fmtcheck.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fmtcheck", x0, x1); + } + return (MemorySegment)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class fpurge { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("fpurge"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int fpurge(FILE *) + * } + */ + public static FunctionDescriptor fpurge$descriptor() { + return fpurge.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int fpurge(FILE *) + * } + */ + public static MethodHandle fpurge$handle() { + return fpurge.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int fpurge(FILE *) + * } + */ + public static MemorySegment fpurge$address() { + return fpurge.ADDR; + } + + /** + * {@snippet lang=c : + * int fpurge(FILE *) + * } + */ + public static int fpurge(MemorySegment x0) { + var mh$ = fpurge.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("fpurge", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class setbuffer { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_INT + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("setbuffer"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void setbuffer(FILE *, char *, int) + * } + */ + public static FunctionDescriptor setbuffer$descriptor() { + return setbuffer.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void setbuffer(FILE *, char *, int) + * } + */ + public static MethodHandle setbuffer$handle() { + return setbuffer.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void setbuffer(FILE *, char *, int) + * } + */ + public static MemorySegment setbuffer$address() { + return setbuffer.ADDR; + } + + /** + * {@snippet lang=c : + * void setbuffer(FILE *, char *, int) + * } + */ + public static void setbuffer(MemorySegment x0, MemorySegment x1, int x2) { + var mh$ = setbuffer.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("setbuffer", x0, x1, x2); + } + mh$.invokeExact(x0, x1, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class setlinebuf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("setlinebuf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int setlinebuf(FILE *) + * } + */ + public static FunctionDescriptor setlinebuf$descriptor() { + return setlinebuf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int setlinebuf(FILE *) + * } + */ + public static MethodHandle setlinebuf$handle() { + return setlinebuf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int setlinebuf(FILE *) + * } + */ + public static MemorySegment setlinebuf$address() { + return setlinebuf.ADDR; + } + + /** + * {@snippet lang=c : + * int setlinebuf(FILE *) + * } + */ + public static int setlinebuf(MemorySegment x0) { + var mh$ = setlinebuf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("setlinebuf", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class vasprintf { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("vasprintf"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int vasprintf(char **restrict, const char *restrict, va_list) + * } + */ + public static FunctionDescriptor vasprintf$descriptor() { + return vasprintf.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int vasprintf(char **restrict, const char *restrict, va_list) + * } + */ + public static MethodHandle vasprintf$handle() { + return vasprintf.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int vasprintf(char **restrict, const char *restrict, va_list) + * } + */ + public static MemorySegment vasprintf$address() { + return vasprintf.ADDR; + } + + /** + * {@snippet lang=c : + * int vasprintf(char **restrict, const char *restrict, va_list) + * } + */ + public static int vasprintf(MemorySegment x0, MemorySegment x1, MemorySegment x2) { + var mh$ = vasprintf.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("vasprintf", x0, x1, x2); + } + return (int)mh$.invokeExact(x0, x1, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class funopen { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("funopen"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * FILE *funopen(const void *, int (* _Nullable)(void *, char *, int), int (* _Nullable)(void *, const char *, int), fpos_t (* _Nullable)(void *, fpos_t, int), int (* _Nullable)(void *)) + * } + */ + public static FunctionDescriptor funopen$descriptor() { + return funopen.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * FILE *funopen(const void *, int (* _Nullable)(void *, char *, int), int (* _Nullable)(void *, const char *, int), fpos_t (* _Nullable)(void *, fpos_t, int), int (* _Nullable)(void *)) + * } + */ + public static MethodHandle funopen$handle() { + return funopen.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * FILE *funopen(const void *, int (* _Nullable)(void *, char *, int), int (* _Nullable)(void *, const char *, int), fpos_t (* _Nullable)(void *, fpos_t, int), int (* _Nullable)(void *)) + * } + */ + public static MemorySegment funopen$address() { + return funopen.ADDR; + } + + /** + * {@snippet lang=c : + * FILE *funopen(const void *, int (* _Nullable)(void *, char *, int), int (* _Nullable)(void *, const char *, int), fpos_t (* _Nullable)(void *, fpos_t, int), int (* _Nullable)(void *)) + * } + */ + public static MemorySegment funopen(MemorySegment x0, MemorySegment x1, MemorySegment x2, MemorySegment x3, MemorySegment x4) { + var mh$ = funopen.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("funopen", x0, x1, x2, x3, x4); + } + return (MemorySegment)mh$.invokeExact(x0, x1, x2, x3, x4); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + /** + * Variadic invoker class for: + * {@snippet lang=c : + * extern int __sprintf_chk(char *restrict, int, size_t, const char *restrict, ...) + * } + */ + public static class __sprintf_chk { + private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_INT, + somelib_h.C_LONG, + somelib_h.C_POINTER + ); + private static final MemorySegment ADDR = somelib_h.findOrThrow("__sprintf_chk"); + + private final MethodHandle handle; + private final FunctionDescriptor descriptor; + private final MethodHandle spreader; + + private __sprintf_chk(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) { + this.handle = handle; + this.descriptor = descriptor; + this.spreader = spreader; + } + + /** + * Variadic invoker factory for: + * {@snippet lang=c : + * extern int __sprintf_chk(char *restrict, int, size_t, const char *restrict, ...) + * } + */ + public static __sprintf_chk makeInvoker(MemoryLayout... layouts) { + FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts); + Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size()); + var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$); + var spreader$ = mh$.asSpreader(Object[].class, layouts.length); + return new __sprintf_chk(mh$, desc$, spreader$); + } + + /** + * {@return the address} + */ + public static MemorySegment address() { + return ADDR; + } + + /** + * {@return the specialized method handle} + */ + public MethodHandle handle() { + return handle; + } + + /** + * {@return the specialized descriptor} + */ + public FunctionDescriptor descriptor() { + return descriptor; + } + + public int apply(MemorySegment x0, int x1, long x2, MemorySegment x3, Object... x4) { + try { + if (TRACE_DOWNCALLS) { + traceDowncall("__sprintf_chk", x0, x1, x2, x3, x4); + } + return (int)spreader.invokeExact(x0, x1, x2, x3, x4); + } catch(IllegalArgumentException | ClassCastException ex$) { + throw ex$; // rethrow IAE from passing wrong number/type of args + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + /** + * Variadic invoker class for: + * {@snippet lang=c : + * extern int __snprintf_chk(char *restrict, size_t, int, size_t, const char *restrict, ...) + * } + */ + public static class __snprintf_chk { + private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_LONG, + somelib_h.C_INT, + somelib_h.C_LONG, + somelib_h.C_POINTER + ); + private static final MemorySegment ADDR = somelib_h.findOrThrow("__snprintf_chk"); + + private final MethodHandle handle; + private final FunctionDescriptor descriptor; + private final MethodHandle spreader; + + private __snprintf_chk(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) { + this.handle = handle; + this.descriptor = descriptor; + this.spreader = spreader; + } + + /** + * Variadic invoker factory for: + * {@snippet lang=c : + * extern int __snprintf_chk(char *restrict, size_t, int, size_t, const char *restrict, ...) + * } + */ + public static __snprintf_chk makeInvoker(MemoryLayout... layouts) { + FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts); + Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size()); + var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$); + var spreader$ = mh$.asSpreader(Object[].class, layouts.length); + return new __snprintf_chk(mh$, desc$, spreader$); + } + + /** + * {@return the address} + */ + public static MemorySegment address() { + return ADDR; + } + + /** + * {@return the specialized method handle} + */ + public MethodHandle handle() { + return handle; + } + + /** + * {@return the specialized descriptor} + */ + public FunctionDescriptor descriptor() { + return descriptor; + } + + public int apply(MemorySegment x0, long x1, int x2, long x3, MemorySegment x4, Object... x5) { + try { + if (TRACE_DOWNCALLS) { + traceDowncall("__snprintf_chk", x0, x1, x2, x3, x4, x5); + } + return (int)spreader.invokeExact(x0, x1, x2, x3, x4, x5); + } catch(IllegalArgumentException | ClassCastException ex$) { + throw ex$; // rethrow IAE from passing wrong number/type of args + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static class __vsprintf_chk { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_INT, + somelib_h.C_LONG, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("__vsprintf_chk"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern int __vsprintf_chk(char *restrict, int, size_t, const char *restrict, va_list) + * } + */ + public static FunctionDescriptor __vsprintf_chk$descriptor() { + return __vsprintf_chk.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern int __vsprintf_chk(char *restrict, int, size_t, const char *restrict, va_list) + * } + */ + public static MethodHandle __vsprintf_chk$handle() { + return __vsprintf_chk.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * extern int __vsprintf_chk(char *restrict, int, size_t, const char *restrict, va_list) + * } + */ + public static MemorySegment __vsprintf_chk$address() { + return __vsprintf_chk.ADDR; + } + + /** + * {@snippet lang=c : + * extern int __vsprintf_chk(char *restrict, int, size_t, const char *restrict, va_list) + * } + */ + public static int __vsprintf_chk(MemorySegment x0, int x1, long x2, MemorySegment x3, MemorySegment x4) { + var mh$ = __vsprintf_chk.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("__vsprintf_chk", x0, x1, x2, x3, x4); + } + return (int)mh$.invokeExact(x0, x1, x2, x3, x4); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class __vsnprintf_chk { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT, + somelib_h.C_POINTER, + somelib_h.C_LONG, + somelib_h.C_INT, + somelib_h.C_LONG, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("__vsnprintf_chk"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern int __vsnprintf_chk(char *restrict, size_t, int, size_t, const char *restrict, va_list) + * } + */ + public static FunctionDescriptor __vsnprintf_chk$descriptor() { + return __vsnprintf_chk.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern int __vsnprintf_chk(char *restrict, size_t, int, size_t, const char *restrict, va_list) + * } + */ + public static MethodHandle __vsnprintf_chk$handle() { + return __vsnprintf_chk.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * extern int __vsnprintf_chk(char *restrict, size_t, int, size_t, const char *restrict, va_list) + * } + */ + public static MemorySegment __vsnprintf_chk$address() { + return __vsnprintf_chk.ADDR; + } + + /** + * {@snippet lang=c : + * extern int __vsnprintf_chk(char *restrict, size_t, int, size_t, const char *restrict, va_list) + * } + */ + public static int __vsnprintf_chk(MemorySegment x0, long x1, int x2, long x3, MemorySegment x4, MemorySegment x5) { + var mh$ = __vsnprintf_chk.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("__vsnprintf_chk", x0, x1, x2, x3, x4, x5); + } + return (int)mh$.invokeExact(x0, x1, x2, x3, x4, x5); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + private static final int UnimportedEnum_A = (int)0L; + /** + * {@snippet lang=c : + * enum UnimportedEnum.UnimportedEnum_A = 0 + * } + */ + public static int UnimportedEnum_A() { + return UnimportedEnum_A; + } + private static final int UnimportedEnum_B = (int)1L; + /** + * {@snippet lang=c : + * enum UnimportedEnum.UnimportedEnum_B = 1 + * } + */ + public static int UnimportedEnum_B() { + return UnimportedEnum_B; + } + private static final int UnimportedEnum_C = (int)2L; + /** + * {@snippet lang=c : + * enum UnimportedEnum.UnimportedEnum_C = 2 + * } + */ + public static int UnimportedEnum_C() { + return UnimportedEnum_C; + } + + private static class BorrowedFields_from_bar_and_strings { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + BorrowedFields.layout(), + somelib_h.C_POINTER, + DiplomatString16View.layout(), + DiplomatStringView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("BorrowedFields_from_bar_and_strings"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * BorrowedFields BorrowedFields_from_bar_and_strings(const Bar *bar, DiplomatString16View dstr16, DiplomatStringView utf8_str) + * } + */ + public static FunctionDescriptor BorrowedFields_from_bar_and_strings$descriptor() { + return BorrowedFields_from_bar_and_strings.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * BorrowedFields BorrowedFields_from_bar_and_strings(const Bar *bar, DiplomatString16View dstr16, DiplomatStringView utf8_str) + * } + */ + public static MethodHandle BorrowedFields_from_bar_and_strings$handle() { + return BorrowedFields_from_bar_and_strings.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * BorrowedFields BorrowedFields_from_bar_and_strings(const Bar *bar, DiplomatString16View dstr16, DiplomatStringView utf8_str) + * } + */ + public static MemorySegment BorrowedFields_from_bar_and_strings$address() { + return BorrowedFields_from_bar_and_strings.ADDR; + } + + /** + * {@snippet lang=c : + * BorrowedFields BorrowedFields_from_bar_and_strings(const Bar *bar, DiplomatString16View dstr16, DiplomatStringView utf8_str) + * } + */ + public static MemorySegment BorrowedFields_from_bar_and_strings(SegmentAllocator allocator, MemorySegment bar, MemorySegment dstr16, MemorySegment utf8_str) { + var mh$ = BorrowedFields_from_bar_and_strings.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("BorrowedFields_from_bar_and_strings", allocator, bar, dstr16, utf8_str); + } + return (MemorySegment)mh$.invokeExact(allocator, bar, dstr16, utf8_str); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class BorrowedFieldsWithBounds_from_foo_and_strings { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + BorrowedFieldsWithBounds.layout(), + somelib_h.C_POINTER, + DiplomatString16View.layout(), + DiplomatStringView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("BorrowedFieldsWithBounds_from_foo_and_strings"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * BorrowedFieldsWithBounds BorrowedFieldsWithBounds_from_foo_and_strings(const Foo *foo, DiplomatString16View dstr16_x, DiplomatStringView utf8_str_z) + * } + */ + public static FunctionDescriptor BorrowedFieldsWithBounds_from_foo_and_strings$descriptor() { + return BorrowedFieldsWithBounds_from_foo_and_strings.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * BorrowedFieldsWithBounds BorrowedFieldsWithBounds_from_foo_and_strings(const Foo *foo, DiplomatString16View dstr16_x, DiplomatStringView utf8_str_z) + * } + */ + public static MethodHandle BorrowedFieldsWithBounds_from_foo_and_strings$handle() { + return BorrowedFieldsWithBounds_from_foo_and_strings.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * BorrowedFieldsWithBounds BorrowedFieldsWithBounds_from_foo_and_strings(const Foo *foo, DiplomatString16View dstr16_x, DiplomatStringView utf8_str_z) + * } + */ + public static MemorySegment BorrowedFieldsWithBounds_from_foo_and_strings$address() { + return BorrowedFieldsWithBounds_from_foo_and_strings.ADDR; + } + + /** + * {@snippet lang=c : + * BorrowedFieldsWithBounds BorrowedFieldsWithBounds_from_foo_and_strings(const Foo *foo, DiplomatString16View dstr16_x, DiplomatStringView utf8_str_z) + * } + */ + public static MemorySegment BorrowedFieldsWithBounds_from_foo_and_strings(SegmentAllocator allocator, MemorySegment foo, MemorySegment dstr16_x, MemorySegment utf8_str_z) { + var mh$ = BorrowedFieldsWithBounds_from_foo_and_strings.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("BorrowedFieldsWithBounds_from_foo_and_strings", allocator, foo, dstr16_x, utf8_str_z); + } + return (MemorySegment)mh$.invokeExact(allocator, foo, dstr16_x, utf8_str_z); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class NestedBorrowedFields_from_bar_and_foo_and_strings { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + NestedBorrowedFields.layout(), + somelib_h.C_POINTER, + somelib_h.C_POINTER, + DiplomatString16View.layout(), + DiplomatString16View.layout(), + DiplomatStringView.layout(), + DiplomatStringView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("NestedBorrowedFields_from_bar_and_foo_and_strings"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * NestedBorrowedFields NestedBorrowedFields_from_bar_and_foo_and_strings(const Bar *bar, const Foo *foo, DiplomatString16View dstr16_x, DiplomatString16View dstr16_z, DiplomatStringView utf8_str_y, DiplomatStringView utf8_str_z) + * } + */ + public static FunctionDescriptor NestedBorrowedFields_from_bar_and_foo_and_strings$descriptor() { + return NestedBorrowedFields_from_bar_and_foo_and_strings.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * NestedBorrowedFields NestedBorrowedFields_from_bar_and_foo_and_strings(const Bar *bar, const Foo *foo, DiplomatString16View dstr16_x, DiplomatString16View dstr16_z, DiplomatStringView utf8_str_y, DiplomatStringView utf8_str_z) + * } + */ + public static MethodHandle NestedBorrowedFields_from_bar_and_foo_and_strings$handle() { + return NestedBorrowedFields_from_bar_and_foo_and_strings.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * NestedBorrowedFields NestedBorrowedFields_from_bar_and_foo_and_strings(const Bar *bar, const Foo *foo, DiplomatString16View dstr16_x, DiplomatString16View dstr16_z, DiplomatStringView utf8_str_y, DiplomatStringView utf8_str_z) + * } + */ + public static MemorySegment NestedBorrowedFields_from_bar_and_foo_and_strings$address() { + return NestedBorrowedFields_from_bar_and_foo_and_strings.ADDR; + } + + /** + * {@snippet lang=c : + * NestedBorrowedFields NestedBorrowedFields_from_bar_and_foo_and_strings(const Bar *bar, const Foo *foo, DiplomatString16View dstr16_x, DiplomatString16View dstr16_z, DiplomatStringView utf8_str_y, DiplomatStringView utf8_str_z) + * } + */ + public static MemorySegment NestedBorrowedFields_from_bar_and_foo_and_strings(SegmentAllocator allocator, MemorySegment bar, MemorySegment foo, MemorySegment dstr16_x, MemorySegment dstr16_z, MemorySegment utf8_str_y, MemorySegment utf8_str_z) { + var mh$ = NestedBorrowedFields_from_bar_and_foo_and_strings.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("NestedBorrowedFields_from_bar_and_foo_and_strings", allocator, bar, foo, dstr16_x, dstr16_z, utf8_str_y, utf8_str_z); + } + return (MemorySegment)mh$.invokeExact(allocator, bar, foo, dstr16_x, dstr16_z, utf8_str_y, utf8_str_z); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class CyclicStructA_get_b { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CyclicStructB.layout() ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("CyclicStructA_get_b"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * CyclicStructB CyclicStructA_get_b() + * } + */ + public static FunctionDescriptor CyclicStructA_get_b$descriptor() { + return CyclicStructA_get_b.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * CyclicStructB CyclicStructA_get_b() + * } + */ + public static MethodHandle CyclicStructA_get_b$handle() { + return CyclicStructA_get_b.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * CyclicStructB CyclicStructA_get_b() + * } + */ + public static MemorySegment CyclicStructA_get_b$address() { + return CyclicStructA_get_b.ADDR; + } + + /** + * {@snippet lang=c : + * CyclicStructB CyclicStructA_get_b() + * } + */ + public static MemorySegment CyclicStructA_get_b(SegmentAllocator allocator) { + var mh$ = CyclicStructA_get_b.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("CyclicStructA_get_b", allocator); + } + return (MemorySegment)mh$.invokeExact(allocator); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class CyclicStructB_get_a { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + CyclicStructA.layout() ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("CyclicStructB_get_a"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * CyclicStructA CyclicStructB_get_a() + * } + */ + public static FunctionDescriptor CyclicStructB_get_a$descriptor() { + return CyclicStructB_get_a.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * CyclicStructA CyclicStructB_get_a() + * } + */ + public static MethodHandle CyclicStructB_get_a$handle() { + return CyclicStructB_get_a.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * CyclicStructA CyclicStructB_get_a() + * } + */ + public static MemorySegment CyclicStructB_get_a$address() { + return CyclicStructB_get_a.ADDR; + } + + /** + * {@snippet lang=c : + * CyclicStructA CyclicStructB_get_a() + * } + */ + public static MemorySegment CyclicStructB_get_a(SegmentAllocator allocator) { + var mh$ = CyclicStructB_get_a.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("CyclicStructB_get_a", allocator); + } + return (MemorySegment)mh$.invokeExact(allocator); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + private static final int MyEnum_A = (int)-2L; + /** + * {@snippet lang=c : + * enum MyEnum.MyEnum_A = -2 + * } + */ + public static int MyEnum_A() { + return MyEnum_A; + } + private static final int MyEnum_B = (int)-1L; + /** + * {@snippet lang=c : + * enum MyEnum.MyEnum_B = -1 + * } + */ + public static int MyEnum_B() { + return MyEnum_B; + } + private static final int MyEnum_C = (int)0L; + /** + * {@snippet lang=c : + * enum MyEnum.MyEnum_C = 0 + * } + */ + public static int MyEnum_C() { + return MyEnum_C; + } + private static final int MyEnum_D = (int)1L; + /** + * {@snippet lang=c : + * enum MyEnum.MyEnum_D = 1 + * } + */ + public static int MyEnum_D() { + return MyEnum_D; + } + private static final int MyEnum_E = (int)2L; + /** + * {@snippet lang=c : + * enum MyEnum.MyEnum_E = 2 + * } + */ + public static int MyEnum_E() { + return MyEnum_E; + } + private static final int MyEnum_F = (int)3L; + /** + * {@snippet lang=c : + * enum MyEnum.MyEnum_F = 3 + * } + */ + public static int MyEnum_F() { + return MyEnum_F; + } + + private static class MyStruct_new { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + MyStruct.layout() ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("MyStruct_new"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * MyStruct MyStruct_new() + * } + */ + public static FunctionDescriptor MyStruct_new$descriptor() { + return MyStruct_new.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * MyStruct MyStruct_new() + * } + */ + public static MethodHandle MyStruct_new$handle() { + return MyStruct_new.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * MyStruct MyStruct_new() + * } + */ + public static MemorySegment MyStruct_new$address() { + return MyStruct_new.ADDR; + } + + /** + * {@snippet lang=c : + * MyStruct MyStruct_new() + * } + */ + public static MemorySegment MyStruct_new(SegmentAllocator allocator) { + var mh$ = MyStruct_new.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("MyStruct_new", allocator); + } + return (MemorySegment)mh$.invokeExact(allocator); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class MyStruct_into_a { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_CHAR, + MyStruct.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("MyStruct_into_a"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * uint8_t MyStruct_into_a(MyStruct self) + * } + */ + public static FunctionDescriptor MyStruct_into_a$descriptor() { + return MyStruct_into_a.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * uint8_t MyStruct_into_a(MyStruct self) + * } + */ + public static MethodHandle MyStruct_into_a$handle() { + return MyStruct_into_a.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * uint8_t MyStruct_into_a(MyStruct self) + * } + */ + public static MemorySegment MyStruct_into_a$address() { + return MyStruct_into_a.ADDR; + } + + /** + * {@snippet lang=c : + * uint8_t MyStruct_into_a(MyStruct self) + * } + */ + public static byte MyStruct_into_a(MemorySegment self) { + var mh$ = MyStruct_into_a.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("MyStruct_into_a", self); + } + return (byte)mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Bar_foo { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Bar_foo"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * const Foo *Bar_foo(const Bar *self) + * } + */ + public static FunctionDescriptor Bar_foo$descriptor() { + return Bar_foo.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * const Foo *Bar_foo(const Bar *self) + * } + */ + public static MethodHandle Bar_foo$handle() { + return Bar_foo.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * const Foo *Bar_foo(const Bar *self) + * } + */ + public static MemorySegment Bar_foo$address() { + return Bar_foo.ADDR; + } + + /** + * {@snippet lang=c : + * const Foo *Bar_foo(const Bar *self) + * } + */ + public static MemorySegment Bar_foo(MemorySegment self) { + var mh$ = Bar_foo.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Bar_foo", self); + } + return (MemorySegment)mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Bar_destroy { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Bar_destroy"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void Bar_destroy(Bar *self) + * } + */ + public static FunctionDescriptor Bar_destroy$descriptor() { + return Bar_destroy.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void Bar_destroy(Bar *self) + * } + */ + public static MethodHandle Bar_destroy$handle() { + return Bar_destroy.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void Bar_destroy(Bar *self) + * } + */ + public static MemorySegment Bar_destroy$address() { + return Bar_destroy.ADDR; + } + + /** + * {@snippet lang=c : + * void Bar_destroy(Bar *self) + * } + */ + public static void Bar_destroy(MemorySegment self) { + var mh$ = Bar_destroy.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Bar_destroy", self); + } + mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Foo_new { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatStringView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Foo_new"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Foo *Foo_new(DiplomatStringView x) + * } + */ + public static FunctionDescriptor Foo_new$descriptor() { + return Foo_new.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Foo *Foo_new(DiplomatStringView x) + * } + */ + public static MethodHandle Foo_new$handle() { + return Foo_new.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Foo *Foo_new(DiplomatStringView x) + * } + */ + public static MemorySegment Foo_new$address() { + return Foo_new.ADDR; + } + + /** + * {@snippet lang=c : + * Foo *Foo_new(DiplomatStringView x) + * } + */ + public static MemorySegment Foo_new(MemorySegment x) { + var mh$ = Foo_new.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Foo_new", x); + } + return (MemorySegment)mh$.invokeExact(x); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Foo_get_bar { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Foo_get_bar"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Bar *Foo_get_bar(const Foo *self) + * } + */ + public static FunctionDescriptor Foo_get_bar$descriptor() { + return Foo_get_bar.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Bar *Foo_get_bar(const Foo *self) + * } + */ + public static MethodHandle Foo_get_bar$handle() { + return Foo_get_bar.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Bar *Foo_get_bar(const Foo *self) + * } + */ + public static MemorySegment Foo_get_bar$address() { + return Foo_get_bar.ADDR; + } + + /** + * {@snippet lang=c : + * Bar *Foo_get_bar(const Foo *self) + * } + */ + public static MemorySegment Foo_get_bar(MemorySegment self) { + var mh$ = Foo_get_bar.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Foo_get_bar", self); + } + return (MemorySegment)mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Foo_as_returning { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + BorrowedFieldsReturning.layout(), + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Foo_as_returning"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * BorrowedFieldsReturning Foo_as_returning(const Foo *self) + * } + */ + public static FunctionDescriptor Foo_as_returning$descriptor() { + return Foo_as_returning.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * BorrowedFieldsReturning Foo_as_returning(const Foo *self) + * } + */ + public static MethodHandle Foo_as_returning$handle() { + return Foo_as_returning.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * BorrowedFieldsReturning Foo_as_returning(const Foo *self) + * } + */ + public static MemorySegment Foo_as_returning$address() { + return Foo_as_returning.ADDR; + } + + /** + * {@snippet lang=c : + * BorrowedFieldsReturning Foo_as_returning(const Foo *self) + * } + */ + public static MemorySegment Foo_as_returning(SegmentAllocator allocator, MemorySegment self) { + var mh$ = Foo_as_returning.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Foo_as_returning", allocator, self); + } + return (MemorySegment)mh$.invokeExact(allocator, self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Foo_extract_from_fields { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + BorrowedFields.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Foo_extract_from_fields"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Foo *Foo_extract_from_fields(BorrowedFields fields) + * } + */ + public static FunctionDescriptor Foo_extract_from_fields$descriptor() { + return Foo_extract_from_fields.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Foo *Foo_extract_from_fields(BorrowedFields fields) + * } + */ + public static MethodHandle Foo_extract_from_fields$handle() { + return Foo_extract_from_fields.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Foo *Foo_extract_from_fields(BorrowedFields fields) + * } + */ + public static MemorySegment Foo_extract_from_fields$address() { + return Foo_extract_from_fields.ADDR; + } + + /** + * {@snippet lang=c : + * Foo *Foo_extract_from_fields(BorrowedFields fields) + * } + */ + public static MemorySegment Foo_extract_from_fields(MemorySegment fields) { + var mh$ = Foo_extract_from_fields.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Foo_extract_from_fields", fields); + } + return (MemorySegment)mh$.invokeExact(fields); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Foo_extract_from_bounds { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + BorrowedFieldsWithBounds.layout(), + DiplomatStringView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Foo_extract_from_bounds"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Foo *Foo_extract_from_bounds(BorrowedFieldsWithBounds bounds, DiplomatStringView another_string) + * } + */ + public static FunctionDescriptor Foo_extract_from_bounds$descriptor() { + return Foo_extract_from_bounds.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Foo *Foo_extract_from_bounds(BorrowedFieldsWithBounds bounds, DiplomatStringView another_string) + * } + */ + public static MethodHandle Foo_extract_from_bounds$handle() { + return Foo_extract_from_bounds.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Foo *Foo_extract_from_bounds(BorrowedFieldsWithBounds bounds, DiplomatStringView another_string) + * } + */ + public static MemorySegment Foo_extract_from_bounds$address() { + return Foo_extract_from_bounds.ADDR; + } + + /** + * {@snippet lang=c : + * Foo *Foo_extract_from_bounds(BorrowedFieldsWithBounds bounds, DiplomatStringView another_string) + * } + */ + public static MemorySegment Foo_extract_from_bounds(MemorySegment bounds, MemorySegment another_string) { + var mh$ = Foo_extract_from_bounds.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Foo_extract_from_bounds", bounds, another_string); + } + return (MemorySegment)mh$.invokeExact(bounds, another_string); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Foo_destroy { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Foo_destroy"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void Foo_destroy(Foo *self) + * } + */ + public static FunctionDescriptor Foo_destroy$descriptor() { + return Foo_destroy.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void Foo_destroy(Foo *self) + * } + */ + public static MethodHandle Foo_destroy$handle() { + return Foo_destroy.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void Foo_destroy(Foo *self) + * } + */ + public static MemorySegment Foo_destroy$address() { + return Foo_destroy.ADDR; + } + + /** + * {@snippet lang=c : + * void Foo_destroy(Foo *self) + * } + */ + public static void Foo_destroy(MemorySegment self) { + var mh$ = Foo_destroy.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Foo_destroy", self); + } + mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class One_transitivity { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("One_transitivity"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * One *One_transitivity(const One *hold, const One *nohold) + * } + */ + public static FunctionDescriptor One_transitivity$descriptor() { + return One_transitivity.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * One *One_transitivity(const One *hold, const One *nohold) + * } + */ + public static MethodHandle One_transitivity$handle() { + return One_transitivity.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * One *One_transitivity(const One *hold, const One *nohold) + * } + */ + public static MemorySegment One_transitivity$address() { + return One_transitivity.ADDR; + } + + /** + * {@snippet lang=c : + * One *One_transitivity(const One *hold, const One *nohold) + * } + */ + public static MemorySegment One_transitivity(MemorySegment hold, MemorySegment nohold) { + var mh$ = One_transitivity.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("One_transitivity", hold, nohold); + } + return (MemorySegment)mh$.invokeExact(hold, nohold); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class One_cycle { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("One_cycle"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * One *One_cycle(const Two *hold, const One *nohold) + * } + */ + public static FunctionDescriptor One_cycle$descriptor() { + return One_cycle.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * One *One_cycle(const Two *hold, const One *nohold) + * } + */ + public static MethodHandle One_cycle$handle() { + return One_cycle.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * One *One_cycle(const Two *hold, const One *nohold) + * } + */ + public static MemorySegment One_cycle$address() { + return One_cycle.ADDR; + } + + /** + * {@snippet lang=c : + * One *One_cycle(const Two *hold, const One *nohold) + * } + */ + public static MemorySegment One_cycle(MemorySegment hold, MemorySegment nohold) { + var mh$ = One_cycle.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("One_cycle", hold, nohold); + } + return (MemorySegment)mh$.invokeExact(hold, nohold); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class One_many_dependents { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("One_many_dependents"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * One *One_many_dependents(const One *a, const One *b, const Two *c, const Two *d, const Two *nohold) + * } + */ + public static FunctionDescriptor One_many_dependents$descriptor() { + return One_many_dependents.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * One *One_many_dependents(const One *a, const One *b, const Two *c, const Two *d, const Two *nohold) + * } + */ + public static MethodHandle One_many_dependents$handle() { + return One_many_dependents.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * One *One_many_dependents(const One *a, const One *b, const Two *c, const Two *d, const Two *nohold) + * } + */ + public static MemorySegment One_many_dependents$address() { + return One_many_dependents.ADDR; + } + + /** + * {@snippet lang=c : + * One *One_many_dependents(const One *a, const One *b, const Two *c, const Two *d, const Two *nohold) + * } + */ + public static MemorySegment One_many_dependents(MemorySegment a, MemorySegment b, MemorySegment c, MemorySegment d, MemorySegment nohold) { + var mh$ = One_many_dependents.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("One_many_dependents", a, b, c, d, nohold); + } + return (MemorySegment)mh$.invokeExact(a, b, c, d, nohold); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class One_return_outlives_param { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("One_return_outlives_param"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * One *One_return_outlives_param(const Two *hold, const One *nohold) + * } + */ + public static FunctionDescriptor One_return_outlives_param$descriptor() { + return One_return_outlives_param.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * One *One_return_outlives_param(const Two *hold, const One *nohold) + * } + */ + public static MethodHandle One_return_outlives_param$handle() { + return One_return_outlives_param.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * One *One_return_outlives_param(const Two *hold, const One *nohold) + * } + */ + public static MemorySegment One_return_outlives_param$address() { + return One_return_outlives_param.ADDR; + } + + /** + * {@snippet lang=c : + * One *One_return_outlives_param(const Two *hold, const One *nohold) + * } + */ + public static MemorySegment One_return_outlives_param(MemorySegment hold, MemorySegment nohold) { + var mh$ = One_return_outlives_param.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("One_return_outlives_param", hold, nohold); + } + return (MemorySegment)mh$.invokeExact(hold, nohold); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class One_diamond_top { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("One_diamond_top"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * One *One_diamond_top(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static FunctionDescriptor One_diamond_top$descriptor() { + return One_diamond_top.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * One *One_diamond_top(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static MethodHandle One_diamond_top$handle() { + return One_diamond_top.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * One *One_diamond_top(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static MemorySegment One_diamond_top$address() { + return One_diamond_top.ADDR; + } + + /** + * {@snippet lang=c : + * One *One_diamond_top(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static MemorySegment One_diamond_top(MemorySegment top, MemorySegment left, MemorySegment right, MemorySegment bottom) { + var mh$ = One_diamond_top.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("One_diamond_top", top, left, right, bottom); + } + return (MemorySegment)mh$.invokeExact(top, left, right, bottom); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class One_diamond_left { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("One_diamond_left"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * One *One_diamond_left(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static FunctionDescriptor One_diamond_left$descriptor() { + return One_diamond_left.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * One *One_diamond_left(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static MethodHandle One_diamond_left$handle() { + return One_diamond_left.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * One *One_diamond_left(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static MemorySegment One_diamond_left$address() { + return One_diamond_left.ADDR; + } + + /** + * {@snippet lang=c : + * One *One_diamond_left(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static MemorySegment One_diamond_left(MemorySegment top, MemorySegment left, MemorySegment right, MemorySegment bottom) { + var mh$ = One_diamond_left.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("One_diamond_left", top, left, right, bottom); + } + return (MemorySegment)mh$.invokeExact(top, left, right, bottom); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class One_diamond_right { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("One_diamond_right"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * One *One_diamond_right(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static FunctionDescriptor One_diamond_right$descriptor() { + return One_diamond_right.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * One *One_diamond_right(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static MethodHandle One_diamond_right$handle() { + return One_diamond_right.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * One *One_diamond_right(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static MemorySegment One_diamond_right$address() { + return One_diamond_right.ADDR; + } + + /** + * {@snippet lang=c : + * One *One_diamond_right(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static MemorySegment One_diamond_right(MemorySegment top, MemorySegment left, MemorySegment right, MemorySegment bottom) { + var mh$ = One_diamond_right.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("One_diamond_right", top, left, right, bottom); + } + return (MemorySegment)mh$.invokeExact(top, left, right, bottom); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class One_diamond_bottom { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("One_diamond_bottom"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * One *One_diamond_bottom(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static FunctionDescriptor One_diamond_bottom$descriptor() { + return One_diamond_bottom.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * One *One_diamond_bottom(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static MethodHandle One_diamond_bottom$handle() { + return One_diamond_bottom.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * One *One_diamond_bottom(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static MemorySegment One_diamond_bottom$address() { + return One_diamond_bottom.ADDR; + } + + /** + * {@snippet lang=c : + * One *One_diamond_bottom(const One *top, const One *left, const One *right, const One *bottom) + * } + */ + public static MemorySegment One_diamond_bottom(MemorySegment top, MemorySegment left, MemorySegment right, MemorySegment bottom) { + var mh$ = One_diamond_bottom.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("One_diamond_bottom", top, left, right, bottom); + } + return (MemorySegment)mh$.invokeExact(top, left, right, bottom); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class One_diamond_and_nested_types { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("One_diamond_and_nested_types"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * One *One_diamond_and_nested_types(const One *a, const One *b, const One *c, const One *d, const One *nohold) + * } + */ + public static FunctionDescriptor One_diamond_and_nested_types$descriptor() { + return One_diamond_and_nested_types.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * One *One_diamond_and_nested_types(const One *a, const One *b, const One *c, const One *d, const One *nohold) + * } + */ + public static MethodHandle One_diamond_and_nested_types$handle() { + return One_diamond_and_nested_types.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * One *One_diamond_and_nested_types(const One *a, const One *b, const One *c, const One *d, const One *nohold) + * } + */ + public static MemorySegment One_diamond_and_nested_types$address() { + return One_diamond_and_nested_types.ADDR; + } + + /** + * {@snippet lang=c : + * One *One_diamond_and_nested_types(const One *a, const One *b, const One *c, const One *d, const One *nohold) + * } + */ + public static MemorySegment One_diamond_and_nested_types(MemorySegment a, MemorySegment b, MemorySegment c, MemorySegment d, MemorySegment nohold) { + var mh$ = One_diamond_and_nested_types.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("One_diamond_and_nested_types", a, b, c, d, nohold); + } + return (MemorySegment)mh$.invokeExact(a, b, c, d, nohold); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class One_implicit_bounds { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("One_implicit_bounds"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * One *One_implicit_bounds(const One *explicit_hold, const One *implicit_hold, const One *nohold) + * } + */ + public static FunctionDescriptor One_implicit_bounds$descriptor() { + return One_implicit_bounds.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * One *One_implicit_bounds(const One *explicit_hold, const One *implicit_hold, const One *nohold) + * } + */ + public static MethodHandle One_implicit_bounds$handle() { + return One_implicit_bounds.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * One *One_implicit_bounds(const One *explicit_hold, const One *implicit_hold, const One *nohold) + * } + */ + public static MemorySegment One_implicit_bounds$address() { + return One_implicit_bounds.ADDR; + } + + /** + * {@snippet lang=c : + * One *One_implicit_bounds(const One *explicit_hold, const One *implicit_hold, const One *nohold) + * } + */ + public static MemorySegment One_implicit_bounds(MemorySegment explicit_hold, MemorySegment implicit_hold, MemorySegment nohold) { + var mh$ = One_implicit_bounds.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("One_implicit_bounds", explicit_hold, implicit_hold, nohold); + } + return (MemorySegment)mh$.invokeExact(explicit_hold, implicit_hold, nohold); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class One_implicit_bounds_deep { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("One_implicit_bounds_deep"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * One *One_implicit_bounds_deep(const One *explicit_, const One *implicit_1, const One *implicit_2, const One *nohold) + * } + */ + public static FunctionDescriptor One_implicit_bounds_deep$descriptor() { + return One_implicit_bounds_deep.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * One *One_implicit_bounds_deep(const One *explicit_, const One *implicit_1, const One *implicit_2, const One *nohold) + * } + */ + public static MethodHandle One_implicit_bounds_deep$handle() { + return One_implicit_bounds_deep.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * One *One_implicit_bounds_deep(const One *explicit_, const One *implicit_1, const One *implicit_2, const One *nohold) + * } + */ + public static MemorySegment One_implicit_bounds_deep$address() { + return One_implicit_bounds_deep.ADDR; + } + + /** + * {@snippet lang=c : + * One *One_implicit_bounds_deep(const One *explicit_, const One *implicit_1, const One *implicit_2, const One *nohold) + * } + */ + public static MemorySegment One_implicit_bounds_deep(MemorySegment explicit_, MemorySegment implicit_1, MemorySegment implicit_2, MemorySegment nohold) { + var mh$ = One_implicit_bounds_deep.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("One_implicit_bounds_deep", explicit_, implicit_1, implicit_2, nohold); + } + return (MemorySegment)mh$.invokeExact(explicit_, implicit_1, implicit_2, nohold); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class One_destroy { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("One_destroy"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void One_destroy(One *self) + * } + */ + public static FunctionDescriptor One_destroy$descriptor() { + return One_destroy.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void One_destroy(One *self) + * } + */ + public static MethodHandle One_destroy$handle() { + return One_destroy.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void One_destroy(One *self) + * } + */ + public static MemorySegment One_destroy$address() { + return One_destroy.ADDR; + } + + /** + * {@snippet lang=c : + * void One_destroy(One *self) + * } + */ + public static void One_destroy(MemorySegment self) { + var mh$ = One_destroy.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("One_destroy", self); + } + mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Two_destroy { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Two_destroy"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void Two_destroy(Two *self) + * } + */ + public static FunctionDescriptor Two_destroy$descriptor() { + return Two_destroy.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void Two_destroy(Two *self) + * } + */ + public static MethodHandle Two_destroy$handle() { + return Two_destroy.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void Two_destroy(Two *self) + * } + */ + public static MemorySegment Two_destroy$address() { + return Two_destroy.ADDR; + } + + /** + * {@snippet lang=c : + * void Two_destroy(Two *self) + * } + */ + public static void Two_destroy(MemorySegment self) { + var mh$ = Two_destroy.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Two_destroy", self); + } + mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class RefList_node { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("RefList_node"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * RefList *RefList_node(const RefListParameter *data) + * } + */ + public static FunctionDescriptor RefList_node$descriptor() { + return RefList_node.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * RefList *RefList_node(const RefListParameter *data) + * } + */ + public static MethodHandle RefList_node$handle() { + return RefList_node.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * RefList *RefList_node(const RefListParameter *data) + * } + */ + public static MemorySegment RefList_node$address() { + return RefList_node.ADDR; + } + + /** + * {@snippet lang=c : + * RefList *RefList_node(const RefListParameter *data) + * } + */ + public static MemorySegment RefList_node(MemorySegment data) { + var mh$ = RefList_node.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("RefList_node", data); + } + return (MemorySegment)mh$.invokeExact(data); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class RefList_destroy { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("RefList_destroy"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void RefList_destroy(RefList *self) + * } + */ + public static FunctionDescriptor RefList_destroy$descriptor() { + return RefList_destroy.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void RefList_destroy(RefList *self) + * } + */ + public static MethodHandle RefList_destroy$handle() { + return RefList_destroy.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void RefList_destroy(RefList *self) + * } + */ + public static MemorySegment RefList_destroy$address() { + return RefList_destroy.ADDR; + } + + /** + * {@snippet lang=c : + * void RefList_destroy(RefList *self) + * } + */ + public static void RefList_destroy(MemorySegment self) { + var mh$ = RefList_destroy.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("RefList_destroy", self); + } + mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class RefListParameter_destroy { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("RefListParameter_destroy"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void RefListParameter_destroy(RefListParameter *self) + * } + */ + public static FunctionDescriptor RefListParameter_destroy$descriptor() { + return RefListParameter_destroy.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void RefListParameter_destroy(RefListParameter *self) + * } + */ + public static MethodHandle RefListParameter_destroy$handle() { + return RefListParameter_destroy.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void RefListParameter_destroy(RefListParameter *self) + * } + */ + public static MemorySegment RefListParameter_destroy$address() { + return RefListParameter_destroy.ADDR; + } + + /** + * {@snippet lang=c : + * void RefListParameter_destroy(RefListParameter *self) + * } + */ + public static void RefListParameter_destroy(MemorySegment self) { + var mh$ = RefListParameter_destroy.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("RefListParameter_destroy", self); + } + mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_new { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatF64View.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_new"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new(DiplomatF64View v) + * } + */ + public static FunctionDescriptor Float64Vec_new$descriptor() { + return Float64Vec_new.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new(DiplomatF64View v) + * } + */ + public static MethodHandle Float64Vec_new$handle() { + return Float64Vec_new.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new(DiplomatF64View v) + * } + */ + public static MemorySegment Float64Vec_new$address() { + return Float64Vec_new.ADDR; + } + + /** + * {@snippet lang=c : + * Float64Vec *Float64Vec_new(DiplomatF64View v) + * } + */ + public static MemorySegment Float64Vec_new(MemorySegment v) { + var mh$ = Float64Vec_new.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_new", v); + } + return (MemorySegment)mh$.invokeExact(v); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_new_bool { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatBoolView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_new_bool"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_bool(DiplomatBoolView v) + * } + */ + public static FunctionDescriptor Float64Vec_new_bool$descriptor() { + return Float64Vec_new_bool.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_bool(DiplomatBoolView v) + * } + */ + public static MethodHandle Float64Vec_new_bool$handle() { + return Float64Vec_new_bool.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_bool(DiplomatBoolView v) + * } + */ + public static MemorySegment Float64Vec_new_bool$address() { + return Float64Vec_new_bool.ADDR; + } + + /** + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_bool(DiplomatBoolView v) + * } + */ + public static MemorySegment Float64Vec_new_bool(MemorySegment v) { + var mh$ = Float64Vec_new_bool.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_new_bool", v); + } + return (MemorySegment)mh$.invokeExact(v); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_new_i16 { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatI16View.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_new_i16"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_i16(DiplomatI16View v) + * } + */ + public static FunctionDescriptor Float64Vec_new_i16$descriptor() { + return Float64Vec_new_i16.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_i16(DiplomatI16View v) + * } + */ + public static MethodHandle Float64Vec_new_i16$handle() { + return Float64Vec_new_i16.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_i16(DiplomatI16View v) + * } + */ + public static MemorySegment Float64Vec_new_i16$address() { + return Float64Vec_new_i16.ADDR; + } + + /** + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_i16(DiplomatI16View v) + * } + */ + public static MemorySegment Float64Vec_new_i16(MemorySegment v) { + var mh$ = Float64Vec_new_i16.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_new_i16", v); + } + return (MemorySegment)mh$.invokeExact(v); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_new_u16 { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatU16View.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_new_u16"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_u16(DiplomatU16View v) + * } + */ + public static FunctionDescriptor Float64Vec_new_u16$descriptor() { + return Float64Vec_new_u16.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_u16(DiplomatU16View v) + * } + */ + public static MethodHandle Float64Vec_new_u16$handle() { + return Float64Vec_new_u16.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_u16(DiplomatU16View v) + * } + */ + public static MemorySegment Float64Vec_new_u16$address() { + return Float64Vec_new_u16.ADDR; + } + + /** + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_u16(DiplomatU16View v) + * } + */ + public static MemorySegment Float64Vec_new_u16(MemorySegment v) { + var mh$ = Float64Vec_new_u16.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_new_u16", v); + } + return (MemorySegment)mh$.invokeExact(v); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_new_isize { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatIsizeView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_new_isize"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_isize(DiplomatIsizeView v) + * } + */ + public static FunctionDescriptor Float64Vec_new_isize$descriptor() { + return Float64Vec_new_isize.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_isize(DiplomatIsizeView v) + * } + */ + public static MethodHandle Float64Vec_new_isize$handle() { + return Float64Vec_new_isize.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_isize(DiplomatIsizeView v) + * } + */ + public static MemorySegment Float64Vec_new_isize$address() { + return Float64Vec_new_isize.ADDR; + } + + /** + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_isize(DiplomatIsizeView v) + * } + */ + public static MemorySegment Float64Vec_new_isize(MemorySegment v) { + var mh$ = Float64Vec_new_isize.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_new_isize", v); + } + return (MemorySegment)mh$.invokeExact(v); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_new_usize { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatUsizeView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_new_usize"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_usize(DiplomatUsizeView v) + * } + */ + public static FunctionDescriptor Float64Vec_new_usize$descriptor() { + return Float64Vec_new_usize.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_usize(DiplomatUsizeView v) + * } + */ + public static MethodHandle Float64Vec_new_usize$handle() { + return Float64Vec_new_usize.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_usize(DiplomatUsizeView v) + * } + */ + public static MemorySegment Float64Vec_new_usize$address() { + return Float64Vec_new_usize.ADDR; + } + + /** + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_usize(DiplomatUsizeView v) + * } + */ + public static MemorySegment Float64Vec_new_usize(MemorySegment v) { + var mh$ = Float64Vec_new_usize.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_new_usize", v); + } + return (MemorySegment)mh$.invokeExact(v); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_new_f64_be_bytes { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatU8View.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_new_f64_be_bytes"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_f64_be_bytes(DiplomatU8View v) + * } + */ + public static FunctionDescriptor Float64Vec_new_f64_be_bytes$descriptor() { + return Float64Vec_new_f64_be_bytes.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_f64_be_bytes(DiplomatU8View v) + * } + */ + public static MethodHandle Float64Vec_new_f64_be_bytes$handle() { + return Float64Vec_new_f64_be_bytes.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_f64_be_bytes(DiplomatU8View v) + * } + */ + public static MemorySegment Float64Vec_new_f64_be_bytes$address() { + return Float64Vec_new_f64_be_bytes.ADDR; + } + + /** + * {@snippet lang=c : + * Float64Vec *Float64Vec_new_f64_be_bytes(DiplomatU8View v) + * } + */ + public static MemorySegment Float64Vec_new_f64_be_bytes(MemorySegment v) { + var mh$ = Float64Vec_new_f64_be_bytes.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_new_f64_be_bytes", v); + } + return (MemorySegment)mh$.invokeExact(v); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_as_slice { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + DiplomatF64View.layout(), + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_as_slice"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * DiplomatF64View Float64Vec_as_slice(const Float64Vec *self) + * } + */ + public static FunctionDescriptor Float64Vec_as_slice$descriptor() { + return Float64Vec_as_slice.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * DiplomatF64View Float64Vec_as_slice(const Float64Vec *self) + * } + */ + public static MethodHandle Float64Vec_as_slice$handle() { + return Float64Vec_as_slice.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * DiplomatF64View Float64Vec_as_slice(const Float64Vec *self) + * } + */ + public static MemorySegment Float64Vec_as_slice$address() { + return Float64Vec_as_slice.ADDR; + } + + /** + * {@snippet lang=c : + * DiplomatF64View Float64Vec_as_slice(const Float64Vec *self) + * } + */ + public static MemorySegment Float64Vec_as_slice(SegmentAllocator allocator, MemorySegment self) { + var mh$ = Float64Vec_as_slice.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_as_slice", allocator, self); + } + return (MemorySegment)mh$.invokeExact(allocator, self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_fill_slice { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER, + DiplomatF64ViewMut.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_fill_slice"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void Float64Vec_fill_slice(const Float64Vec *self, DiplomatF64ViewMut v) + * } + */ + public static FunctionDescriptor Float64Vec_fill_slice$descriptor() { + return Float64Vec_fill_slice.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void Float64Vec_fill_slice(const Float64Vec *self, DiplomatF64ViewMut v) + * } + */ + public static MethodHandle Float64Vec_fill_slice$handle() { + return Float64Vec_fill_slice.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void Float64Vec_fill_slice(const Float64Vec *self, DiplomatF64ViewMut v) + * } + */ + public static MemorySegment Float64Vec_fill_slice$address() { + return Float64Vec_fill_slice.ADDR; + } + + /** + * {@snippet lang=c : + * void Float64Vec_fill_slice(const Float64Vec *self, DiplomatF64ViewMut v) + * } + */ + public static void Float64Vec_fill_slice(MemorySegment self, MemorySegment v) { + var mh$ = Float64Vec_fill_slice.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_fill_slice", self, v); + } + mh$.invokeExact(self, v); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_set_value { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER, + DiplomatF64View.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_set_value"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void Float64Vec_set_value(Float64Vec *self, DiplomatF64View new_slice) + * } + */ + public static FunctionDescriptor Float64Vec_set_value$descriptor() { + return Float64Vec_set_value.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void Float64Vec_set_value(Float64Vec *self, DiplomatF64View new_slice) + * } + */ + public static MethodHandle Float64Vec_set_value$handle() { + return Float64Vec_set_value.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void Float64Vec_set_value(Float64Vec *self, DiplomatF64View new_slice) + * } + */ + public static MemorySegment Float64Vec_set_value$address() { + return Float64Vec_set_value.ADDR; + } + + /** + * {@snippet lang=c : + * void Float64Vec_set_value(Float64Vec *self, DiplomatF64View new_slice) + * } + */ + public static void Float64Vec_set_value(MemorySegment self, MemorySegment new_slice) { + var mh$ = Float64Vec_set_value.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_set_value", self, new_slice); + } + mh$.invokeExact(self, new_slice); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_to_string { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_to_string"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void Float64Vec_to_string(const Float64Vec *self, DiplomatWrite *write) + * } + */ + public static FunctionDescriptor Float64Vec_to_string$descriptor() { + return Float64Vec_to_string.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void Float64Vec_to_string(const Float64Vec *self, DiplomatWrite *write) + * } + */ + public static MethodHandle Float64Vec_to_string$handle() { + return Float64Vec_to_string.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void Float64Vec_to_string(const Float64Vec *self, DiplomatWrite *write) + * } + */ + public static MemorySegment Float64Vec_to_string$address() { + return Float64Vec_to_string.ADDR; + } + + /** + * {@snippet lang=c : + * void Float64Vec_to_string(const Float64Vec *self, DiplomatWrite *write) + * } + */ + public static void Float64Vec_to_string(MemorySegment self, MemorySegment write) { + var mh$ = Float64Vec_to_string.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_to_string", self, write); + } + mh$.invokeExact(self, write); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_borrow { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + DiplomatF64View.layout(), + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_borrow"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * DiplomatF64View Float64Vec_borrow(const Float64Vec *self) + * } + */ + public static FunctionDescriptor Float64Vec_borrow$descriptor() { + return Float64Vec_borrow.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * DiplomatF64View Float64Vec_borrow(const Float64Vec *self) + * } + */ + public static MethodHandle Float64Vec_borrow$handle() { + return Float64Vec_borrow.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * DiplomatF64View Float64Vec_borrow(const Float64Vec *self) + * } + */ + public static MemorySegment Float64Vec_borrow$address() { + return Float64Vec_borrow.ADDR; + } + + /** + * {@snippet lang=c : + * DiplomatF64View Float64Vec_borrow(const Float64Vec *self) + * } + */ + public static MemorySegment Float64Vec_borrow(SegmentAllocator allocator, MemorySegment self) { + var mh$ = Float64Vec_borrow.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_borrow", allocator, self); + } + return (MemorySegment)mh$.invokeExact(allocator, self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Float64Vec_destroy { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Float64Vec_destroy"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void Float64Vec_destroy(Float64Vec *self) + * } + */ + public static FunctionDescriptor Float64Vec_destroy$descriptor() { + return Float64Vec_destroy.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void Float64Vec_destroy(Float64Vec *self) + * } + */ + public static MethodHandle Float64Vec_destroy$handle() { + return Float64Vec_destroy.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void Float64Vec_destroy(Float64Vec *self) + * } + */ + public static MemorySegment Float64Vec_destroy$address() { + return Float64Vec_destroy.ADDR; + } + + /** + * {@snippet lang=c : + * void Float64Vec_destroy(Float64Vec *self) + * } + */ + public static void Float64Vec_destroy(MemorySegment self) { + var mh$ = Float64Vec_destroy.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Float64Vec_destroy", self); + } + mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class MyString_new { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatStringView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("MyString_new"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * MyString *MyString_new(DiplomatStringView v) + * } + */ + public static FunctionDescriptor MyString_new$descriptor() { + return MyString_new.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * MyString *MyString_new(DiplomatStringView v) + * } + */ + public static MethodHandle MyString_new$handle() { + return MyString_new.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * MyString *MyString_new(DiplomatStringView v) + * } + */ + public static MemorySegment MyString_new$address() { + return MyString_new.ADDR; + } + + /** + * {@snippet lang=c : + * MyString *MyString_new(DiplomatStringView v) + * } + */ + public static MemorySegment MyString_new(MemorySegment v) { + var mh$ = MyString_new.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("MyString_new", v); + } + return (MemorySegment)mh$.invokeExact(v); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class MyString_new_unsafe { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatStringView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("MyString_new_unsafe"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * MyString *MyString_new_unsafe(DiplomatStringView v) + * } + */ + public static FunctionDescriptor MyString_new_unsafe$descriptor() { + return MyString_new_unsafe.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * MyString *MyString_new_unsafe(DiplomatStringView v) + * } + */ + public static MethodHandle MyString_new_unsafe$handle() { + return MyString_new_unsafe.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * MyString *MyString_new_unsafe(DiplomatStringView v) + * } + */ + public static MemorySegment MyString_new_unsafe$address() { + return MyString_new_unsafe.ADDR; + } + + /** + * {@snippet lang=c : + * MyString *MyString_new_unsafe(DiplomatStringView v) + * } + */ + public static MemorySegment MyString_new_unsafe(MemorySegment v) { + var mh$ = MyString_new_unsafe.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("MyString_new_unsafe", v); + } + return (MemorySegment)mh$.invokeExact(v); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class MyString_new_from_first { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatStringsView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("MyString_new_from_first"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * MyString *MyString_new_from_first(DiplomatStringsView v) + * } + */ + public static FunctionDescriptor MyString_new_from_first$descriptor() { + return MyString_new_from_first.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * MyString *MyString_new_from_first(DiplomatStringsView v) + * } + */ + public static MethodHandle MyString_new_from_first$handle() { + return MyString_new_from_first.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * MyString *MyString_new_from_first(DiplomatStringsView v) + * } + */ + public static MemorySegment MyString_new_from_first$address() { + return MyString_new_from_first.ADDR; + } + + /** + * {@snippet lang=c : + * MyString *MyString_new_from_first(DiplomatStringsView v) + * } + */ + public static MemorySegment MyString_new_from_first(MemorySegment v) { + var mh$ = MyString_new_from_first.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("MyString_new_from_first", v); + } + return (MemorySegment)mh$.invokeExact(v); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class MyString_set_str { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER, + DiplomatStringView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("MyString_set_str"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void MyString_set_str(MyString *self, DiplomatStringView new_str) + * } + */ + public static FunctionDescriptor MyString_set_str$descriptor() { + return MyString_set_str.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void MyString_set_str(MyString *self, DiplomatStringView new_str) + * } + */ + public static MethodHandle MyString_set_str$handle() { + return MyString_set_str.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void MyString_set_str(MyString *self, DiplomatStringView new_str) + * } + */ + public static MemorySegment MyString_set_str$address() { + return MyString_set_str.ADDR; + } + + /** + * {@snippet lang=c : + * void MyString_set_str(MyString *self, DiplomatStringView new_str) + * } + */ + public static void MyString_set_str(MemorySegment self, MemorySegment new_str) { + var mh$ = MyString_set_str.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("MyString_set_str", self, new_str); + } + mh$.invokeExact(self, new_str); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class MyString_get_str { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("MyString_get_str"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void MyString_get_str(const MyString *self, DiplomatWrite *write) + * } + */ + public static FunctionDescriptor MyString_get_str$descriptor() { + return MyString_get_str.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void MyString_get_str(const MyString *self, DiplomatWrite *write) + * } + */ + public static MethodHandle MyString_get_str$handle() { + return MyString_get_str.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void MyString_get_str(const MyString *self, DiplomatWrite *write) + * } + */ + public static MemorySegment MyString_get_str$address() { + return MyString_get_str.ADDR; + } + + /** + * {@snippet lang=c : + * void MyString_get_str(const MyString *self, DiplomatWrite *write) + * } + */ + public static void MyString_get_str(MemorySegment self, MemorySegment write) { + var mh$ = MyString_get_str.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("MyString_get_str", self, write); + } + mh$.invokeExact(self, write); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class MyString_string_transform { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + DiplomatStringView.layout(), + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("MyString_string_transform"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void MyString_string_transform(DiplomatStringView foo, DiplomatWrite *write) + * } + */ + public static FunctionDescriptor MyString_string_transform$descriptor() { + return MyString_string_transform.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void MyString_string_transform(DiplomatStringView foo, DiplomatWrite *write) + * } + */ + public static MethodHandle MyString_string_transform$handle() { + return MyString_string_transform.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void MyString_string_transform(DiplomatStringView foo, DiplomatWrite *write) + * } + */ + public static MemorySegment MyString_string_transform$address() { + return MyString_string_transform.ADDR; + } + + /** + * {@snippet lang=c : + * void MyString_string_transform(DiplomatStringView foo, DiplomatWrite *write) + * } + */ + public static void MyString_string_transform(MemorySegment foo, MemorySegment write) { + var mh$ = MyString_string_transform.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("MyString_string_transform", foo, write); + } + mh$.invokeExact(foo, write); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class MyString_destroy { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("MyString_destroy"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void MyString_destroy(MyString *self) + * } + */ + public static FunctionDescriptor MyString_destroy$descriptor() { + return MyString_destroy.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void MyString_destroy(MyString *self) + * } + */ + public static MethodHandle MyString_destroy$handle() { + return MyString_destroy.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void MyString_destroy(MyString *self) + * } + */ + public static MemorySegment MyString_destroy$address() { + return MyString_destroy.ADDR; + } + + /** + * {@snippet lang=c : + * void MyString_destroy(MyString *self) + * } + */ + public static void MyString_destroy(MemorySegment self) { + var mh$ = MyString_destroy.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("MyString_destroy", self); + } + mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Opaque_new { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Opaque_new"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Opaque *Opaque_new() + * } + */ + public static FunctionDescriptor Opaque_new$descriptor() { + return Opaque_new.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Opaque *Opaque_new() + * } + */ + public static MethodHandle Opaque_new$handle() { + return Opaque_new.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Opaque *Opaque_new() + * } + */ + public static MemorySegment Opaque_new$address() { + return Opaque_new.ADDR; + } + + /** + * {@snippet lang=c : + * Opaque *Opaque_new() + * } + */ + public static MemorySegment Opaque_new() { + var mh$ = Opaque_new.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Opaque_new"); + } + return (MemorySegment)mh$.invokeExact(); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Opaque_from_str { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatStringView.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Opaque_from_str"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Opaque *Opaque_from_str(DiplomatStringView input) + * } + */ + public static FunctionDescriptor Opaque_from_str$descriptor() { + return Opaque_from_str.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Opaque *Opaque_from_str(DiplomatStringView input) + * } + */ + public static MethodHandle Opaque_from_str$handle() { + return Opaque_from_str.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Opaque *Opaque_from_str(DiplomatStringView input) + * } + */ + public static MemorySegment Opaque_from_str$address() { + return Opaque_from_str.ADDR; + } + + /** + * {@snippet lang=c : + * Opaque *Opaque_from_str(DiplomatStringView input) + * } + */ + public static MemorySegment Opaque_from_str(MemorySegment input) { + var mh$ = Opaque_from_str.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Opaque_from_str", input); + } + return (MemorySegment)mh$.invokeExact(input); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Opaque_get_debug_str { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Opaque_get_debug_str"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void Opaque_get_debug_str(const Opaque *self, DiplomatWrite *write) + * } + */ + public static FunctionDescriptor Opaque_get_debug_str$descriptor() { + return Opaque_get_debug_str.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void Opaque_get_debug_str(const Opaque *self, DiplomatWrite *write) + * } + */ + public static MethodHandle Opaque_get_debug_str$handle() { + return Opaque_get_debug_str.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void Opaque_get_debug_str(const Opaque *self, DiplomatWrite *write) + * } + */ + public static MemorySegment Opaque_get_debug_str$address() { + return Opaque_get_debug_str.ADDR; + } + + /** + * {@snippet lang=c : + * void Opaque_get_debug_str(const Opaque *self, DiplomatWrite *write) + * } + */ + public static void Opaque_get_debug_str(MemorySegment self, MemorySegment write) { + var mh$ = Opaque_get_debug_str.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Opaque_get_debug_str", self, write); + } + mh$.invokeExact(self, write); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Opaque_assert_struct { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER, + MyStruct.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Opaque_assert_struct"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void Opaque_assert_struct(const Opaque *self, MyStruct s) + * } + */ + public static FunctionDescriptor Opaque_assert_struct$descriptor() { + return Opaque_assert_struct.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void Opaque_assert_struct(const Opaque *self, MyStruct s) + * } + */ + public static MethodHandle Opaque_assert_struct$handle() { + return Opaque_assert_struct.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void Opaque_assert_struct(const Opaque *self, MyStruct s) + * } + */ + public static MemorySegment Opaque_assert_struct$address() { + return Opaque_assert_struct.ADDR; + } + + /** + * {@snippet lang=c : + * void Opaque_assert_struct(const Opaque *self, MyStruct s) + * } + */ + public static void Opaque_assert_struct(MemorySegment self, MemorySegment s) { + var mh$ = Opaque_assert_struct.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Opaque_assert_struct", self, s); + } + mh$.invokeExact(self, s); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Opaque_returns_usize { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_LONG ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Opaque_returns_usize"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * size_t Opaque_returns_usize() + * } + */ + public static FunctionDescriptor Opaque_returns_usize$descriptor() { + return Opaque_returns_usize.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * size_t Opaque_returns_usize() + * } + */ + public static MethodHandle Opaque_returns_usize$handle() { + return Opaque_returns_usize.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * size_t Opaque_returns_usize() + * } + */ + public static MemorySegment Opaque_returns_usize$address() { + return Opaque_returns_usize.ADDR; + } + + /** + * {@snippet lang=c : + * size_t Opaque_returns_usize() + * } + */ + public static long Opaque_returns_usize() { + var mh$ = Opaque_returns_usize.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Opaque_returns_usize"); + } + return (long)mh$.invokeExact(); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Opaque_internal_len { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_LONG, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Opaque_internal_len"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * size_t Opaque_internal_len(const Opaque *self) + * } + */ + public static FunctionDescriptor Opaque_internal_len$descriptor() { + return Opaque_internal_len.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * size_t Opaque_internal_len(const Opaque *self) + * } + */ + public static MethodHandle Opaque_internal_len$handle() { + return Opaque_internal_len.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * size_t Opaque_internal_len(const Opaque *self) + * } + */ + public static MemorySegment Opaque_internal_len$address() { + return Opaque_internal_len.ADDR; + } + + /** + * {@snippet lang=c : + * size_t Opaque_internal_len(const Opaque *self) + * } + */ + public static long Opaque_internal_len(MemorySegment self) { + var mh$ = Opaque_internal_len.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Opaque_internal_len", self); + } + return (long)mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Opaque_returns_imported { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + ImportedStruct.layout() ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Opaque_returns_imported"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * ImportedStruct Opaque_returns_imported() + * } + */ + public static FunctionDescriptor Opaque_returns_imported$descriptor() { + return Opaque_returns_imported.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * ImportedStruct Opaque_returns_imported() + * } + */ + public static MethodHandle Opaque_returns_imported$handle() { + return Opaque_returns_imported.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * ImportedStruct Opaque_returns_imported() + * } + */ + public static MemorySegment Opaque_returns_imported$address() { + return Opaque_returns_imported.ADDR; + } + + /** + * {@snippet lang=c : + * ImportedStruct Opaque_returns_imported() + * } + */ + public static MemorySegment Opaque_returns_imported(SegmentAllocator allocator) { + var mh$ = Opaque_returns_imported.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Opaque_returns_imported", allocator); + } + return (MemorySegment)mh$.invokeExact(allocator); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Opaque_cmp { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_CHAR ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Opaque_cmp"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int8_t Opaque_cmp() + * } + */ + public static FunctionDescriptor Opaque_cmp$descriptor() { + return Opaque_cmp.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int8_t Opaque_cmp() + * } + */ + public static MethodHandle Opaque_cmp$handle() { + return Opaque_cmp.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int8_t Opaque_cmp() + * } + */ + public static MemorySegment Opaque_cmp$address() { + return Opaque_cmp.ADDR; + } + + /** + * {@snippet lang=c : + * int8_t Opaque_cmp() + * } + */ + public static byte Opaque_cmp() { + var mh$ = Opaque_cmp.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Opaque_cmp"); + } + return (byte)mh$.invokeExact(); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Opaque_destroy { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Opaque_destroy"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void Opaque_destroy(Opaque *self) + * } + */ + public static FunctionDescriptor Opaque_destroy$descriptor() { + return Opaque_destroy.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void Opaque_destroy(Opaque *self) + * } + */ + public static MethodHandle Opaque_destroy$handle() { + return Opaque_destroy.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void Opaque_destroy(Opaque *self) + * } + */ + public static MemorySegment Opaque_destroy$address() { + return Opaque_destroy.ADDR; + } + + /** + * {@snippet lang=c : + * void Opaque_destroy(Opaque *self) + * } + */ + public static void Opaque_destroy(MemorySegment self) { + var mh$ = Opaque_destroy.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Opaque_destroy", self); + } + mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class OpaqueMutexedString_from_usize { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_LONG + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("OpaqueMutexedString_from_usize"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * OpaqueMutexedString *OpaqueMutexedString_from_usize(size_t number) + * } + */ + public static FunctionDescriptor OpaqueMutexedString_from_usize$descriptor() { + return OpaqueMutexedString_from_usize.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * OpaqueMutexedString *OpaqueMutexedString_from_usize(size_t number) + * } + */ + public static MethodHandle OpaqueMutexedString_from_usize$handle() { + return OpaqueMutexedString_from_usize.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * OpaqueMutexedString *OpaqueMutexedString_from_usize(size_t number) + * } + */ + public static MemorySegment OpaqueMutexedString_from_usize$address() { + return OpaqueMutexedString_from_usize.ADDR; + } + + /** + * {@snippet lang=c : + * OpaqueMutexedString *OpaqueMutexedString_from_usize(size_t number) + * } + */ + public static MemorySegment OpaqueMutexedString_from_usize(long number) { + var mh$ = OpaqueMutexedString_from_usize.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("OpaqueMutexedString_from_usize", number); + } + return (MemorySegment)mh$.invokeExact(number); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class OpaqueMutexedString_change { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER, + somelib_h.C_LONG + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("OpaqueMutexedString_change"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void OpaqueMutexedString_change(const OpaqueMutexedString *self, size_t number) + * } + */ + public static FunctionDescriptor OpaqueMutexedString_change$descriptor() { + return OpaqueMutexedString_change.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void OpaqueMutexedString_change(const OpaqueMutexedString *self, size_t number) + * } + */ + public static MethodHandle OpaqueMutexedString_change$handle() { + return OpaqueMutexedString_change.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void OpaqueMutexedString_change(const OpaqueMutexedString *self, size_t number) + * } + */ + public static MemorySegment OpaqueMutexedString_change$address() { + return OpaqueMutexedString_change.ADDR; + } + + /** + * {@snippet lang=c : + * void OpaqueMutexedString_change(const OpaqueMutexedString *self, size_t number) + * } + */ + public static void OpaqueMutexedString_change(MemorySegment self, long number) { + var mh$ = OpaqueMutexedString_change.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("OpaqueMutexedString_change", self, number); + } + mh$.invokeExact(self, number); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class OpaqueMutexedString_borrow { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("OpaqueMutexedString_borrow"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * const OpaqueMutexedString *OpaqueMutexedString_borrow(const OpaqueMutexedString *self) + * } + */ + public static FunctionDescriptor OpaqueMutexedString_borrow$descriptor() { + return OpaqueMutexedString_borrow.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * const OpaqueMutexedString *OpaqueMutexedString_borrow(const OpaqueMutexedString *self) + * } + */ + public static MethodHandle OpaqueMutexedString_borrow$handle() { + return OpaqueMutexedString_borrow.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * const OpaqueMutexedString *OpaqueMutexedString_borrow(const OpaqueMutexedString *self) + * } + */ + public static MemorySegment OpaqueMutexedString_borrow$address() { + return OpaqueMutexedString_borrow.ADDR; + } + + /** + * {@snippet lang=c : + * const OpaqueMutexedString *OpaqueMutexedString_borrow(const OpaqueMutexedString *self) + * } + */ + public static MemorySegment OpaqueMutexedString_borrow(MemorySegment self) { + var mh$ = OpaqueMutexedString_borrow.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("OpaqueMutexedString_borrow", self); + } + return (MemorySegment)mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class OpaqueMutexedString_borrow_other { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("OpaqueMutexedString_borrow_other"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * const OpaqueMutexedString *OpaqueMutexedString_borrow_other(const OpaqueMutexedString *other) + * } + */ + public static FunctionDescriptor OpaqueMutexedString_borrow_other$descriptor() { + return OpaqueMutexedString_borrow_other.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * const OpaqueMutexedString *OpaqueMutexedString_borrow_other(const OpaqueMutexedString *other) + * } + */ + public static MethodHandle OpaqueMutexedString_borrow_other$handle() { + return OpaqueMutexedString_borrow_other.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * const OpaqueMutexedString *OpaqueMutexedString_borrow_other(const OpaqueMutexedString *other) + * } + */ + public static MemorySegment OpaqueMutexedString_borrow_other$address() { + return OpaqueMutexedString_borrow_other.ADDR; + } + + /** + * {@snippet lang=c : + * const OpaqueMutexedString *OpaqueMutexedString_borrow_other(const OpaqueMutexedString *other) + * } + */ + public static MemorySegment OpaqueMutexedString_borrow_other(MemorySegment other) { + var mh$ = OpaqueMutexedString_borrow_other.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("OpaqueMutexedString_borrow_other", other); + } + return (MemorySegment)mh$.invokeExact(other); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class OpaqueMutexedString_borrow_self_or_other { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("OpaqueMutexedString_borrow_self_or_other"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * const OpaqueMutexedString *OpaqueMutexedString_borrow_self_or_other(const OpaqueMutexedString *self, const OpaqueMutexedString *other) + * } + */ + public static FunctionDescriptor OpaqueMutexedString_borrow_self_or_other$descriptor() { + return OpaqueMutexedString_borrow_self_or_other.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * const OpaqueMutexedString *OpaqueMutexedString_borrow_self_or_other(const OpaqueMutexedString *self, const OpaqueMutexedString *other) + * } + */ + public static MethodHandle OpaqueMutexedString_borrow_self_or_other$handle() { + return OpaqueMutexedString_borrow_self_or_other.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * const OpaqueMutexedString *OpaqueMutexedString_borrow_self_or_other(const OpaqueMutexedString *self, const OpaqueMutexedString *other) + * } + */ + public static MemorySegment OpaqueMutexedString_borrow_self_or_other$address() { + return OpaqueMutexedString_borrow_self_or_other.ADDR; + } + + /** + * {@snippet lang=c : + * const OpaqueMutexedString *OpaqueMutexedString_borrow_self_or_other(const OpaqueMutexedString *self, const OpaqueMutexedString *other) + * } + */ + public static MemorySegment OpaqueMutexedString_borrow_self_or_other(MemorySegment self, MemorySegment other) { + var mh$ = OpaqueMutexedString_borrow_self_or_other.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("OpaqueMutexedString_borrow_self_or_other", self, other); + } + return (MemorySegment)mh$.invokeExact(self, other); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class OpaqueMutexedString_get_len_and_add { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_LONG, + somelib_h.C_POINTER, + somelib_h.C_LONG + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("OpaqueMutexedString_get_len_and_add"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * size_t OpaqueMutexedString_get_len_and_add(const OpaqueMutexedString *self, size_t other) + * } + */ + public static FunctionDescriptor OpaqueMutexedString_get_len_and_add$descriptor() { + return OpaqueMutexedString_get_len_and_add.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * size_t OpaqueMutexedString_get_len_and_add(const OpaqueMutexedString *self, size_t other) + * } + */ + public static MethodHandle OpaqueMutexedString_get_len_and_add$handle() { + return OpaqueMutexedString_get_len_and_add.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * size_t OpaqueMutexedString_get_len_and_add(const OpaqueMutexedString *self, size_t other) + * } + */ + public static MemorySegment OpaqueMutexedString_get_len_and_add$address() { + return OpaqueMutexedString_get_len_and_add.ADDR; + } + + /** + * {@snippet lang=c : + * size_t OpaqueMutexedString_get_len_and_add(const OpaqueMutexedString *self, size_t other) + * } + */ + public static long OpaqueMutexedString_get_len_and_add(MemorySegment self, long other) { + var mh$ = OpaqueMutexedString_get_len_and_add.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("OpaqueMutexedString_get_len_and_add", self, other); + } + return (long)mh$.invokeExact(self, other); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class OpaqueMutexedString_dummy_str { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + DiplomatStringView.layout(), + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("OpaqueMutexedString_dummy_str"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * DiplomatStringView OpaqueMutexedString_dummy_str(const OpaqueMutexedString *self) + * } + */ + public static FunctionDescriptor OpaqueMutexedString_dummy_str$descriptor() { + return OpaqueMutexedString_dummy_str.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * DiplomatStringView OpaqueMutexedString_dummy_str(const OpaqueMutexedString *self) + * } + */ + public static MethodHandle OpaqueMutexedString_dummy_str$handle() { + return OpaqueMutexedString_dummy_str.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * DiplomatStringView OpaqueMutexedString_dummy_str(const OpaqueMutexedString *self) + * } + */ + public static MemorySegment OpaqueMutexedString_dummy_str$address() { + return OpaqueMutexedString_dummy_str.ADDR; + } + + /** + * {@snippet lang=c : + * DiplomatStringView OpaqueMutexedString_dummy_str(const OpaqueMutexedString *self) + * } + */ + public static MemorySegment OpaqueMutexedString_dummy_str(SegmentAllocator allocator, MemorySegment self) { + var mh$ = OpaqueMutexedString_dummy_str.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("OpaqueMutexedString_dummy_str", allocator, self); + } + return (MemorySegment)mh$.invokeExact(allocator, self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class OpaqueMutexedString_wrapper { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("OpaqueMutexedString_wrapper"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Utf16Wrap *OpaqueMutexedString_wrapper(const OpaqueMutexedString *self) + * } + */ + public static FunctionDescriptor OpaqueMutexedString_wrapper$descriptor() { + return OpaqueMutexedString_wrapper.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Utf16Wrap *OpaqueMutexedString_wrapper(const OpaqueMutexedString *self) + * } + */ + public static MethodHandle OpaqueMutexedString_wrapper$handle() { + return OpaqueMutexedString_wrapper.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Utf16Wrap *OpaqueMutexedString_wrapper(const OpaqueMutexedString *self) + * } + */ + public static MemorySegment OpaqueMutexedString_wrapper$address() { + return OpaqueMutexedString_wrapper.ADDR; + } + + /** + * {@snippet lang=c : + * Utf16Wrap *OpaqueMutexedString_wrapper(const OpaqueMutexedString *self) + * } + */ + public static MemorySegment OpaqueMutexedString_wrapper(MemorySegment self) { + var mh$ = OpaqueMutexedString_wrapper.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("OpaqueMutexedString_wrapper", self); + } + return (MemorySegment)mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class OpaqueMutexedString_destroy { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("OpaqueMutexedString_destroy"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void OpaqueMutexedString_destroy(OpaqueMutexedString *self) + * } + */ + public static FunctionDescriptor OpaqueMutexedString_destroy$descriptor() { + return OpaqueMutexedString_destroy.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void OpaqueMutexedString_destroy(OpaqueMutexedString *self) + * } + */ + public static MethodHandle OpaqueMutexedString_destroy$handle() { + return OpaqueMutexedString_destroy.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void OpaqueMutexedString_destroy(OpaqueMutexedString *self) + * } + */ + public static MemorySegment OpaqueMutexedString_destroy$address() { + return OpaqueMutexedString_destroy.ADDR; + } + + /** + * {@snippet lang=c : + * void OpaqueMutexedString_destroy(OpaqueMutexedString *self) + * } + */ + public static void OpaqueMutexedString_destroy(MemorySegment self) { + var mh$ = OpaqueMutexedString_destroy.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("OpaqueMutexedString_destroy", self); + } + mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Utf16Wrap_from_utf16 { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_POINTER, + DiplomatString16View.layout() + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Utf16Wrap_from_utf16"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * Utf16Wrap *Utf16Wrap_from_utf16(DiplomatString16View input) + * } + */ + public static FunctionDescriptor Utf16Wrap_from_utf16$descriptor() { + return Utf16Wrap_from_utf16.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * Utf16Wrap *Utf16Wrap_from_utf16(DiplomatString16View input) + * } + */ + public static MethodHandle Utf16Wrap_from_utf16$handle() { + return Utf16Wrap_from_utf16.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * Utf16Wrap *Utf16Wrap_from_utf16(DiplomatString16View input) + * } + */ + public static MemorySegment Utf16Wrap_from_utf16$address() { + return Utf16Wrap_from_utf16.ADDR; + } + + /** + * {@snippet lang=c : + * Utf16Wrap *Utf16Wrap_from_utf16(DiplomatString16View input) + * } + */ + public static MemorySegment Utf16Wrap_from_utf16(MemorySegment input) { + var mh$ = Utf16Wrap_from_utf16.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Utf16Wrap_from_utf16", input); + } + return (MemorySegment)mh$.invokeExact(input); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Utf16Wrap_get_debug_str { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER, + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Utf16Wrap_get_debug_str"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void Utf16Wrap_get_debug_str(const Utf16Wrap *self, DiplomatWrite *write) + * } + */ + public static FunctionDescriptor Utf16Wrap_get_debug_str$descriptor() { + return Utf16Wrap_get_debug_str.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void Utf16Wrap_get_debug_str(const Utf16Wrap *self, DiplomatWrite *write) + * } + */ + public static MethodHandle Utf16Wrap_get_debug_str$handle() { + return Utf16Wrap_get_debug_str.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void Utf16Wrap_get_debug_str(const Utf16Wrap *self, DiplomatWrite *write) + * } + */ + public static MemorySegment Utf16Wrap_get_debug_str$address() { + return Utf16Wrap_get_debug_str.ADDR; + } + + /** + * {@snippet lang=c : + * void Utf16Wrap_get_debug_str(const Utf16Wrap *self, DiplomatWrite *write) + * } + */ + public static void Utf16Wrap_get_debug_str(MemorySegment self, MemorySegment write) { + var mh$ = Utf16Wrap_get_debug_str.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Utf16Wrap_get_debug_str", self, write); + } + mh$.invokeExact(self, write); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Utf16Wrap_borrow_cont { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + DiplomatString16View.layout(), + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Utf16Wrap_borrow_cont"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * DiplomatString16View Utf16Wrap_borrow_cont(const Utf16Wrap *self) + * } + */ + public static FunctionDescriptor Utf16Wrap_borrow_cont$descriptor() { + return Utf16Wrap_borrow_cont.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * DiplomatString16View Utf16Wrap_borrow_cont(const Utf16Wrap *self) + * } + */ + public static MethodHandle Utf16Wrap_borrow_cont$handle() { + return Utf16Wrap_borrow_cont.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * DiplomatString16View Utf16Wrap_borrow_cont(const Utf16Wrap *self) + * } + */ + public static MemorySegment Utf16Wrap_borrow_cont$address() { + return Utf16Wrap_borrow_cont.ADDR; + } + + /** + * {@snippet lang=c : + * DiplomatString16View Utf16Wrap_borrow_cont(const Utf16Wrap *self) + * } + */ + public static MemorySegment Utf16Wrap_borrow_cont(SegmentAllocator allocator, MemorySegment self) { + var mh$ = Utf16Wrap_borrow_cont.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Utf16Wrap_borrow_cont", allocator, self); + } + return (MemorySegment)mh$.invokeExact(allocator, self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class Utf16Wrap_destroy { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + somelib_h.C_POINTER + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("Utf16Wrap_destroy"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * void Utf16Wrap_destroy(Utf16Wrap *self) + * } + */ + public static FunctionDescriptor Utf16Wrap_destroy$descriptor() { + return Utf16Wrap_destroy.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * void Utf16Wrap_destroy(Utf16Wrap *self) + * } + */ + public static MethodHandle Utf16Wrap_destroy$handle() { + return Utf16Wrap_destroy.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * void Utf16Wrap_destroy(Utf16Wrap *self) + * } + */ + public static MemorySegment Utf16Wrap_destroy$address() { + return Utf16Wrap_destroy.ADDR; + } + + /** + * {@snippet lang=c : + * void Utf16Wrap_destroy(Utf16Wrap *self) + * } + */ + public static void Utf16Wrap_destroy(MemorySegment self) { + var mh$ = Utf16Wrap_destroy.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("Utf16Wrap_destroy", self); + } + mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + private static final int ContiguousEnum_C = (int)0L; + /** + * {@snippet lang=c : + * enum ContiguousEnum.ContiguousEnum_C = 0 + * } + */ + public static int ContiguousEnum_C() { + return ContiguousEnum_C; + } + private static final int ContiguousEnum_D = (int)1L; + /** + * {@snippet lang=c : + * enum ContiguousEnum.ContiguousEnum_D = 1 + * } + */ + public static int ContiguousEnum_D() { + return ContiguousEnum_D; + } + private static final int ContiguousEnum_E = (int)2L; + /** + * {@snippet lang=c : + * enum ContiguousEnum.ContiguousEnum_E = 2 + * } + */ + public static int ContiguousEnum_E() { + return ContiguousEnum_E; + } + private static final int ContiguousEnum_F = (int)3L; + /** + * {@snippet lang=c : + * enum ContiguousEnum.ContiguousEnum_F = 3 + * } + */ + public static int ContiguousEnum_F() { + return ContiguousEnum_F; + } + + private static class MyEnum_into_value { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_CHAR, + somelib_h.C_INT + ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("MyEnum_into_value"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * int8_t MyEnum_into_value(MyEnum self) + * } + */ + public static FunctionDescriptor MyEnum_into_value$descriptor() { + return MyEnum_into_value.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * int8_t MyEnum_into_value(MyEnum self) + * } + */ + public static MethodHandle MyEnum_into_value$handle() { + return MyEnum_into_value.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * int8_t MyEnum_into_value(MyEnum self) + * } + */ + public static MemorySegment MyEnum_into_value$address() { + return MyEnum_into_value.ADDR; + } + + /** + * {@snippet lang=c : + * int8_t MyEnum_into_value(MyEnum self) + * } + */ + public static byte MyEnum_into_value(int self) { + var mh$ = MyEnum_into_value.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("MyEnum_into_value", self); + } + return (byte)mh$.invokeExact(self); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class MyEnum_get_a { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + somelib_h.C_INT ); + + public static final MemorySegment ADDR = somelib_h.findOrThrow("MyEnum_get_a"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * MyEnum MyEnum_get_a() + * } + */ + public static FunctionDescriptor MyEnum_get_a$descriptor() { + return MyEnum_get_a.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * MyEnum MyEnum_get_a() + * } + */ + public static MethodHandle MyEnum_get_a$handle() { + return MyEnum_get_a.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * MyEnum MyEnum_get_a() + * } + */ + public static MemorySegment MyEnum_get_a$address() { + return MyEnum_get_a.ADDR; + } + + /** + * {@snippet lang=c : + * MyEnum MyEnum_get_a() + * } + */ + public static int MyEnum_get_a() { + var mh$ = MyEnum_get_a.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("MyEnum_get_a"); + } + return (int)mh$.invokeExact(); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + /** + * {@snippet lang=c : + * #define __DARWIN_SUF_EXTSN "$DARWIN_EXTSN" + * } + */ + public static MemorySegment __DARWIN_SUF_EXTSN() { + class Holder { + static final MemorySegment __DARWIN_SUF_EXTSN + = somelib_h.LIBRARY_ARENA.allocateFrom("$DARWIN_EXTSN"); + } + return Holder.__DARWIN_SUF_EXTSN; + } + private static final long __DARWIN_C_ANSI = 4096L; + /** + * {@snippet lang=c : + * #define __DARWIN_C_ANSI 4096 + * } + */ + public static long __DARWIN_C_ANSI() { + return __DARWIN_C_ANSI; + } + private static final long __DARWIN_C_FULL = 900000L; + /** + * {@snippet lang=c : + * #define __DARWIN_C_FULL 900000 + * } + */ + public static long __DARWIN_C_FULL() { + return __DARWIN_C_FULL; + } + private static final long __DARWIN_C_LEVEL = 900000L; + /** + * {@snippet lang=c : + * #define __DARWIN_C_LEVEL 900000 + * } + */ + public static long __DARWIN_C_LEVEL() { + return __DARWIN_C_LEVEL; + } + /** + * {@snippet lang=c : + * #define __ASSERT_FILE_NAME "jextract$7555175648453266457.h" + * } + */ + public static MemorySegment __ASSERT_FILE_NAME() { + class Holder { + static final MemorySegment __ASSERT_FILE_NAME + = somelib_h.LIBRARY_ARENA.allocateFrom("jextract$7555175648453266457.h"); + } + return Holder.__ASSERT_FILE_NAME; + } + private static final MemorySegment NULL = MemorySegment.ofAddress(0L); + /** + * {@snippet lang=c : + * #define NULL (void*) 0 + * } + */ + public static MemorySegment NULL() { + return NULL; + } + private static final MemorySegment __DARWIN_NULL = MemorySegment.ofAddress(0L); + /** + * {@snippet lang=c : + * #define __DARWIN_NULL (void*) 0 + * } + */ + public static MemorySegment __DARWIN_NULL() { + return __DARWIN_NULL; + } + private static final long USER_ADDR_NULL = 0L; + /** + * {@snippet lang=c : + * #define USER_ADDR_NULL 0 + * } + */ + public static long USER_ADDR_NULL() { + return USER_ADDR_NULL; + } + private static final long INT64_MAX = 9223372036854775807L; + /** + * {@snippet lang=c : + * #define INT64_MAX 9223372036854775807 + * } + */ + public static long INT64_MAX() { + return INT64_MAX; + } + private static final int INT8_MIN = (int)-128L; + /** + * {@snippet lang=c : + * #define INT8_MIN -128 + * } + */ + public static int INT8_MIN() { + return INT8_MIN; + } + private static final int INT16_MIN = (int)-32768L; + /** + * {@snippet lang=c : + * #define INT16_MIN -32768 + * } + */ + public static int INT16_MIN() { + return INT16_MIN; + } + private static final int INT32_MIN = (int)-2147483648L; + /** + * {@snippet lang=c : + * #define INT32_MIN -2147483648 + * } + */ + public static int INT32_MIN() { + return INT32_MIN; + } + private static final long INT64_MIN = -9223372036854775808L; + /** + * {@snippet lang=c : + * #define INT64_MIN -9223372036854775808 + * } + */ + public static long INT64_MIN() { + return INT64_MIN; + } + private static final int UINT32_MAX = (int)4294967295L; + /** + * {@snippet lang=c : + * #define UINT32_MAX 4294967295 + * } + */ + public static int UINT32_MAX() { + return UINT32_MAX; + } + private static final long UINT64_MAX = -1L; + /** + * {@snippet lang=c : + * #define UINT64_MAX -1 + * } + */ + public static long UINT64_MAX() { + return UINT64_MAX; + } + private static final int INT_LEAST8_MIN = (int)-128L; + /** + * {@snippet lang=c : + * #define INT_LEAST8_MIN -128 + * } + */ + public static int INT_LEAST8_MIN() { + return INT_LEAST8_MIN; + } + private static final int INT_LEAST16_MIN = (int)-32768L; + /** + * {@snippet lang=c : + * #define INT_LEAST16_MIN -32768 + * } + */ + public static int INT_LEAST16_MIN() { + return INT_LEAST16_MIN; + } + private static final int INT_LEAST32_MIN = (int)-2147483648L; + /** + * {@snippet lang=c : + * #define INT_LEAST32_MIN -2147483648 + * } + */ + public static int INT_LEAST32_MIN() { + return INT_LEAST32_MIN; + } + private static final long INT_LEAST64_MIN = -9223372036854775808L; + /** + * {@snippet lang=c : + * #define INT_LEAST64_MIN -9223372036854775808 + * } + */ + public static long INT_LEAST64_MIN() { + return INT_LEAST64_MIN; + } + private static final int INT_LEAST8_MAX = (int)127L; + /** + * {@snippet lang=c : + * #define INT_LEAST8_MAX 127 + * } + */ + public static int INT_LEAST8_MAX() { + return INT_LEAST8_MAX; + } + private static final int INT_LEAST16_MAX = (int)32767L; + /** + * {@snippet lang=c : + * #define INT_LEAST16_MAX 32767 + * } + */ + public static int INT_LEAST16_MAX() { + return INT_LEAST16_MAX; + } + private static final int INT_LEAST32_MAX = (int)2147483647L; + /** + * {@snippet lang=c : + * #define INT_LEAST32_MAX 2147483647 + * } + */ + public static int INT_LEAST32_MAX() { + return INT_LEAST32_MAX; + } + private static final long INT_LEAST64_MAX = 9223372036854775807L; + /** + * {@snippet lang=c : + * #define INT_LEAST64_MAX 9223372036854775807 + * } + */ + public static long INT_LEAST64_MAX() { + return INT_LEAST64_MAX; + } + private static final int UINT_LEAST8_MAX = (int)255L; + /** + * {@snippet lang=c : + * #define UINT_LEAST8_MAX 255 + * } + */ + public static int UINT_LEAST8_MAX() { + return UINT_LEAST8_MAX; + } + private static final int UINT_LEAST16_MAX = (int)65535L; + /** + * {@snippet lang=c : + * #define UINT_LEAST16_MAX 65535 + * } + */ + public static int UINT_LEAST16_MAX() { + return UINT_LEAST16_MAX; + } + private static final int UINT_LEAST32_MAX = (int)4294967295L; + /** + * {@snippet lang=c : + * #define UINT_LEAST32_MAX 4294967295 + * } + */ + public static int UINT_LEAST32_MAX() { + return UINT_LEAST32_MAX; + } + private static final long UINT_LEAST64_MAX = -1L; + /** + * {@snippet lang=c : + * #define UINT_LEAST64_MAX -1 + * } + */ + public static long UINT_LEAST64_MAX() { + return UINT_LEAST64_MAX; + } + private static final int INT_FAST8_MIN = (int)-128L; + /** + * {@snippet lang=c : + * #define INT_FAST8_MIN -128 + * } + */ + public static int INT_FAST8_MIN() { + return INT_FAST8_MIN; + } + private static final int INT_FAST16_MIN = (int)-32768L; + /** + * {@snippet lang=c : + * #define INT_FAST16_MIN -32768 + * } + */ + public static int INT_FAST16_MIN() { + return INT_FAST16_MIN; + } + private static final int INT_FAST32_MIN = (int)-2147483648L; + /** + * {@snippet lang=c : + * #define INT_FAST32_MIN -2147483648 + * } + */ + public static int INT_FAST32_MIN() { + return INT_FAST32_MIN; + } + private static final long INT_FAST64_MIN = -9223372036854775808L; + /** + * {@snippet lang=c : + * #define INT_FAST64_MIN -9223372036854775808 + * } + */ + public static long INT_FAST64_MIN() { + return INT_FAST64_MIN; + } + private static final int INT_FAST8_MAX = (int)127L; + /** + * {@snippet lang=c : + * #define INT_FAST8_MAX 127 + * } + */ + public static int INT_FAST8_MAX() { + return INT_FAST8_MAX; + } + private static final int INT_FAST16_MAX = (int)32767L; + /** + * {@snippet lang=c : + * #define INT_FAST16_MAX 32767 + * } + */ + public static int INT_FAST16_MAX() { + return INT_FAST16_MAX; + } + private static final int INT_FAST32_MAX = (int)2147483647L; + /** + * {@snippet lang=c : + * #define INT_FAST32_MAX 2147483647 + * } + */ + public static int INT_FAST32_MAX() { + return INT_FAST32_MAX; + } + private static final long INT_FAST64_MAX = 9223372036854775807L; + /** + * {@snippet lang=c : + * #define INT_FAST64_MAX 9223372036854775807 + * } + */ + public static long INT_FAST64_MAX() { + return INT_FAST64_MAX; + } + private static final int UINT_FAST8_MAX = (int)255L; + /** + * {@snippet lang=c : + * #define UINT_FAST8_MAX 255 + * } + */ + public static int UINT_FAST8_MAX() { + return UINT_FAST8_MAX; + } + private static final int UINT_FAST16_MAX = (int)65535L; + /** + * {@snippet lang=c : + * #define UINT_FAST16_MAX 65535 + * } + */ + public static int UINT_FAST16_MAX() { + return UINT_FAST16_MAX; + } + private static final int UINT_FAST32_MAX = (int)4294967295L; + /** + * {@snippet lang=c : + * #define UINT_FAST32_MAX 4294967295 + * } + */ + public static int UINT_FAST32_MAX() { + return UINT_FAST32_MAX; + } + private static final long UINT_FAST64_MAX = -1L; + /** + * {@snippet lang=c : + * #define UINT_FAST64_MAX -1 + * } + */ + public static long UINT_FAST64_MAX() { + return UINT_FAST64_MAX; + } + private static final long INTPTR_MAX = 9223372036854775807L; + /** + * {@snippet lang=c : + * #define INTPTR_MAX 9223372036854775807 + * } + */ + public static long INTPTR_MAX() { + return INTPTR_MAX; + } + private static final long INTPTR_MIN = -9223372036854775808L; + /** + * {@snippet lang=c : + * #define INTPTR_MIN -9223372036854775808 + * } + */ + public static long INTPTR_MIN() { + return INTPTR_MIN; + } + private static final long UINTPTR_MAX = -1L; + /** + * {@snippet lang=c : + * #define UINTPTR_MAX -1 + * } + */ + public static long UINTPTR_MAX() { + return UINTPTR_MAX; + } + private static final long INTMAX_MAX = 9223372036854775807L; + /** + * {@snippet lang=c : + * #define INTMAX_MAX 9223372036854775807 + * } + */ + public static long INTMAX_MAX() { + return INTMAX_MAX; + } + private static final long UINTMAX_MAX = -1L; + /** + * {@snippet lang=c : + * #define UINTMAX_MAX -1 + * } + */ + public static long UINTMAX_MAX() { + return UINTMAX_MAX; + } + private static final long INTMAX_MIN = -9223372036854775808L; + /** + * {@snippet lang=c : + * #define INTMAX_MIN -9223372036854775808 + * } + */ + public static long INTMAX_MIN() { + return INTMAX_MIN; + } + private static final long PTRDIFF_MIN = -9223372036854775808L; + /** + * {@snippet lang=c : + * #define PTRDIFF_MIN -9223372036854775808 + * } + */ + public static long PTRDIFF_MIN() { + return PTRDIFF_MIN; + } + private static final long PTRDIFF_MAX = 9223372036854775807L; + /** + * {@snippet lang=c : + * #define PTRDIFF_MAX 9223372036854775807 + * } + */ + public static long PTRDIFF_MAX() { + return PTRDIFF_MAX; + } + private static final long SIZE_MAX = -1L; + /** + * {@snippet lang=c : + * #define SIZE_MAX -1 + * } + */ + public static long SIZE_MAX() { + return SIZE_MAX; + } + private static final long RSIZE_MAX = 9223372036854775807L; + /** + * {@snippet lang=c : + * #define RSIZE_MAX 9223372036854775807 + * } + */ + public static long RSIZE_MAX() { + return RSIZE_MAX; + } + private static final int WCHAR_MAX = (int)2147483647L; + /** + * {@snippet lang=c : + * #define WCHAR_MAX 2147483647 + * } + */ + public static int WCHAR_MAX() { + return WCHAR_MAX; + } + private static final int WCHAR_MIN = (int)-2147483648L; + /** + * {@snippet lang=c : + * #define WCHAR_MIN -2147483648 + * } + */ + public static int WCHAR_MIN() { + return WCHAR_MIN; + } + private static final int WINT_MIN = (int)-2147483648L; + /** + * {@snippet lang=c : + * #define WINT_MIN -2147483648 + * } + */ + public static int WINT_MIN() { + return WINT_MIN; + } + private static final int WINT_MAX = (int)2147483647L; + /** + * {@snippet lang=c : + * #define WINT_MAX 2147483647 + * } + */ + public static int WINT_MAX() { + return WINT_MAX; + } + private static final int SIG_ATOMIC_MIN = (int)-2147483648L; + /** + * {@snippet lang=c : + * #define SIG_ATOMIC_MIN -2147483648 + * } + */ + public static int SIG_ATOMIC_MIN() { + return SIG_ATOMIC_MIN; + } + private static final int SIG_ATOMIC_MAX = (int)2147483647L; + /** + * {@snippet lang=c : + * #define SIG_ATOMIC_MAX 2147483647 + * } + */ + public static int SIG_ATOMIC_MAX() { + return SIG_ATOMIC_MAX; + } + private static final int MAC_OS_X_VERSION_10_0 = (int)1000L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_0 1000 + * } + */ + public static int MAC_OS_X_VERSION_10_0() { + return MAC_OS_X_VERSION_10_0; + } + private static final int MAC_OS_X_VERSION_10_1 = (int)1010L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_1 1010 + * } + */ + public static int MAC_OS_X_VERSION_10_1() { + return MAC_OS_X_VERSION_10_1; + } + private static final int MAC_OS_X_VERSION_10_2 = (int)1020L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_2 1020 + * } + */ + public static int MAC_OS_X_VERSION_10_2() { + return MAC_OS_X_VERSION_10_2; + } + private static final int MAC_OS_X_VERSION_10_3 = (int)1030L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_3 1030 + * } + */ + public static int MAC_OS_X_VERSION_10_3() { + return MAC_OS_X_VERSION_10_3; + } + private static final int MAC_OS_X_VERSION_10_4 = (int)1040L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_4 1040 + * } + */ + public static int MAC_OS_X_VERSION_10_4() { + return MAC_OS_X_VERSION_10_4; + } + private static final int MAC_OS_X_VERSION_10_5 = (int)1050L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_5 1050 + * } + */ + public static int MAC_OS_X_VERSION_10_5() { + return MAC_OS_X_VERSION_10_5; + } + private static final int MAC_OS_X_VERSION_10_6 = (int)1060L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_6 1060 + * } + */ + public static int MAC_OS_X_VERSION_10_6() { + return MAC_OS_X_VERSION_10_6; + } + private static final int MAC_OS_X_VERSION_10_7 = (int)1070L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_7 1070 + * } + */ + public static int MAC_OS_X_VERSION_10_7() { + return MAC_OS_X_VERSION_10_7; + } + private static final int MAC_OS_X_VERSION_10_8 = (int)1080L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_8 1080 + * } + */ + public static int MAC_OS_X_VERSION_10_8() { + return MAC_OS_X_VERSION_10_8; + } + private static final int MAC_OS_X_VERSION_10_9 = (int)1090L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_9 1090 + * } + */ + public static int MAC_OS_X_VERSION_10_9() { + return MAC_OS_X_VERSION_10_9; + } + private static final int MAC_OS_X_VERSION_10_10 = (int)101000L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_10 101000 + * } + */ + public static int MAC_OS_X_VERSION_10_10() { + return MAC_OS_X_VERSION_10_10; + } + private static final int MAC_OS_X_VERSION_10_10_2 = (int)101002L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_10_2 101002 + * } + */ + public static int MAC_OS_X_VERSION_10_10_2() { + return MAC_OS_X_VERSION_10_10_2; + } + private static final int MAC_OS_X_VERSION_10_10_3 = (int)101003L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_10_3 101003 + * } + */ + public static int MAC_OS_X_VERSION_10_10_3() { + return MAC_OS_X_VERSION_10_10_3; + } + private static final int MAC_OS_X_VERSION_10_11 = (int)101100L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_11 101100 + * } + */ + public static int MAC_OS_X_VERSION_10_11() { + return MAC_OS_X_VERSION_10_11; + } + private static final int MAC_OS_X_VERSION_10_11_2 = (int)101102L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_11_2 101102 + * } + */ + public static int MAC_OS_X_VERSION_10_11_2() { + return MAC_OS_X_VERSION_10_11_2; + } + private static final int MAC_OS_X_VERSION_10_11_3 = (int)101103L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_11_3 101103 + * } + */ + public static int MAC_OS_X_VERSION_10_11_3() { + return MAC_OS_X_VERSION_10_11_3; + } + private static final int MAC_OS_X_VERSION_10_11_4 = (int)101104L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_11_4 101104 + * } + */ + public static int MAC_OS_X_VERSION_10_11_4() { + return MAC_OS_X_VERSION_10_11_4; + } + private static final int MAC_OS_X_VERSION_10_12 = (int)101200L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_12 101200 + * } + */ + public static int MAC_OS_X_VERSION_10_12() { + return MAC_OS_X_VERSION_10_12; + } + private static final int MAC_OS_X_VERSION_10_12_1 = (int)101201L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_12_1 101201 + * } + */ + public static int MAC_OS_X_VERSION_10_12_1() { + return MAC_OS_X_VERSION_10_12_1; + } + private static final int MAC_OS_X_VERSION_10_12_2 = (int)101202L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_12_2 101202 + * } + */ + public static int MAC_OS_X_VERSION_10_12_2() { + return MAC_OS_X_VERSION_10_12_2; + } + private static final int MAC_OS_X_VERSION_10_12_4 = (int)101204L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_12_4 101204 + * } + */ + public static int MAC_OS_X_VERSION_10_12_4() { + return MAC_OS_X_VERSION_10_12_4; + } + private static final int MAC_OS_X_VERSION_10_13 = (int)101300L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_13 101300 + * } + */ + public static int MAC_OS_X_VERSION_10_13() { + return MAC_OS_X_VERSION_10_13; + } + private static final int MAC_OS_X_VERSION_10_13_1 = (int)101301L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_13_1 101301 + * } + */ + public static int MAC_OS_X_VERSION_10_13_1() { + return MAC_OS_X_VERSION_10_13_1; + } + private static final int MAC_OS_X_VERSION_10_13_2 = (int)101302L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_13_2 101302 + * } + */ + public static int MAC_OS_X_VERSION_10_13_2() { + return MAC_OS_X_VERSION_10_13_2; + } + private static final int MAC_OS_X_VERSION_10_13_4 = (int)101304L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_13_4 101304 + * } + */ + public static int MAC_OS_X_VERSION_10_13_4() { + return MAC_OS_X_VERSION_10_13_4; + } + private static final int MAC_OS_X_VERSION_10_14 = (int)101400L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_14 101400 + * } + */ + public static int MAC_OS_X_VERSION_10_14() { + return MAC_OS_X_VERSION_10_14; + } + private static final int MAC_OS_X_VERSION_10_14_1 = (int)101401L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_14_1 101401 + * } + */ + public static int MAC_OS_X_VERSION_10_14_1() { + return MAC_OS_X_VERSION_10_14_1; + } + private static final int MAC_OS_X_VERSION_10_14_4 = (int)101404L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_14_4 101404 + * } + */ + public static int MAC_OS_X_VERSION_10_14_4() { + return MAC_OS_X_VERSION_10_14_4; + } + private static final int MAC_OS_X_VERSION_10_14_5 = (int)101405L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_14_5 101405 + * } + */ + public static int MAC_OS_X_VERSION_10_14_5() { + return MAC_OS_X_VERSION_10_14_5; + } + private static final int MAC_OS_X_VERSION_10_14_6 = (int)101406L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_14_6 101406 + * } + */ + public static int MAC_OS_X_VERSION_10_14_6() { + return MAC_OS_X_VERSION_10_14_6; + } + private static final int MAC_OS_X_VERSION_10_15 = (int)101500L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_15 101500 + * } + */ + public static int MAC_OS_X_VERSION_10_15() { + return MAC_OS_X_VERSION_10_15; + } + private static final int MAC_OS_X_VERSION_10_15_1 = (int)101501L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_15_1 101501 + * } + */ + public static int MAC_OS_X_VERSION_10_15_1() { + return MAC_OS_X_VERSION_10_15_1; + } + private static final int MAC_OS_X_VERSION_10_15_4 = (int)101504L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_15_4 101504 + * } + */ + public static int MAC_OS_X_VERSION_10_15_4() { + return MAC_OS_X_VERSION_10_15_4; + } + private static final int MAC_OS_X_VERSION_10_16 = (int)101600L; + /** + * {@snippet lang=c : + * #define MAC_OS_X_VERSION_10_16 101600 + * } + */ + public static int MAC_OS_X_VERSION_10_16() { + return MAC_OS_X_VERSION_10_16; + } + private static final int MAC_OS_VERSION_11_0 = (int)110000L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_11_0 110000 + * } + */ + public static int MAC_OS_VERSION_11_0() { + return MAC_OS_VERSION_11_0; + } + private static final int MAC_OS_VERSION_11_1 = (int)110100L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_11_1 110100 + * } + */ + public static int MAC_OS_VERSION_11_1() { + return MAC_OS_VERSION_11_1; + } + private static final int MAC_OS_VERSION_11_3 = (int)110300L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_11_3 110300 + * } + */ + public static int MAC_OS_VERSION_11_3() { + return MAC_OS_VERSION_11_3; + } + private static final int MAC_OS_VERSION_11_4 = (int)110400L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_11_4 110400 + * } + */ + public static int MAC_OS_VERSION_11_4() { + return MAC_OS_VERSION_11_4; + } + private static final int MAC_OS_VERSION_11_5 = (int)110500L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_11_5 110500 + * } + */ + public static int MAC_OS_VERSION_11_5() { + return MAC_OS_VERSION_11_5; + } + private static final int MAC_OS_VERSION_11_6 = (int)110600L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_11_6 110600 + * } + */ + public static int MAC_OS_VERSION_11_6() { + return MAC_OS_VERSION_11_6; + } + private static final int MAC_OS_VERSION_12_0 = (int)120000L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_12_0 120000 + * } + */ + public static int MAC_OS_VERSION_12_0() { + return MAC_OS_VERSION_12_0; + } + private static final int MAC_OS_VERSION_12_1 = (int)120100L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_12_1 120100 + * } + */ + public static int MAC_OS_VERSION_12_1() { + return MAC_OS_VERSION_12_1; + } + private static final int MAC_OS_VERSION_12_2 = (int)120200L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_12_2 120200 + * } + */ + public static int MAC_OS_VERSION_12_2() { + return MAC_OS_VERSION_12_2; + } + private static final int MAC_OS_VERSION_12_3 = (int)120300L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_12_3 120300 + * } + */ + public static int MAC_OS_VERSION_12_3() { + return MAC_OS_VERSION_12_3; + } + private static final int MAC_OS_VERSION_12_4 = (int)120400L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_12_4 120400 + * } + */ + public static int MAC_OS_VERSION_12_4() { + return MAC_OS_VERSION_12_4; + } + private static final int MAC_OS_VERSION_12_5 = (int)120500L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_12_5 120500 + * } + */ + public static int MAC_OS_VERSION_12_5() { + return MAC_OS_VERSION_12_5; + } + private static final int MAC_OS_VERSION_12_6 = (int)120600L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_12_6 120600 + * } + */ + public static int MAC_OS_VERSION_12_6() { + return MAC_OS_VERSION_12_6; + } + private static final int MAC_OS_VERSION_12_7 = (int)120700L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_12_7 120700 + * } + */ + public static int MAC_OS_VERSION_12_7() { + return MAC_OS_VERSION_12_7; + } + private static final int MAC_OS_VERSION_13_0 = (int)130000L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_13_0 130000 + * } + */ + public static int MAC_OS_VERSION_13_0() { + return MAC_OS_VERSION_13_0; + } + private static final int MAC_OS_VERSION_13_1 = (int)130100L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_13_1 130100 + * } + */ + public static int MAC_OS_VERSION_13_1() { + return MAC_OS_VERSION_13_1; + } + private static final int MAC_OS_VERSION_13_2 = (int)130200L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_13_2 130200 + * } + */ + public static int MAC_OS_VERSION_13_2() { + return MAC_OS_VERSION_13_2; + } + private static final int MAC_OS_VERSION_13_3 = (int)130300L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_13_3 130300 + * } + */ + public static int MAC_OS_VERSION_13_3() { + return MAC_OS_VERSION_13_3; + } + private static final int MAC_OS_VERSION_13_4 = (int)130400L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_13_4 130400 + * } + */ + public static int MAC_OS_VERSION_13_4() { + return MAC_OS_VERSION_13_4; + } + private static final int MAC_OS_VERSION_13_5 = (int)130500L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_13_5 130500 + * } + */ + public static int MAC_OS_VERSION_13_5() { + return MAC_OS_VERSION_13_5; + } + private static final int MAC_OS_VERSION_13_6 = (int)130600L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_13_6 130600 + * } + */ + public static int MAC_OS_VERSION_13_6() { + return MAC_OS_VERSION_13_6; + } + private static final int MAC_OS_VERSION_14_0 = (int)140000L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_14_0 140000 + * } + */ + public static int MAC_OS_VERSION_14_0() { + return MAC_OS_VERSION_14_0; + } + private static final int MAC_OS_VERSION_14_1 = (int)140100L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_14_1 140100 + * } + */ + public static int MAC_OS_VERSION_14_1() { + return MAC_OS_VERSION_14_1; + } + private static final int MAC_OS_VERSION_14_2 = (int)140200L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_14_2 140200 + * } + */ + public static int MAC_OS_VERSION_14_2() { + return MAC_OS_VERSION_14_2; + } + private static final int MAC_OS_VERSION_14_3 = (int)140300L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_14_3 140300 + * } + */ + public static int MAC_OS_VERSION_14_3() { + return MAC_OS_VERSION_14_3; + } + private static final int MAC_OS_VERSION_14_4 = (int)140400L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_14_4 140400 + * } + */ + public static int MAC_OS_VERSION_14_4() { + return MAC_OS_VERSION_14_4; + } + private static final int MAC_OS_VERSION_14_5 = (int)140500L; + /** + * {@snippet lang=c : + * #define MAC_OS_VERSION_14_5 140500 + * } + */ + public static int MAC_OS_VERSION_14_5() { + return MAC_OS_VERSION_14_5; + } + private static final int __MAC_OS_X_VERSION_MAX_ALLOWED = (int)140500L; + /** + * {@snippet lang=c : + * #define __MAC_OS_X_VERSION_MAX_ALLOWED 140500 + * } + */ + public static int __MAC_OS_X_VERSION_MAX_ALLOWED() { + return __MAC_OS_X_VERSION_MAX_ALLOWED; + } + private static final int __DARWIN_WCHAR_MAX = (int)2147483647L; + /** + * {@snippet lang=c : + * #define __DARWIN_WCHAR_MAX 2147483647 + * } + */ + public static int __DARWIN_WCHAR_MAX() { + return __DARWIN_WCHAR_MAX; + } + private static final int __DARWIN_WCHAR_MIN = (int)-2147483648L; + /** + * {@snippet lang=c : + * #define __DARWIN_WCHAR_MIN -2147483648 + * } + */ + public static int __DARWIN_WCHAR_MIN() { + return __DARWIN_WCHAR_MIN; + } + private static final int __DARWIN_WEOF = (int)-1L; + /** + * {@snippet lang=c : + * #define __DARWIN_WEOF -1 + * } + */ + public static int __DARWIN_WEOF() { + return __DARWIN_WEOF; + } + private static final int EOF = (int)-1L; + /** + * {@snippet lang=c : + * #define EOF -1 + * } + */ + public static int EOF() { + return EOF; + } + /** + * {@snippet lang=c : + * #define P_tmpdir "/var/tmp/" + * } + */ + public static MemorySegment P_tmpdir() { + class Holder { + static final MemorySegment P_tmpdir + = somelib_h.LIBRARY_ARENA.allocateFrom("/var/tmp/"); + } + return Holder.P_tmpdir; + } +} + diff --git a/feature/java/somelib/src/test/java/dev/diplomattest/somelib/Float64VecTest.java b/feature/java/somelib/src/test/java/dev/diplomattest/somelib/Float64VecTest.java new file mode 100644 index 0000000..a0962a1 --- /dev/null +++ b/feature/java/somelib/src/test/java/dev/diplomattest/somelib/Float64VecTest.java @@ -0,0 +1,30 @@ +package dev.diplomattest.somelib; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.*; + +class Float64VecTest { + @Test + void testFloat64Vec() { + long[] lArray = {1, 2, 3, 4}; + + double[] dArray = {1, 2, 3, 4}; + var float64Vec = Float64Vec.newIsize(lArray); + var outArray = float64Vec.asSlice(); + assertEquals(dArray.length, outArray.length); + for (var i = 0; i < dArray.length; i++) { + assertEquals(dArray[i], outArray[i]); + } + + var newVec = Float64Vec.new_(dArray); + var newArray = newVec.asSlice(); + assertEquals(dArray.length, newArray.length); + for (var i = 0; i < dArray.length; i++) { + assertEquals(dArray[i], newArray[i]); + } + } + +} \ No newline at end of file diff --git a/feature/java/somelib/src/test/java/dev/diplomattest/somelib/MyEnumTest.java b/feature/java/somelib/src/test/java/dev/diplomattest/somelib/MyEnumTest.java new file mode 100644 index 0000000..a94e2ba --- /dev/null +++ b/feature/java/somelib/src/test/java/dev/diplomattest/somelib/MyEnumTest.java @@ -0,0 +1,12 @@ +package dev.diplomattest.somelib; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class MyEnumTest { + @Test + public void testGetA() { + assertEquals(MyEnum.getA(), MyEnum.A); + } +} diff --git a/feature/java/somelib/src/test/java/dev/diplomattest/somelib/MyStringTest.java b/feature/java/somelib/src/test/java/dev/diplomattest/somelib/MyStringTest.java new file mode 100644 index 0000000..1e0d501 --- /dev/null +++ b/feature/java/somelib/src/test/java/dev/diplomattest/somelib/MyStringTest.java @@ -0,0 +1,22 @@ +package dev.diplomattest.somelib; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Comparator; + +import static org.junit.jupiter.api.Assertions.*; + +class MyStringTest { + + @Test + void newFromFirst() { + var str = "Hi There"; + var str1 = "Hi There 1"; + var str2 = "Hi There 2"; + var strs = new String[]{str, str1, str2}; + var myStr = MyString.newFromFirst(strs); + assertEquals(myStr.getStr(), str); + + } +} \ No newline at end of file diff --git a/feature/java/somelib/src/test/java/dev/diplomattest/somelib/OpaqueTest.java b/feature/java/somelib/src/test/java/dev/diplomattest/somelib/OpaqueTest.java new file mode 100644 index 0000000..ee5ac79 --- /dev/null +++ b/feature/java/somelib/src/test/java/dev/diplomattest/somelib/OpaqueTest.java @@ -0,0 +1,19 @@ +package dev.diplomattest.somelib; + +import org.junit.jupiter.api.Test; + +import java.lang.foreign.Arena; +import java.lang.foreign.SegmentAllocator; + +import static org.junit.jupiter.api.Assertions.*; + +class OpaqueTest { + @Test + void testOpaque() { + var input = "How do you do?"; + var opaque = Opaque.fromStr(input); + var debugStr = opaque.getDebugStr(); + assertEquals(input.length(), opaque.internalLen()); + assertEquals("\"How do you do?\"", debugStr); + } +} \ No newline at end of file diff --git a/feature/src/attrs.rs b/feature/src/attrs.rs new file mode 100644 index 0000000..9d87a32 --- /dev/null +++ b/feature/src/attrs.rs @@ -0,0 +1,35 @@ +#[diplomat::bridge] +#[diplomat::abi_rename = "namespace_{0}"] +#[diplomat::attr(not(any(c, kotlin)), rename = "Renamed{0}")] +#[diplomat::attr(auto, namespace = "ns")] +pub mod ffi { + #[diplomat::opaque] + #[diplomat::attr(not(supports = iterators), disable)] + pub struct MyIterable(Vec); + + #[diplomat::opaque] + #[diplomat::attr(not(supports = iterators), disable)] + pub struct MyIterator<'a>(std::slice::Iter<'a, u8>); + + #[diplomat::opaque] + #[diplomat::attr(not(supports = indexing), disable)] + pub struct MyIndexer(Vec); + + impl MyIterable { + #[diplomat::attr(auto, constructor)] + pub fn new(x: &[u8]) -> Box { + Box::new(Self(x.into())) + } + #[diplomat::attr(auto, iterable)] + pub fn iter<'a>(&'a self) -> Box> { + Box::new(MyIterator(self.0.iter())) + } + } + + impl<'a> MyIterator<'a> { + #[diplomat::attr(auto, iterator)] + pub fn next(&mut self) -> Option { + self.0.next().copied() + } + } +} diff --git a/feature/src/imports.rs b/feature/src/imports.rs new file mode 100644 index 0000000..1b5cba9 --- /dev/null +++ b/feature/src/imports.rs @@ -0,0 +1,13 @@ +#[diplomat::bridge] +pub mod ffi { + pub enum UnimportedEnum { + A, + B, + C, + } + + pub struct ImportedStruct { + foo: UnimportedEnum, + count: u8, + } +} diff --git a/feature/src/lib.rs b/feature/src/lib.rs new file mode 100644 index 0000000..c4567df --- /dev/null +++ b/feature/src/lib.rs @@ -0,0 +1,19 @@ +//! Various integration tests for Diplomat features + +// We're not trying to write good code here, just tests +#![allow(clippy::style, dead_code)] +// Diplomat limitations +#![allow( + clippy::needless_lifetimes, + clippy::result_unit_err, + clippy::should_implement_trait +)] + +extern crate alloc; + +pub mod attrs; +pub mod imports; +pub mod lifetimes; +pub mod selftype; +pub mod slices; +pub mod structs; diff --git a/feature/src/lifetimes.rs b/feature/src/lifetimes.rs new file mode 100644 index 0000000..c2a33a2 --- /dev/null +++ b/feature/src/lifetimes.rs @@ -0,0 +1,298 @@ +#[diplomat::bridge] +pub mod ffi { + #[diplomat::opaque] + pub struct Foo<'a>(&'a DiplomatStr); + + #[diplomat::opaque] + #[diplomat::transparent_convert] + pub struct Bar<'b, 'a: 'b>(&'b Foo<'a>); + + pub struct BorrowedFields<'a> { + a: DiplomatStr16Slice<'a>, + b: DiplomatStrSlice<'a>, + c: DiplomatUtf8StrSlice<'a>, + } + + pub struct BorrowedFieldsWithBounds<'a, 'b: 'a, 'c: 'b> { + field_a: DiplomatStr16Slice<'a>, + field_b: DiplomatStrSlice<'b>, + field_c: DiplomatUtf8StrSlice<'c>, + } + + pub struct BorrowedFieldsReturning<'a> { + bytes: DiplomatStrSlice<'a>, + } + impl<'a> Foo<'a> { + #[diplomat::attr(auto, constructor)] + pub fn new(x: &'a DiplomatStr) -> Box { + Box::new(Foo(x)) + } + + #[diplomat::attr(auto, getter = "bar")] + pub fn get_bar<'b>(&'b self) -> Box> { + Box::new(Bar(self)) + } + + #[diplomat::attr(auto, named_constructor = "static")] + #[diplomat::attr(not(supports = static_slices), disable)] + pub fn new_static(x: &'static DiplomatStr) -> Box { + Box::new(Foo(x)) + } + + pub fn as_returning(&self) -> BorrowedFieldsReturning<'a> { + BorrowedFieldsReturning { + bytes: self.0.into(), + } + } + + #[diplomat::attr(auto, named_constructor)] + pub fn extract_from_fields(fields: BorrowedFields<'a>) -> Box { + Box::new(Foo(fields.b.into())) + } + + #[diplomat::attr(auto, named_constructor)] + /// Test that the extraction logic correctly pins the right fields + pub fn extract_from_bounds<'x, 'y: 'x + 'a, 'z: 'x + 'y>( + bounds: BorrowedFieldsWithBounds<'x, 'y, 'z>, + another_string: &'a DiplomatStr, + ) -> Box { + if bounds.field_b.is_empty() { + Box::new(Self(another_string)) + } else { + Box::new(Self(bounds.field_b.into())) + } + } + } + + impl<'x> BorrowedFields<'x> { + pub fn from_bar_and_strings( + bar: &'x Bar<'x, 'x>, + dstr16: &'x DiplomatStr16, + utf8_str: &'x str, + ) -> Self { + BorrowedFields { + a: dstr16.into(), + b: bar.0 .0.into(), + c: utf8_str.into(), + } + } + } + + impl<'x, 'y: 'x, 'z: 'y> BorrowedFieldsWithBounds<'x, 'y, 'z> { + pub fn from_foo_and_strings( + foo: &'x Foo<'y>, + dstr16_x: &'x DiplomatStr16, + utf8_str_z: &'z str, + ) -> Self { + BorrowedFieldsWithBounds { + field_a: dstr16_x.into(), + field_b: foo.0.into(), + field_c: utf8_str_z.into(), + } + } + } + + pub struct NestedBorrowedFields<'x, 'y: 'x, 'z> { + fields: BorrowedFields<'x>, + bounds: BorrowedFieldsWithBounds<'x, 'y, 'y>, + bounds2: BorrowedFieldsWithBounds<'z, 'z, 'z>, + } + + impl<'x, 'y: 'x, 'z> NestedBorrowedFields<'x, 'y, 'z> { + pub fn from_bar_and_foo_and_strings( + bar: &'x Bar<'x, 'y>, + foo: &'z Foo<'z>, + dstr16_x: &'x DiplomatStr16, + dstr16_z: &'z DiplomatStr16, + utf8_str_y: &'y str, + utf8_str_z: &'z str, + ) -> Self { + let fields = BorrowedFields::from_bar_and_strings(bar, dstr16_x, utf8_str_y); + let bounds = + BorrowedFieldsWithBounds::from_foo_and_strings(bar.0, dstr16_x, utf8_str_y); + let bounds2 = BorrowedFieldsWithBounds::from_foo_and_strings(foo, dstr16_z, utf8_str_z); + Self { + fields, + bounds, + bounds2, + } + } + } + + // FIXME(#191): This test breaks the C++ codegen + impl<'b, 'a: 'b> Bar<'b, 'a> { + #[diplomat::attr(auto, getter)] + pub fn foo(&'b self) -> &'b Foo<'a> { + self.0 + } + } + + #[derive(Copy, Clone)] + #[diplomat::opaque] + pub struct One<'a>(super::One<'a>); + + #[derive(Copy, Clone)] + #[diplomat::opaque] + pub struct Two<'a, 'b>(super::Two<'a, 'b>); + + impl<'o> One<'o> { + // Holds: [hold] + #[allow(clippy::extra_unused_lifetimes)] + #[diplomat::attr(auto, named_constructor)] + pub fn transitivity<'a, 'b: 'a, 'c: 'b, 'd: 'c, 'e: 'd, 'x>( + hold: &'x One<'e>, + nohold: &One<'x>, + ) -> Box> { + let _ = (hold, nohold); + unimplemented!() + } + + // Holds: [hold] + #[allow(clippy::extra_unused_lifetimes)] + #[diplomat::attr(auto, named_constructor)] + pub fn cycle<'a: 'b, 'b: 'c, 'c: 'a, 'x>( + hold: &Two<'x, 'b>, + nohold: &'x One<'x>, + ) -> Box> { + let _ = (hold, nohold); + unimplemented!() + } + + // Holds: [a, b, c, d] + #[diplomat::attr(auto, named_constructor)] + pub fn many_dependents<'a, 'b: 'a, 'c: 'a, 'd: 'b + 'x, 'x, 'y>( + a: &'x One<'a>, + b: &'b One<'a>, + c: &Two<'x, 'c>, + d: &'x Two<'d, 'y>, + nohold: &'x Two<'x, 'y>, + ) -> Box> { + let _ = (a, b, c, d, nohold); + unimplemented!() + } + + // Holds: [hold] + #[diplomat::attr(auto, named_constructor)] + pub fn return_outlives_param<'short, 'long: 'short>( + hold: &Two<'long, 'short>, + nohold: &'short One<'short>, + ) -> Box> { + let _ = (hold, nohold); + unimplemented!() + } + + // Holds: [top, left, right, bottom] + #[diplomat::attr(auto, named_constructor)] + pub fn diamond_top<'top, 'left: 'top, 'right: 'top, 'bottom: 'left + 'right>( + top: &One<'top>, + left: &One<'left>, + right: &One<'right>, + bottom: &One<'bottom>, + ) -> Box> { + Box::new(match 0 { + 0 => *bottom, + 1 => *left, + 2 => *right, + _ => *top, + }) + } + + // Holds: [left, bottom] + #[diplomat::attr(auto, named_constructor)] + pub fn diamond_left<'top, 'left: 'top, 'right: 'top, 'bottom: 'left + 'right>( + top: &One<'top>, + left: &One<'left>, + right: &One<'right>, + bottom: &One<'bottom>, + ) -> Box> { + let _ = (top, right); + Box::new(match 0 { + 0 => *bottom, + _ => *left, + }) + } + + // Holds: [right, bottom] + #[diplomat::attr(auto, named_constructor)] + pub fn diamond_right<'top, 'left: 'top, 'right: 'top, 'bottom: 'left + 'right>( + top: &One<'top>, + left: &One<'left>, + right: &One<'right>, + bottom: &One<'bottom>, + ) -> Box> { + let _ = (top, left); + Box::new(match 0 { + 0 => *bottom, + _ => *right, + }) + } + + // Holds: [bottom] + #[diplomat::attr(auto, named_constructor)] + pub fn diamond_bottom<'top, 'left: 'top, 'right: 'top, 'bottom: 'left + 'right>( + top: &One<'top>, + left: &One<'left>, + right: &One<'right>, + bottom: &One<'bottom>, + ) -> Box> { + let _ = (top, left, right); + Box::new(*bottom) + } + + // Holds: [a, b, c, d] + #[diplomat::attr(auto, named_constructor)] + pub fn diamond_and_nested_types<'a, 'b: 'a, 'c: 'b, 'd: 'b + 'c, 'x, 'y>( + a: &One<'a>, + b: &'y One<'b>, + c: &One<'c>, + d: &One<'d>, + nohold: &One<'x>, + ) -> Box> { + let _ = nohold; + Box::new(match 0 { + 0 => *a, + 1 => *b, + 2 => *c, + _ => *d, + }) + } + + // Holds: [implicit_hold, explicit_hold] + #[allow(clippy::extra_unused_lifetimes)] + #[diplomat::attr(auto, named_constructor)] + pub fn implicit_bounds<'a, 'b: 'a, 'c: 'b, 'd: 'c, 'x, 'y>( + explicit_hold: &'d One<'x>, // implies that 'x: 'd + implicit_hold: &One<'x>, + nohold: &One<'y>, + ) -> Box> { + let _ = nohold; + Box::new(match 0 { + 0 => *explicit_hold, + _ => *implicit_hold, + }) + } + + // Holds: [a, b, c] + #[allow(clippy::needless_lifetimes)] + #[diplomat::attr(auto, named_constructor)] + pub fn implicit_bounds_deep<'a, 'b, 'c, 'd, 'x>( + explicit_: &'a One<'b>, + implicit_1: &'b One<'c>, + implicit_2: &'c One<'d>, + nohold: &'x One<'x>, + ) -> Box> { + let _ = nohold; + Box::new(match 0 { + 0 => *explicit_, + 1 => *implicit_1, + _ => *implicit_2, + }) + } + } +} + +#[derive(Copy, Clone)] +pub struct One<'a>(&'a ()); + +#[derive(Copy, Clone)] +pub struct Two<'a, 'b>(&'a (), &'b ()); diff --git a/feature/src/selftype.rs b/feature/src/selftype.rs new file mode 100644 index 0000000..d96a2a0 --- /dev/null +++ b/feature/src/selftype.rs @@ -0,0 +1,22 @@ +#[diplomat::bridge] +mod ffi { + #[diplomat::opaque] + struct RefListParameter; + + #[diplomat::opaque] + struct RefList<'a>((&'a RefListParameter, Option>)); + + impl<'b> RefList<'b> { + #[diplomat::attr(auto, named_constructor)] + pub fn node(data: &'b RefListParameter) -> Box { + Box::new(RefList((data, None))) + } + + // pub fn extend(&mut self, other: Self) { + // match self.next.as_mut() { + // Some(tail) => tail.extend(other), + // None => self.next = Some(Box::new(other)), + // } + // } + } +} diff --git a/feature/src/slices.rs b/feature/src/slices.rs new file mode 100644 index 0000000..1a98069 --- /dev/null +++ b/feature/src/slices.rs @@ -0,0 +1,123 @@ +#[diplomat::bridge] +mod ffi { + use diplomat_runtime::{DiplomatStr, DiplomatStrSlice, DiplomatWrite}; + use std::fmt::Write as _; + + #[diplomat::opaque] + struct MyString(String); + + impl MyString { + #[diplomat::attr(auto, constructor)] + pub fn new(v: &DiplomatStr) -> Box { + Box::new(Self(String::from_utf8(v.to_owned()).unwrap())) + } + + #[diplomat::attr(auto, named_constructor = "unsafe")] + pub fn new_unsafe(v: &str) -> Box { + Box::new(Self(v.to_string())) + } + + #[diplomat::attr(supports = memory_sharing, disable)] + pub fn new_owned(v: Box) -> Box { + Box::new(Self(String::from_utf8(v.into()).unwrap())) + } + + pub fn new_from_first(v: &[DiplomatStrSlice]) -> Box { + Box::new(Self(core::str::from_utf8(v[0].into()).unwrap().into())) + } + + #[diplomat::attr(auto, setter = "str")] + pub fn set_str(&mut self, new_str: &DiplomatStr) { + self.0 = String::from_utf8(new_str.to_owned()).unwrap(); + } + + #[diplomat::attr(auto, getter = "str")] + pub fn get_str(&self, write: &mut DiplomatWrite) { + let _infallible = write!(write, "{}", self.0); + } + + pub fn string_transform(foo: &str, write: &mut DiplomatWrite) { + let _ = foo; + let _ = write; + } + } + + #[diplomat::opaque] + struct Float64Vec(Vec); + + impl Float64Vec { + #[diplomat::attr(not(supports = memory_sharing), disable)] + pub fn new(v: &[f64]) -> Box { + Box::new(Self(v.to_vec())) + } + + #[diplomat::attr(auto, named_constructor = "bool")] + pub fn new_bool(v: &[bool]) -> Box { + Box::new(Self(v.iter().map(|&x| x as u8 as f64).collect())) + } + + #[diplomat::attr(auto, named_constructor = "i16")] + pub fn new_i16(v: &[i16]) -> Box { + Box::new(Self(v.iter().map(|&x| x as f64).collect())) + } + + #[diplomat::attr(auto, named_constructor = "u16")] + pub fn new_u16(v: &[u16]) -> Box { + Box::new(Self(v.iter().map(|&x| x as f64).collect())) + } + + #[diplomat::attr(auto, named_constructor = "isize")] + pub fn new_isize(v: &[isize]) -> Box { + Box::new(Self(v.iter().map(|&x| x as f64).collect())) + } + + #[diplomat::attr(auto, named_constructor = "usize")] + pub fn new_usize(v: &[usize]) -> Box { + Box::new(Self(v.iter().map(|&x| x as f64).collect())) + } + + #[diplomat::attr(auto, named_constructor = "f64BeBytes")] + pub fn new_f64_be_bytes(v: &[DiplomatByte]) -> Box { + Box::new(Self( + v.chunks_exact(8) + .map(|b| f64::from_be_bytes([b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]])) + .collect(), + )) + } + + #[diplomat::attr(supports = memory_sharing, disable)] + #[diplomat::attr(auto, constructor)] + pub fn new_from_owned(v: Box<[f64]>) -> Box { + Box::new(Self(v.into())) + } + + #[diplomat::attr(auto, getter = "asSlice")] + pub fn as_slice<'a>(&'a self) -> &'a [f64] { + &self.0 + } + + pub fn fill_slice(&self, v: &mut [f64]) { + v.copy_from_slice(&self.0) + } + + pub fn set_value(&mut self, new_slice: &[f64]) { + self.0 = new_slice.to_vec(); + } + + #[diplomat::attr(auto, stringifier)] + pub fn to_string(&self, w: &mut DiplomatWrite) { + let _infallible = write!(w, "{:?}", self.0); + } + + #[allow(clippy::needless_lifetimes)] + pub fn borrow<'a>(&'a self) -> &'a [f64] { + &self.0 + } + + #[diplomat::attr(auto, indexer)] + #[diplomat::attr(java, disable)] + pub fn get(&self, i: usize) -> Option { + self.0.get(i).copied() + } + } +} diff --git a/feature/src/structs.rs b/feature/src/structs.rs new file mode 100644 index 0000000..e454eb7 --- /dev/null +++ b/feature/src/structs.rs @@ -0,0 +1,271 @@ +#[allow(clippy::needless_lifetimes)] +#[diplomat::bridge] +pub mod ffi { + use diplomat_runtime::DiplomatStr16; + + use crate::imports::ffi::ImportedStruct; + use std::fmt::Write; + use std::sync::Mutex; + + #[diplomat::opaque] + #[diplomat::transparent_convert] + pub struct Opaque(String); + + #[diplomat::opaque] + pub struct OpaqueMutexedString(Mutex); + + #[diplomat::opaque] + pub struct Utf16Wrap(Vec); + + #[derive(Debug, PartialEq, Eq)] + pub enum MyEnum { + A = -2, + B = -1, + C = 0, + D = 1, + E = 2, + F = 3, + } + + #[derive(Debug, PartialEq, Eq)] + pub enum ContiguousEnum { + C = 0, + D = 1, + E = 2, + F = 3, + } + + pub struct MyStruct { + a: u8, + b: bool, + c: u8, + d: u64, + e: i32, + f: DiplomatChar, + g: MyEnum, + } + + pub struct MyZst; + + impl Opaque { + #[diplomat::attr(auto, constructor)] + pub fn new() -> Box { + Box::new(Opaque("".into())) + } + + #[diplomat::attr(java, disable)] + pub fn try_from_utf8(input: &DiplomatStr) -> Option> { + let s = std::str::from_utf8(input).ok()?; + Some(Box::new(Self(s.into()))) + } + + pub fn from_str(input: &str) -> Box { + Box::new(Self(input.into())) + } + + pub fn get_debug_str(&self, write: &mut DiplomatWrite) { + let _infallible = write!(write, "{:?}", &self.0); + } + + #[diplomat::rust_link(Something::something, FnInStruct)] + #[diplomat::rust_link(Something::something_else, FnInStruct)] + #[diplomat::rust_link(Something::something_small, FnInStruct, compact)] + #[diplomat::rust_link(SomethingElse::something, FnInStruct, compact)] + #[diplomat::rust_link(SomethingElse::something_else, FnInStruct, hidden)] + pub fn assert_struct(&self, s: MyStruct) { + s.assert_value(); + } + + pub fn returns_usize() -> usize { + 412 + } + + pub fn internal_len(&self) -> usize { + self.0.len() + } + + pub fn returns_imported() -> ImportedStruct { + unimplemented!() + } + + pub fn cmp() -> core::cmp::Ordering { + unimplemented!() + } + } + + impl OpaqueMutexedString { + pub fn from_usize(number: usize) -> Box { + Box::new(OpaqueMutexedString(Mutex::new(format!("{number}")))) + } + + pub fn change(&self, number: usize) { + let mut guard = self.0.lock().expect("Failed to lock mutex"); + *guard = format!("{number}"); + } + + pub fn borrow<'a>(&'a self) -> &'a OpaqueMutexedString { + self + } + + pub fn borrow_other<'a>(other: &'a OpaqueMutexedString) -> &'a OpaqueMutexedString { + other + } + + pub fn borrow_self_or_other<'a>( + &'a self, + other: &'a OpaqueMutexedString, + ) -> &'a OpaqueMutexedString { + let guard = self.0.lock().expect("Failed to lock mutex"); + if guard.len() % 2 == 0 { + self + } else { + other + } + } + + pub fn get_len_and_add(&self, other: usize) -> usize { + let guard = self.0.lock().expect("Failed to lock mutex"); + guard.len() + other + } + + pub fn dummy_str<'a>(&'a self) -> &'a DiplomatStr { + "A const str with non byte char: 餐 which is a DiplomatChar,".as_bytes() + } + + pub fn wrapper<'a>(&'a self) -> Box { + let chars = "A const str with non byte char: 𐐷 which is a DiplomatChar," + .encode_utf16() + .collect(); + Box::new(Utf16Wrap(chars)) + } + } + + impl Utf16Wrap { + #[diplomat::attr(auto, constructor)] + pub fn from_utf16(input: &DiplomatStr16) -> Box { + Box::new(Self(input.into())) + } + + pub fn get_debug_str(&self, write: &mut DiplomatWrite) { + let _infallible = write!(write, "{:?}", &self.0); + } + + pub fn borrow_cont<'a>(&'a self) -> &'a DiplomatStr16 { + &self.0 + } + } + + impl MyEnum { + pub fn into_value(self) -> i8 { + self as i8 + } + + pub fn get_a() -> MyEnum { + MyEnum::A + } + } + + impl MyStruct { + #[diplomat::attr(auto, constructor)] + pub fn new() -> MyStruct { + MyStruct { + a: 17, + b: true, + c: 209, + d: 1234, + e: 5991, + f: '餐' as DiplomatChar, + g: MyEnum::B, + } + } + + pub fn into_a(self) -> u8 { + self.a + } + + fn assert_value(&self) { + assert_eq!(self.a, 17); + assert!(self.b); + assert_eq!(self.c, 209); + assert_eq!(self.d, 1234); + assert_eq!(self.e, 5991); + assert_eq!(self.f, '餐' as DiplomatChar); + assert_eq!(self.g, MyEnum::B); + } + + #[diplomat::attr(java, disable)] + pub fn returns_zst_result() -> Result<(), MyZst> { + Ok(()) + } + + #[diplomat::attr(java, disable)] + pub fn fails_zst_result() -> Result<(), MyZst> { + Err(MyZst {}) + } + } + + // Test that cycles between structs work even when + // they reference each other in the methods + #[derive(Default)] + pub struct CyclicStructA { + pub a: CyclicStructB, + } + #[derive(Default)] + pub struct CyclicStructB { + pub field: u8, + } + + impl CyclicStructA { + pub fn get_b() -> CyclicStructB { + Default::default() + } + } + impl CyclicStructB { + pub fn get_a() -> CyclicStructA { + Default::default() + } + } + + /// Testing JS-specific layout/padding behavior + #[diplomat::attr(not(js), disable)] + pub struct ScalarPairWithPadding { + pub first: u8, + // Padding: [3 x u8] + pub second: u32, + } + + impl ScalarPairWithPadding { + pub fn assert_value(self) { + assert_eq!(self.first, 122); + assert_eq!(self.second, 414); + } + } + + /// Testing JS-specific layout/padding behavior + #[diplomat::attr(not(js), disable)] + pub struct BigStructWithStuff { + pub first: u8, + // Padding: [1 x u8] + pub second: u16, + pub third: u16, + // Padding: [1 x u16] + pub fourth: ScalarPairWithPadding, + pub fifth: u8, + } + + impl BigStructWithStuff { + pub fn assert_value(self, extra_val: u16) { + assert_eq!(self.first, 101); + assert_eq!(self.second, 505); + assert_eq!(self.third, 9345); + self.fourth.assert_value(); + assert_eq!(self.fifth, 99); + assert_eq!(extra_val, 853); + } + } +} + +#[allow(unused)] +fn test_transparent_convert_exists(s: &String) -> &ffi::Opaque { + ffi::Opaque::transparent_convert(s) +} diff --git a/jextrsact/Cargo.toml b/jextrsact/Cargo.toml new file mode 100644 index 0000000..b549625 --- /dev/null +++ b/jextrsact/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "jextrsact" +version = "0.1.0" +edition = "2021" + +[dependencies] +diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat", rev = "588f6ffe413bfca367bbb2a749a5965d40a3d5b3", package = "diplomat-runtime"} +diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat", rev = "588f6ffe413bfca367bbb2a749a5965d40a3d5b3", package = "diplomat-tool" } +diplomat_core = { git = "https://github.com/rust-diplomat/diplomat", rev = "588f6ffe413bfca367bbb2a749a5965d40a3d5b3", package = "diplomat_core" } diff --git a/jextrsact/README.md b/jextrsact/README.md new file mode 100644 index 0000000..eb34316 --- /dev/null +++ b/jextrsact/README.md @@ -0,0 +1,4 @@ +jext**rs**act intends to be a minimal conversion tool for generating [JEP 454](https://openjdk.org/jeps/454) +binding code for diplomat types and functions. It is purely theoretical at this point but should be +relatively straightforward. One can use [the native code](../feature/java/somelib/src/main/java/dev/diplomattest/somelib/ntv) +as an example. diff --git a/jextrsact/src/lib.rs b/jextrsact/src/lib.rs new file mode 100644 index 0000000..07d4ab7 --- /dev/null +++ b/jextrsact/src/lib.rs @@ -0,0 +1,28 @@ +use std::borrow::Cow; + +/// The goal of this library is to generate native binding code similar to jextract +/// but focusing only on functionality needed to make diplomat work +/// ```java +/// public class MyStruct { +/// +/// MyStruct() { +/// // Should not be called directly +/// } +/// +/// private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( +/// somelib_h.C_CHAR.withName("a"), +/// somelib_h.C_BOOL.withName("b"), +/// somelib_h.C_CHAR.withName("c"), +/// MemoryLayout.paddingLayout(5), +/// somelib_h.C_LONG_LONG.withName("d"), +/// somelib_h.C_INT.withName("e"), +/// somelib_h.C_INT.withName("f"), +/// somelib_h.C_INT.withName("g"), +/// MemoryLayout.paddingLayout(4) +/// ).withName("MyStruct"); +/// } +/// ``` +/// +pub fn gen_struct_layout<'a>() -> Cow<'a, str> { + todo!() +}