Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
1924cba8
Commit
1924cba8
authored
Dec 18, 2009
by
Martin Sustrik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
memory management in Lisp binding fixed
parent
86d68cbc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
18 deletions
+41
-18
zeromq-api.lisp
bindings/cl/zeromq-api.lisp
+41
-18
No files found.
bindings/cl/zeromq-api.lisp
View file @
1924cba8
...
...
@@ -17,28 +17,51 @@
(
in-package
:zeromq
)
;; Stolen from CFFI. Uses custom allocator (alloc-fn) instead of foreign-alloc
(
defun
copy-lisp-string-octets
(
string
alloc-fn
&key
(
encoding
cffi::*default-foreign-encoding*
)
(
null-terminated-p
t
)
(
start
0
)
end
)
"Allocate a foreign string containing Lisp string STRING.
The string must be freed with FOREIGN-STRING-FREE."
(
check-type
string
string
)
(
cffi::with-checked-simple-vector
((
string
(
coerce
string
'babel:unicode-string
))
(
start
start
)
(
end
end
))
(
declare
(
type
simple-string
string
))
(
let*
((
mapping
(
cffi::lookup-mapping
cffi::*foreign-string-mappings*
encoding
))
(
count
(
funcall
(
cffi::octet-counter
mapping
)
string
start
end
0
))
(
length
(
if
null-terminated-p
(
+
count
(
cffi::null-terminator-len
encoding
))
count
))
(
ptr
(
funcall
alloc-fn
length
)))
(
funcall
(
cffi::encoder
mapping
)
string
start
end
ptr
0
)
(
when
null-terminated-p
(
dotimes
(
i
(
cffi::null-terminator-len
encoding
))
(
setf
(
mem-ref
ptr
:char
(
+
count
i
))
0
)))
(
values
ptr
length
))))
(
defclass
msg
()
((
raw
:accessor
msg-raw
:initform
nil
)
(
shared
:accessor
msg-shared
:initform
0
:initarg
:shared
)))
((
raw
:accessor
msg-raw
:initform
nil
)))
(
defmethod
initialize-instance
:after
((
inst
msg
)
&key
size
data
)
(
let
((
obj
(
foreign-alloc
'msg
)))
(
with-slots
(
raw
shared
)
inst
(
setf
raw
obj
)
(
tg:finalize
inst
(
lambda
()
(
%msg-close
raw
)
(
foreign-free
raw
)))
(
when
shared
(
setf
(
foreign-slot-value
obj
'msg
'shared
)
(
if
shared
1
0
)))
(
cond
(
size
(
%msg-init-size
raw
size
))
(
data
(
multiple-value-bind
(
ptr
len
)
(
etypecase
data
(
string
(
foreign-string-alloc
data
))
(
array
(
values
(
foreign-alloc
:uchar
:initial-contents
data
)
(
length
data
))))
(
msg-init-data
raw
ptr
len
(
callback
zmq-free
))))
(
t
(
msg-init
raw
))))))
(
tg:finalize
inst
(
lambda
()
(
%msg-close
obj
)
(
foreign-free
obj
)))
(
cond
(
size
(
%msg-init-size
obj
size
))
(
data
(
etypecase
data
(
string
(
copy-lisp-string-octets
data
(
lambda
(
sz
)
(
%msg-init-size
obj
sz
)
(
%msg-data
obj
))))
(
array
(
progn
(
%msg-init-size
obj
(
length
data
))
(
let
((
ptr
(
%msg-data
obj
))
(
i
-1
))
(
map
nil
(
lambda
(
x
)
(
setf
(
mem-aref
ptr
:uchar
(
incf
i
))
x
))
data
))))))
(
t
(
msg-init
obj
)))
(
setf
(
msg-raw
inst
)
obj
)))
(
defclass
pollitem
()
((
raw
:accessor
pollitem-raw
:initform
nil
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment