mainnyacc parser generator - Support: sr #111073, Cannot fh-object-set! on function...

 
 

sr #111073: Cannot fh-object-set! on function pointer

Submitter:  Felix Lechner <lechner>
Submitted:  Mon 10 Jun 2024 01:48:50 AM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  None
Privacy:  Public Assigned to:  mwette
Open/Closed:  Open Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 15 Jun 2024 02:57:12 AM UTC, comment #6: 

THanks.  I am going to revert to using (system ffi-help-rt).
I'm going to remove the (ffi ffi-help-rt) one.

matt

Matt Wette <mwette>
Group administrator
Sat 15 Jun 2024 01:00:48 AM UTC, comment #5: 

Also, did the location of ffi-help-rt.scm change from (system ffi-help-rt) to (ffi ffi-help-rt)?  This is confusing from several angles:

  1. The branch dev-1.10 has similar files in both locations.
  2. The file in the old location (system ffi-help-rt) is version 1.09.4
  3. The file in the new location (ffi ffi-help-rt) is version 1.08.1
  4. Both modules have names in 'define-module' that match their location but nearly identical contents
  5. module/Makefile.in installs the old version in (ffi ffi-help-rt) but not the new version in (system ffi-help-rt)


The result is that my package definition does not actually contain the new version in (system ffi-help-rt).

As a minor point of guidance, is it's okay if I use the 'ffi' name space, as well?  I presently ship the nyacc-generated files as (ffi pam), (ffi pamc), and (ffi pam-misc).  Thanks!

Felix Lechner <lechner>
Fri 14 Jun 2024 10:58:02 PM UTC, comment #4: 

Hi Matt,

Thanks for the fix!  Grabbing ff-help-rt.scm seemed to have been enough.

Now the following code fails, however:


(define (get-username handle)
  (let* ((username-pointer (make-char*)))
    (pam_get_item handle
                  (ffi-pam-symbol-val 'PAM_USER)
                  (pointer-to username-pointer))
    (char*->string username-pointer)))


The error occurs in the call to char*->string:


ERROR: In procedure pointer->string:
In procedure pointer->string: Wrong type argument in position 1 (expecting POINTER_P): 8489776


There is now a bytestructure, but I have not found a way to look inside.  It is opaque to me.

I also see an exception while printing the backtrace, but do not know what that means, either.  Thanks!


Backtrace:
          13 (primitive-load "/lcl/lechner/pam/guile-pam/test/load")
In ice-9/eval.scm:
    619:8 12 (_ #(#(#(#(#<directory (guile-user) 7fd995f24?>) ?) ?) ?))
In unknown file:
          11 (_ #<procedure 7fd9909d7d00 at ice-9/eval.scm:330:13 ()> ?)
In ice-9/eval.scm:
   293:34 10 (_ #(#(#(#(#(#(#<directory (guile-user)?>) ?) ?) ?) ?) ?))
   293:34  9 (_ #(#(#(#(#(#(#(#<directory (pam le?>) ?) ?) ?) ?) ?) ?))
In unknown file:
Exception thrown while printing backtrace:
In procedure primitive-call-ip: Wrong type argument in position 1 (expecting PRIMITIVE_P): #<procedure 7fd9909c1600 (_ _ _ _)>


Felix Lechner <lechner>
Fri 14 Jun 2024 02:18:17 PM UTC, comment #3: 

oops. grabbing system/ffi-help-rt.scm may be enough, but not sure

Matt Wette <mwette>
Group administrator
Fri 14 Jun 2024 02:17:27 PM UTC, comment #2: 

1.10 is available on the dev-1.10 branch

Matt Wette <mwette>
Group administrator
Fri 14 Jun 2024 02:12:20 PM UTC, comment #1: 

Does not generate an error in yet-to-be-released 1.10
(use-modules (system ffi-help-rt))
(use-modules (bytestructures guile))
(use-modules ((system foreign) #:prefix ffi:))


(define foo-desc
  (bs:struct
   (list `(conv ,(fh:function
                  int
                  (list int
                        (fh:pointer (fh:pointer 'void))
                        (fh:pointer (fh:pointer 'void))
                        (fh:pointer 'void))))
         `(appdata_ptr ,(fh:pointer 'void)))))

(define-fh-compound-type foo foo-desc foo? make-foo)

(define ptr
  (ffi:procedure->pointer
   ffi:int
   (lambda (num_msg pam_message pam_response appdata_ptr)
     (format #t "Number of messages ~s~%" num_msg))
   (list ffi:int '* '* '*)))

(define conversation
  (let* ((conv (make-foo)))
    (fh-object-set! conv 'conv ptr)
    conv))

scheme@(guile-user)> conversation
$1 = #<foo 0x77f6f08a53b0>
scheme@(guile-user)> (fh-object-ref conversation 'conv)
$2 = #<procedure 77f6ea6112e0 ( _ _)>

Matt Wette <mwette>
Group administrator
Mon 10 Jun 2024 01:48:50 AM UTC, original submission:  

Hi,

With this definition generated by the FFI Helper:

  (bs:struct
    (list `(conv ,(fh:function
                    int
                    (list int
                          (fh:pointer (fh:pointer 'void))
                          (fh:pointer (fh:pointer 'void))
                          (fh:pointer 'void))))
          `(appdata_ptr ,(fh:pointer 'void))))

I am unable to set the 'conv component with this code:

         (ptr (procedure->pointer int
                                  (lambda (num_msg pam_message pam_response appdata_ptr)
                                    (format #t "Number of messages ~s~%" num_msg))
                                  (list int '* '* '*)))
         (conversation (let* ((conv (make-struct-pam_conv)))
                         (fh-object-set! conv 'conv ptr)
                         conv))

The code produces this error message:

bytestructures/body/base.scm:155:12: In procedure bytestructure-primitive-set!:
Cannot write value with this bytestructure descriptor. #<pointer 0x7fcc41a79fe0> #<bytestructure-descriptor 0x7fcc41614300>

What am I doing wrong, please? Thanks!

Felix Lechner <lechner>

 

(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)
  • -email is unavailable- added by lechner (Submitted the item)
  •  

    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.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-06-14 mwette Assigned toNone mwette

    Back to the top

    Powered by Savane 3.14-04e1.
    Corresponding source code