Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault from subscriber defined in dotimes #579

Open
pazeshun opened this issue Sep 20, 2018 · 4 comments
Open

Segmentation fault from subscriber defined in dotimes #579

pazeshun opened this issue Sep 20, 2018 · 4 comments
Labels

Comments

@pazeshun
Copy link

pazeshun commented Sep 20, 2018

I want to define multiple subscribers by dotimes, but that trial failed with segmentation fault.
Here is the simple sample code:

(ros::roseus "test" :anonymous nil)
(ros::roseus-add-msgs "std_msgs")

(setq test-list (list 1 2))
(setq topics (list "~test1" "~test2"))
(dotimes (i (length test-list))
  (ros::subscribe (elt topics i) std_msgs::Bool
                  #'(lambda (a msg) (print (elt test-list a))) i 1))
(ros::spin)

When I published to /test/test1 or /test/test2, segmentation fault occurs.
Debugging with @Affonso-Gui found the following code also occurs segmentation fault:

(ros::roseus "test" :anonymous nil)
(ros::roseus-add-msgs "std_msgs")

(setq var 0)
(let (b)
  (ros::subscribe "~test" std_msgs::Bool
                  #'(lambda (msg) (print var))))
(ros::spin)

When we erase local variable b, add one more argument to lambda fuction, or don't use global variable var, segmentation fault doesn't occur.

@pazeshun pazeshun added the bug label Sep 20, 2018
@pazeshun
Copy link
Author

We found dotimes problem comes from let by expanding macro:

4.irteusgl$ macroexpand '(dotimes (i 1) (print 1))
(let ((i 0) (#:dotimes355 1)) (declare (integer i #:dotimes355)) (while (< i #:dotimes355) (print 1) (setq i (1+ i))) nil)
5.irteusgl$ pprint *
(let
   ((i 0) (#:dotimes355 1))
   (declare (integer i #:dotimes355))
   (while (< i #:dotimes355) (print 1) (setq i (1+ i)))
   nil)
nil

@furushchev
Copy link
Member

It looks like this is related to some of the existing issues:
#251
#324

This problem is originated from the limitation of euslisp: a closure is unsupported.

As seen in the link below, lambda function in let scope is defined differently from it in global scope.
#324 (comment)

In the example you mentioned, this problem can be avoided by changing codes like below for example:

(ros::roseus "test" :anonymous nil)

(setq test-list (list 1 2))
(setq topics (list "~test1" "~test2"))
(dotimes (i (length test-list))
  (ros::subscribe (elt topics i) std_msgs::Bool
    `(lambda-closure () 0 0 (a msg) (print (elt test-list a))) i 1))
(ros::spin)

@k-okada
Copy link
Member

k-okada commented Sep 20, 2018

related to euslisp/EusLisp#147 (comment) ?

@pazeshun
Copy link
Author

related to euslisp/EusLisp#147 (comment) ?

I think so. This issue comes from the known issue.
The main point of this issue becomes an alert of implicit let inclusion like dotimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants