From b3756311c6f6f8f0b7223dd5ff1c9b18d1c8f0eb Mon Sep 17 00:00:00 2001 From: Vitaly Mayatskikh Date: Wed, 6 Oct 2010 00:14:06 +0200 Subject: [PATCH] There's no need to mess with null-terminated strings. --- zeromq-api.lisp | 17 +++++------------ zeromq.asd | 2 +- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/zeromq-api.lisp b/zeromq-api.lisp index 0b331d2..2b407bc 100644 --- a/zeromq-api.lisp +++ b/zeromq-api.lisp @@ -17,7 +17,7 @@ ;; 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 (start 0) end) + (start 0) end) "Allocate a foreign string containing Lisp string STRING. The string must be freed with FOREIGN-STRING-FREE." (check-type string string) @@ -26,20 +26,14 @@ The string must be freed with FOREIGN-STRING-FREE." (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))) + (ptr (funcall alloc-fn count))) (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)))) + (values ptr count)))) (defclass msg () ((raw :accessor msg-raw :initform nil))) -(defmethod initialize-instance :after ((inst msg) &key size data null-terminated-p) +(defmethod initialize-instance :after ((inst msg) &key size data) (let ((obj (foreign-alloc 'msg))) (tg:finalize inst (lambda () (%msg-close obj) @@ -50,8 +44,7 @@ The string must be freed with FOREIGN-STRING-FREE." (string (copy-lisp-string-octets data (lambda (sz) (%msg-init-size obj sz) - (%msg-data obj)) - :null-terminated-p null-terminated-p)) + (%msg-data obj)))) ((simple-array (unsigned-byte 8)) (let ((len (length data))) (%msg-init-size obj len) diff --git a/zeromq.asd b/zeromq.asd index 1ec9dfd..0fdcc77 100644 --- a/zeromq.asd +++ b/zeromq.asd @@ -10,7 +10,7 @@ (asdf:defsystem zeromq :name "zeromq" - :version "0.1.3" + :version "0.1.4" :author "Vitaly Mayatskikh " :licence "LGPLv3" :description "Zero MQ 2 bindings" -- 2.11.4.GIT