Add null for implementing serdes
This commit is contained in:
parent
fd8d649f63
commit
bd7216a06e
3 changed files with 15 additions and 4 deletions
|
|
@ -2,6 +2,9 @@
|
||||||
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
|
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
|
||||||
|
|
||||||
## [UNRELEASED]
|
## [UNRELEASED]
|
||||||
|
### Added
|
||||||
|
- New `coffi.mem/null` var for implementing custom types
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Usage of deprecated `(Class/STATIC_FIELD)` access pattern
|
- Usage of deprecated `(Class/STATIC_FIELD)` access pattern
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -292,7 +292,7 @@
|
||||||
|
|
||||||
;; cast null pointers to something understood by panama
|
;; cast null pointers to something understood by panama
|
||||||
(#{::mem/pointer} type)
|
(#{::mem/pointer} type)
|
||||||
`(or ~sym MemorySegment/NULL)
|
`(or ~sym mem/null)
|
||||||
|
|
||||||
(mem/primitive-type type)
|
(mem/primitive-type type)
|
||||||
`(mem/serialize* ~sym ~type-sym ~arena)
|
`(mem/serialize* ~sym ~type-sym ~arena)
|
||||||
|
|
|
||||||
|
|
@ -112,10 +112,18 @@
|
||||||
^long [addressable]
|
^long [addressable]
|
||||||
(.address ^MemorySegment addressable))
|
(.address ^MemorySegment addressable))
|
||||||
|
|
||||||
|
(def ^MemorySegment null
|
||||||
|
"The NULL pointer object.
|
||||||
|
|
||||||
|
While this object is safe to pass to functions which serialize to a pointer,
|
||||||
|
it's generally encouraged to simply pass `nil`. This value primarily exists to
|
||||||
|
make it easier to write custom types with a primitive pointer representation."
|
||||||
|
MemorySegment/NULL)
|
||||||
|
|
||||||
(defn null?
|
(defn null?
|
||||||
"Checks if a memory address is null."
|
"Checks if a memory address is null."
|
||||||
[addr]
|
[addr]
|
||||||
(or (.equals MemorySegment/NULL addr) (not addr)))
|
(or (.equals null addr) (not addr)))
|
||||||
|
|
||||||
(defn address?
|
(defn address?
|
||||||
"Checks if an object is a memory address.
|
"Checks if an object is a memory address.
|
||||||
|
|
@ -872,7 +880,7 @@
|
||||||
(serialize-into obj (second type) segment arena)
|
(serialize-into obj (second type) segment arena)
|
||||||
(address-of segment))
|
(address-of segment))
|
||||||
obj)
|
obj)
|
||||||
MemorySegment/NULL))
|
null))
|
||||||
|
|
||||||
(defmethod serialize* ::void
|
(defmethod serialize* ::void
|
||||||
[_obj _type _arena]
|
[_obj _type _arena]
|
||||||
|
|
@ -1132,7 +1140,7 @@
|
||||||
[obj _type ^Arena arena]
|
[obj _type ^Arena arena]
|
||||||
(if obj
|
(if obj
|
||||||
(.allocateFrom arena ^String obj)
|
(.allocateFrom arena ^String obj)
|
||||||
MemorySegment/NULL))
|
null))
|
||||||
|
|
||||||
(defmethod deserialize* ::c-string
|
(defmethod deserialize* ::c-string
|
||||||
[addr _type]
|
[addr _type]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue