nnicandro / emacs-zmq

Emacs bindings to ØMQ
GNU General Public License v2.0
49 stars 18 forks source link

Return NULL for nil object in ezmq_extract_obj #34

Closed shwina closed 3 years ago

shwina commented 3 years ago

ezmq_extract_obj fails when the object can be nil.

For example, when ezmq_proxy is invoked without a third argument, or equivalently, with nil as its third argument, as in (zmq-proxy frontend backend nil), we get:

Debugger entered--Lisp error: (wrong-type-argument user-ptrp nil)
  zmq-proxy(#<user-ptr ptr=0x100d44e80 finalizer=0x101b6ef30> #<user-ptr ptr=0x101a34610 finalizer=0x101b6ef30> nil)
  (let* ((context (zmq-context)) (frontend (zmq-socket context zmq-ROUTER)) (backend (zmq-socket context zmq-DEALER))) (zmq-bind frontend "tcp://*:5559") (zmq-bind backend "tcp://*:5560") (zmq-proxy frontend backend nil))
  eval-buffer(#<buffer  *load*> nil "/Users/ashwin/workspace/github/shwina/emacs-zmq-examples/extended-request-reply/broker.el" nil t)  ; Reading at buffer position 317
  load-with-code-conversion("/Users/ashwin/workspace/github/shwina/emacs-zmq-examples/extended-request-reply/broker.el" "/Users/ashwin/workspace/github/shwina/emacs-zmq-examples/extended-request-reply/broker.el" nil t)
  load("/Users/ashwin/workspace/github/shwina/emacs-zmq-examples/extended-request-reply/broker.el" nil t t)
  command-line-1(("-scriptload" "broker.el"))
  command-line()
  normal-top-level()

This PR makes it so that ezmq_extract_obj returns NULL when the Lisp object is nil.

nnicandro commented 3 years ago

Making this change would affect the semantics of the EZMQ_EXTRACT_OBJ macro which expects an error to be raised by ezmq_extract_obj if the val argument is nil or not a valid ZMQ object type.

I've gone ahead and fixed the issue in 38dc6c4119aee57666caf8f97c8a3d7f678823e0. Thanks for the pull request.

shwina commented 3 years ago

Thanks!