home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / lisp / 3219 < prev    next >
Encoding:
Text File  |  1993-01-09  |  2.5 KB  |  95 lines

  1. Newsgroups: comp.lang.lisp
  2. Path: sparky!uunet!think.com!rpi!batcomputer!cornell!raman
  3. From: raman@cs.cornell.edu (T. V. Raman)
  4. Subject: Weird foreign function interface problem:
  5. Message-ID: <1993Jan9.180146.29819@cs.cornell.edu>
  6. Summary: Weird error from Lucid:
  7. Keywords: Foreign functions C Lucid open
  8. Organization: Cornell Univ. CS Dept, Ithaca NY 14853
  9. Date: Sat, 9 Jan 1993 18:01:46 GMT
  10. Lines: 83
  11.  
  12.  
  13.  
  14. I am having a weird problem with the foreign function interface in
  15. Lucid.
  16.  
  17. I have a C function playnotes
  18. Synopsis:
  19.  
  20. playnotes(volume, length, tone, decay, octave)
  21.     int             tone, length;
  22.     float           volume, decay;
  23.     char            octave[];
  24.  
  25.  
  26. Using the lcl:def-foreign-function I have defined:
  27.  
  28. (lcl:def-foreign-function (play-notes-internal (:name "_playnotes")
  29.                         (:return-type :signed-32bit))
  30.     (volume :double-float)
  31.   (length :signed-32bit )
  32.   (tone :signed-32bit)
  33.   (decay :double-float)
  34.               (octave  :pointer :character)
  35.               )
  36.  
  37.  
  38. The function works as expected.
  39.  
  40. However if the audio device is busy, I get a segmentation fault from
  41. lucid, even though the C function opens the audio device as
  42.  
  43.     f = open("/dev/audio", O_WRONLY);
  44.     if (f < 0) {
  45.       fprintf(stderr, "Within playnotes:%s  \n", progname);
  46.       fprintf(stderr, "%s: Cannot open /dev/audio \n", progname);
  47.       exit(1);
  48.     }
  49.  
  50. which blocks until the device becomes available when called from a C
  51. program.
  52.  
  53. Thus if I write a C program `notes' which calls the above playnotes function,
  54. from one window do
  55. cat > /dev/audio
  56. and from another window call the C program   `notes'
  57. then `notes' waits until the cat closes the /dev/audio and then plays the
  58. specified note.
  59.  
  60. However if I try the same thing but with the lucid function instead of
  61. the C `notes' ie:
  62.  
  63. From one window do
  64. cat > /dev/audio
  65. and in another window do
  66.  
  67. (play-notes ...)
  68. Then I get the error:
  69.  
  70. USER> (play-notes :length 5 :decay 0.09 :volume 100.0)
  71. >>Trap: Interrupt: segmentation violation
  72.  
  73. PLAY-NOTES-INTERNAL:
  74.    Required arg 0 (VOLUME): 100.0
  75.    Required arg 1 (LENGTH): 5
  76.    Required arg 2 (TONE): 0
  77.    Required arg 3 (DECAY): 0.09
  78.    Required arg 4 (OCTAVE): #<Foreign-Pointer 7E5AA8 (:POINTER :CHARACTER)>
  79. :A  0: Abort to Lisp Top Level
  80.  
  81.  
  82. ;;; Note: play-notes just calls play-notes-internal with default
  83. values
  84.  
  85. So where is the bug?
  86.  
  87. Thanks for the help,
  88.  
  89. --Raman
  90. -- 
  91.    T. V. Raman <raman@cs.cornell.edu>Tel: (607)255-9202  R 272-3649
  92.                        Office: 4116 Upson Hall,
  93. Department of Computer Science, Cornell University Ithaca NY 14853-6201
  94.                 Res: 226 Bryant Avenue Ithaca NY 14850
  95.