Skip to content

Segmentation fault occurs in funcall-ing a lambda-closure, when a function sets itself as the lambda-closure inside #463

Open
@knorth55

Description

@knorth55

when a function (spam1) sets itself as a lambda-closure inside (setq *spam-func* #'spam1),
segmentation fault occurs in funcall (funcall *spam-func* (list 1))

test code: https://gist.github.com/knorth55/5f0e02f8c0103323d51d04aea482f57a#file-spam-l

Funcall case

#'spam : segmentation fault

(defun spam1 (x)
  (setq *spam-func* #'spam1)
  (format t "spam1: ~A ~%" x)
  (unix::sleep 1))


;; segmentation fault
(spam1 0)
(print *spam-func*)
(funcall *spam-func* 1)
$ eus spam.l
configuring by "/home/shingo/install/jskeus/eus/lib/eusrt.l"
;; readmacro ;; object ;; packsym ;; common ;; constants ;; stream ;; string ;; loader ;; pprint ;; process ;; hashtab ;; array ;; mathtran ;; eusdebug ;; eusforeign ;; extnum ;; coordinates ;; tty ;; history ;; toplevel ;; trans ;; comp ;; builtins ;; par ;; helpsub ;; eushelp ;; fstringdouble 
EusLisp 9.27(b5be4c1) for Linux64 created on ecublens(Fri Nov 6 17:37:52 JST 2020)
spam1: 0 
(lambda-closure spam1 15975616 0 (x) (setq *spam-func* #'spam1) (format t "spam1: ~A ~%" x) (unix:sleep 1))
;; Segmentation Fault.
;; in (setq *spam-func* #'spam1)
;; You are still in a signal handler.
;;Try reset or throw to upper level as soon as possible.
;; code=-916475408 x=c95fb0c0 addr=4
Fatal: 

#'(lambda (x) (spam x)): OK

When we use (setq *spam-func* #'(lambda (x) (spam2 x))), we can avoid the segmentation fault.

(defun spam2 (x)
  (setq *spam-func* #'(lambda (xx) (spam2 xx)))
  (format t "spam2: ~A ~%" x)
  (unix::sleep 1))


;; OK
(spam2 0)
(print *spam-func*)
(funcall *spam-func* 1)
$ roseus spam.l 
configuring by "/home/shingo/install/jskeus/eus/lib/eusrt.l"
;; readmacro ;; object ;; packsym ;; common ;; constants ;; stream ;; string ;; loader ;; pprint ;; process ;; hashtab ;; array ;; mathtran ;; eusdebug ;; eusforeign ;; extnum ;; coordinates ;; tty ;; history ;; toplevel ;; trans ;; comp ;; builtins ;; par ;; intersection ;; geoclasses ;; geopack ;; geobody ;; primt ;; compose ;; polygon ;; viewing ;; viewport ;; viewsurface ;; hid ;; shadow ;; bodyrel ;; dda ;; helpsub ;; eushelp ;; xforeign ;; Xdecl ;; Xgraphics ;; Xcolor ;; Xeus ;; Xevent ;; Xpanel ;; Xitem ;; Xtext ;; Xmenu ;; Xscroll ;; Xcanvas ;; Xtop ;; Xapplwin 
connected to Xserver DISPLAY=:0
X events are being asynchronously monitored.
;; pixword ;; RGBHLS ;; convolve ;; piximage ;; pbmfile ;; image_correlation ;; oglforeign ;; gldecl ;; glconst ;; glforeign ;; gluconst ;; gluforeign ;; glxconst ;; glxforeign ;; eglforeign ;; eglfunc ;; glutil ;; gltexture ;; glprim ;; gleus ;; glview ;; toiv-undefined ;; fstringdouble irtmath irtutil irtc irtgeoc irtgraph ___time ___pgsql irtgeo euspqp pqp irtscene irtmodel irtdyna irtrobot irtsensor irtbvh irtcollada irtstl irtwrl irtpointcloud eusbullet bullet irtcollision irtx eusjpeg euspng png irtimage irtglrgb 
;; extending gcstack 0x61ae650[16374] --> 0x6638e90[32748] top=3c53
irtgl irtglc irtviewer 
EusLisp 9.27(b5be4c1 80d69c9) for Linux64 created on ecublens(Fri Nov 6 17:37:52 JST 2020)
roseus ;; loading roseus("1.7.4-97-gb214284") on euslisp((9.27 ecublens Fri Nov 6 17:37:52 JST 2020 b5be4c1 80d69c9))
eustf roseus_c_util spam2: 0 
(lambda-closure nil 35317752 0 (x) (spam2 x))
spam2: 1 

Apply

#'spam : segmentation fault

(defun spam1 (x)
  (setq *spam-func* #'spam1)
  (format t "spam1: ~A ~%" x)
  (unix::sleep 1))

;; segmentation fault
(spam1 0)
(print *spam-func*)
(apply *spam-func* (list 1))
$ eus spam.l
configuring by "/home/shingo/install/jskeus/eus/lib/eusrt.l"
;; readmacro ;; object ;; packsym ;; common ;; constants ;; stream ;; string ;; loader ;; pprint ;; process ;; hashtab ;; array ;; mathtran ;; eusdebug ;; eusforeign ;; extnum ;; coordinates ;; tty ;; history ;; toplevel ;; trans ;; comp ;; builtins ;; par ;; helpsub ;; eushelp ;; fstringdouble 
EusLisp 9.27(b5be4c1) for Linux64 created on ecublens(Fri Nov 6 17:37:52 JST 2020)
spam1: 0 
(lambda-closure spam1 32879808 0 (x) (setq *spam-func* #'spam1) (format t "spam1: ~A ~%" x) (unix:sleep 1))
;; Segmentation Fault.
;; in (apply *spam-func* (list 1))
;; You are still in a signal handler.
;;Try reset or throw to upper level as soon as possible.
;; code=372082800 x=162d8740 addr=1f5b4c0
Fatal: 

#'(lambda (x) (spam x)) : segmentation fault

(defun spam2 (x)
  (setq *spam-func* #'(lambda (xx) (spam2 xx)))
  (format t "spam2: ~A ~%" x)
  (unix::sleep 1))

;; segmentation fault
(spam2 0)
(print *spam-func*)
(apply *spam-func* (list 1))
$ eus spam.l
configuring by "/home/shingo/install/jskeus/eus/lib/eusrt.l"
;; readmacro ;; object ;; packsym ;; common ;; constants ;; stream ;; string ;; loader ;; pprint ;; process ;; hashtab ;; array ;; mathtran ;; eusdebug ;; eusforeign ;; extnum ;; coordinates ;; tty ;; history ;; toplevel ;; trans ;; comp ;; builtins ;; par ;; helpsub ;; eushelp ;; fstringdouble 
EusLisp 9.27(b5be4c1) for Linux64 created on ecublens(Fri Nov 6 17:37:52 JST 2020)
spam2: 0 
(lambda-closure nil 9147584 0 (xx) (spam2 xx))
;; Segmentation Fault.
;; in (apply *spam-func* (list 1))
;; You are still in a signal handler.
;;Try reset or throw to upper level as soon as possible.
;; code=-584781136 x=dd24f180 addr=8b94c0
Fatal: 

#'spam-test: segmentation fault

(defun spam3-test (xx)
  (format t "spam3-test: ~A ~%" xx)
  (unix::sleep 1))

(defun spam3 (x)
  (setq *spam-func* #'spam3-test)
  (format t "spam3: ~A ~%" x)
  (unix::sleep 1))

;; segmentation fault
(spam3 0)
(print *spam-func*)
(apply *spam-func* (list 1))
$ eus spam.l
configuring by "/home/shingo/install/jskeus/eus/lib/eusrt.l"
;; readmacro ;; object ;; packsym ;; common ;; constants ;; stream ;; string ;; loader ;; pprint ;; process ;; hashtab ;; array ;; mathtran ;; eusdebug ;; eusforeign ;; extnum ;; coordinates ;; tty ;; history ;; toplevel ;; trans ;; comp ;; builtins ;; par ;; helpsub ;; eushelp ;; fstringdouble 
EusLisp 9.27(b5be4c1) for Linux64 created on ecublens(Fri Nov 6 17:37:52 JST 2020)
spam3: 0 
(lambda-closure spam3-test 10745024 0 (xx) (format t "spam3-test: ~A ~%" xx) (unix:sleep 1))
;; Segmentation Fault.
;; in (apply *spam-func* (list 1))
;; You are still in a signal handler.
;;Try reset or throw to upper level as soon as possible.
;; code=1339940976 x=4fdddf40 addr=a3f4c0
Fatal: 

#'(lambda (x) (spam-test x)): segmentation fault

(defun spam4-test (xx)
  (format t "spam3-test: ~A ~%" xx)
  (unix::sleep 1))

(defun spam4 (x)
  (setq *spam-func* #'(lambda (xx) (spam4-test xx)))
  (format t "spam4: ~A ~%" x)
  (unix::sleep 1))

;; segmentation fault
(spam4 0)
(print *spam-func*)
(apply *spam-func* (list 1))
$ eus spam.l
configuring by "/home/shingo/install/jskeus/eus/lib/eusrt.l"
;; readmacro ;; object ;; packsym ;; common ;; constants ;; stream ;; string ;; loader ;; pprint ;; process ;; hashtab ;; array ;; mathtran ;; eusdebug ;; eusforeign ;; extnum ;; coordinates ;; tty ;; history ;; toplevel ;; trans ;; comp ;; builtins ;; par ;; helpsub ;; eushelp ;; fstringdouble 
EusLisp 9.27(b5be4c1) for Linux64 created on ecublens(Fri Nov 6 17:37:52 JST 2020)
spam4: 0 
(lambda-closure nil 17814720 0 (xx) (spam4-test xx))
;; Segmentation Fault.
;; in (apply *spam-func* (list 1))
;; You are still in a signal handler.
;;Try reset or throw to upper level as soon as possible.
;; code=693430448 x=2954e780 addr=10fd4c0
Fatal: 

#'(lambda (xx) (format t "spam5-lambda: ~A ~%" xx) : segmentation fault

(defun spam5 (x)
  (setq *spam-func*
        #'(lambda (xx)
            (format t "spam5-lambda: ~A ~%" xx)))
  (format t "spam5: ~A ~%" x)
  (unix::sleep 1))

;; segmentation fault
(spam5 0)
(print *spam-func*)
(apply *spam-func* (list 1))
$ eus spam.l
configuring by "/home/shingo/install/jskeus/eus/lib/eusrt.l"
;; readmacro ;; object ;; packsym ;; common ;; constants ;; stream ;; string ;; loader ;; pprint ;; process ;; hashtab ;; array ;; mathtran ;; eusdebug ;; eusforeign ;; extnum ;; coordinates ;; tty ;; history ;; toplevel ;; trans ;; comp ;; builtins ;; par ;; helpsub ;; eushelp ;; fstringdouble 
EusLisp 9.27(b5be4c1) for Linux64 created on ecublens(Fri Nov 6 17:37:52 JST 2020)
spam5: 0 
(lambda-closure nil 31184064 0 (xx) (format t "spam5-lambda: ~A ~%" xx))
;; Segmentation Fault.
;; in (apply *spam-func* (list 1))
;; You are still in a signal handler.
;;Try reset or throw to upper level as soon as possible.
;; code=2103082992 x=7d5a7ec0 addr=1dbd4c0
Fatal: 

`(lambda-closure nil 0 0 (xx) (format t "spam6-lambda: ~A ~%" xx)) : OK

(defun spam6 (x)
  (setq *spam-func*
        `(lambda-closure nil 0 0 (xx)
                         (format t "spam6-lambda: ~A ~%" xx)))
  (format t "spam6: ~A ~%" x)
  (unix::sleep 1))

;; OK 
(spam6 0)
(print *spam-func*)
(apply *spam-func* (list 1))
$ eus spam.l 
configuring by "/home/shingo/install/jskeus/eus/lib/eusrt.l"
;; readmacro ;; object ;; packsym ;; common ;; constants ;; stream ;; string ;; loader ;; pprint ;; process ;; hashtab ;; array ;; mathtran ;; eusdebug ;; eusforeign ;; extnum ;; coordinates ;; tty ;; history ;; toplevel ;; trans ;; comp ;; builtins ;; par ;; helpsub ;; eushelp ;; fstringdouble 
EusLisp 9.27(b5be4c1) for Linux64 created on ecublens(Fri Nov 6 17:37:52 JST 2020)
spam6: 0 
(lambda-closure nil 0 0 (xx) (format t "spam6-lambda: ~A ~%" xx))
spam6-lambda: 1 
1.eus$ 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions