bugnyacc parser generator - Bugs: bug #57949, function pointer in struct

 
 

bug #57949: function pointer in struct

Submitter:  None
Submitted:  Tue 03 Mar 2020 04:27:27 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  mwette
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 30 May 2022 02:40:29 PM UTC, comment #3: 

see examples/ffi/bug57949.ffi in 1.07

Matt Wette <mwette>
Group administrator
Tue 05 Apr 2022 07:35:14 PM UTC, comment #2: 

I've made progress on this: see dev-1.07 branch,
commit cef6ceacdfd5f6f1ce60eca61626b39b83b0a422

For your example it produces:

(define-public struct-foo-desc
  (bs:struct
    (list `(bar ,(fh:function 'void (list 'void))))))
(define-fh-compound-type struct-foo struct-foo-desc struct-foo?
 make-struct-foo)
(export struct-foo struct-foo? make-struct-foo)
(define-public struct-foo*-desc
  (fh:pointer struct-foo-desc))
(define-fh-pointer-type struct-foo* struct-foo*-desc struct-foo*?
 make-struct-foo*)
(export struct-foo* struct-foo*? make-struct-foo*)
(fh-ref<=>deref!
  struct-foo*
  make-struct-foo*
  struct-foo
  make-struct-foo)

Matt Wette <mwette>
Group administrator
Wed 04 Mar 2020 01:06:16 AM UTC, comment #1: 

Normally objects returned from function calls are wrapped w/ FH types, but hi this case I would have to wrap fh-object-ref results somehow.   That would be useful but eat memory.   Not a trivial task.   I need to think about this a bit.

Matt Wette <mwette>
Group administrator
Tue 03 Mar 2020 04:27:27 PM UTC, original submission:  

Example:


struct foo
{
        void bar(void);
};


Processing the above C code with compile-ffi produces the following Scheme code:


;; struct foo {
;;   void bar(void);
;; };
(define-public struct-foo-desc
  (bs:struct (list `(bar ,(bs:pointer 'void)))))
(define-fh-compound-type struct-foo struct-foo-desc struct-foo?
 make-struct-foo)
(export struct-foo struct-foo? make-struct-foo)
(define-public struct-foo*-desc
  (bs:pointer struct-foo-desc))
(define-fh-pointer-type struct-foo* struct-foo*-desc struct-foo*?
 make-struct-foo*)
(export struct-foo* struct-foo*? make-struct-foo*)
(ref<->deref!
  struct-foo*
  make-struct-foo*
  struct-foo
  make-struct-foo)


AFAICT bar's type information is not included in the Scheme code, so there's no way to call bar from Scheme short of taking bar's address (as returned by fh-object-ref) and converting it using pointer->procedure. It would be great if fh-object-ref would return a procedure that calls bar in this case.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mwette (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-05-30 mwette StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2022-04-05 mwette StatusNone In Progress
    2020-03-04 mwette Assigned toNone mwette

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code