From 7ec2cd157597a4f47cf87335193c56e011f34a7f Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Wed, 19 Jan 2022 10:56:46 -0600 Subject: [PATCH] Add size and alignment constants for primitives --- src/clj/coffi/mem.clj | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/clj/coffi/mem.clj b/src/clj/coffi/mem.clj index 53166d9..21db3d4 100644 --- a/src/clj/coffi/mem.clj +++ b/src/clj/coffi/mem.clj @@ -264,6 +264,62 @@ "The [[MemoryLayout]] for a native pointer in [[native-endian]] [[ByteOrder]]." CLinker/C_POINTER) +(def short-size + "The size in bytes of a c-sized short." + (.byteSize short-layout)) + +(def int-size + "The size in bytes of a c-sized int." + (.byteSize int-layout)) + +(def long-size + "The size in bytes of a c-sized long." + (.byteSize long-layout)) + +(def long-long-size + "The size in bytes of a c-sized long long." + (.byteSize long-long-layout)) + +(def float-size + "The size in bytes of a c-sized float." + (.byteSize float-layout)) + +(def double-size + "The size in bytes of a c-sized double." + (.byteSize double-layout)) + +(def pointer-size + "The size in bytes of a c-sized pointer." + (.byteSize pointer-layout)) + +(def short-alignment + "The alignment in bytes of a c-sized short." + (.byteAlignment short-layout)) + +(def int-alignment + "The alignment in bytes of a c-sized int." + (.byteAlignment int-layout)) + +(def long-alignment + "The alignment in bytes of a c-sized long." + (.byteAlignment long-layout)) + +(def long-long-alignment + "The alignment in bytes of a c-sized long long." + (.byteAlignment long-long-layout)) + +(def float-alignment + "The alignment in bytes of a c-sized float." + (.byteAlignment float-layout)) + +(def double-alignment + "The alignment in bytes of a c-sized double." + (.byteAlignment double-layout)) + +(def pointer-alignment + "The alignment in bytes of a c-sized pointer." + (.byteAlignment pointer-layout)) + (defn read-byte "Reads a [[byte]] from the `segment`, at an optional `offset`." {:inline