Handle null memory addresses in serdes

This commit is contained in:
Joshua Suskalo 2021-09-17 10:49:47 -05:00
parent 595073f84a
commit 4215e2a398

View file

@ -259,11 +259,12 @@
(defmethod serialize* ::pointer (defmethod serialize* ::pointer
[obj type scope] [obj type scope]
(if (sequential? type) (when-not (null? obj)
(let [segment (alloc-instance (second type) scope)] (if (sequential? type)
(serialize-into obj (second type) segment scope) (let [segment (alloc-instance (second type) scope)]
(address-of segment)) (serialize-into obj (second type) segment scope)
obj)) (address-of segment))
obj)))
(defmulti serialize-into (defmulti serialize-into
"Writes a serialized version of the `obj` to the given `segment`. "Writes a serialized version of the `obj` to the given `segment`.
@ -419,10 +420,11 @@
(defmethod deserialize* ::pointer (defmethod deserialize* ::pointer
[addr type] [addr type]
(if (sequential? type) (when-not (null? addr)
(deserialize (slice-global addr (size-of (second type))) (if (sequential? type)
(second type)) (deserialize-from (slice-global addr (size-of (second type)))
addr)) (second type))
addr)))
(defn deserialize (defn deserialize
"Deserializes an arbitrary type. "Deserializes an arbitrary type.
@ -445,11 +447,14 @@
(defmethod serialize* ::c-string (defmethod serialize* ::c-string
[obj _type scope] [obj _type scope]
(address-of (CLinker/toCString (str obj) ^ResourceScope scope))) (if obj
(address-of (CLinker/toCString (str obj) ^ResourceScope scope))
(MemoryAddress/NULL)))
(defmethod deserialize* ::c-string (defmethod deserialize* ::c-string
[addr _type] [addr _type]
(CLinker/toJavaString ^MemoryAddress addr)) (when-not (null? addr)
(CLinker/toJavaString ^MemoryAddress addr)))
#_(defn seq-of #_(defn seq-of
"Constructs a lazy sequence of `type` elements deserialized from `segment`." "Constructs a lazy sequence of `type` elements deserialized from `segment`."