* type friction C <-> scheme
@ 2017-06-09 20:36 Catonano
2017-06-09 20:52 ` Mike Gran
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Catonano @ 2017-06-09 20:36 UTC (permalink / raw)
To: guile-user
Here we go again
After successfully wrapping freexl_open, I can't do the same with
freexl_get_info
One of the arguments expected by such function is "unsigned short"
When I load the namespace at the REPL I get
scheme@(guile-user)> ,m (freexl common)
While executing meta-command:
ERROR: In procedure pointer->procedure: Wrong type argument in position 3:
int
I tried with uint8, uint16 and uint32, with the same result
Here's the function I'm referring to
https://www.gaia-gis.it/gaia-sins/freexl-1.0.1-doxy-doc/html/freexl_8h.html#ad6dbe072c7a4632853d90f4509bf3aee
And here's my code (there are some instructions as comments in the code)
https://gitlab.com/humanitiesNerd/guile-freexl
And here's an excerpt
(define freexl-get-info
(let* ((ptr (freexl-func "freexl_get_info"))
(proc (pointer->procedure int ptr '(* int *)))
;;the int in the arguments list generates
;;a wrong argument type error when
;;loading the namespace at the REPL, like this
;;scheme@(guile-user)> ,m (freexl common)
;;While executing meta-command:
;;ERROR: In procedure pointer->procedure: Wrong type argument
;;in position 3: int
)
(lambda (handle-ptr what)
(let* ((outcome-ptr (bytevector->pointer (make-bytevector (sizeof
'*))))
(result (proc handle-ptr what outcome-ptr)))
(if (not (= result 0))
(throw 'get-info-error 'error-code result)
outcome-ptr)
))))
Thanks in advance
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-09 20:36 type friction C <-> scheme Catonano
@ 2017-06-09 20:52 ` Mike Gran
2017-06-09 21:33 ` Catonano
2017-06-09 20:56 ` Matt Wette
2017-06-11 18:01 ` Matt Wette
2 siblings, 1 reply; 14+ messages in thread
From: Mike Gran @ 2017-06-09 20:52 UTC (permalink / raw)
To: Catonano, guile-user
On Fri, Jun 09, 2017 at 10:36:45PM +0200, Catonano wrote:
> Here we go again
> And here's an excerpt
>
> (define freexl-get-info
> (let* ((ptr (freexl-func "freexl_get_info"))
> (proc (pointer->procedure int ptr '(* int *)))
It appears that when I did bindings for guile-aspell,
I used the form (list '* int '*), so that that int was
used as a syntax or variable.
https://github.com/spk121/guile-aspell/blob/master/aspell.scm#L165
Good luck,
Mike Gran
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-09 20:36 type friction C <-> scheme Catonano
2017-06-09 20:52 ` Mike Gran
@ 2017-06-09 20:56 ` Matt Wette
2017-06-09 21:39 ` Catonano
2017-06-11 18:01 ` Matt Wette
2 siblings, 1 reply; 14+ messages in thread
From: Matt Wette @ 2017-06-09 20:56 UTC (permalink / raw)
To: Catonano; +Cc: guile-user
> On Jun 9, 2017, at 1:36 PM, Catonano <catonano@gmail.com> wrote:
>
> Here we go again
>
> After successfully wrapping freexl_open, I can't do the same with
> freexl_get_info
>
> One of the arguments expected by such function is "unsigned short"
>
> When I load the namespace at the REPL I get
>
> scheme@(guile-user)> ,m (freexl common)
> While executing meta-command:
> ERROR: In procedure pointer->procedure: Wrong type argument in position 3:
> int
>
> I tried with uint8, uint16 and uint32, with the same result
>
> Here's the function I'm referring to
>
> https://www.gaia-gis.it/gaia-sins/freexl-1.0.1-doxy-doc/html/freexl_8h.html#ad6dbe072c7a4632853d90f4509bf3aee
>
> And here's my code (there are some instructions as comments in the code)
> https://gitlab.com/humanitiesNerd/guile-freexl
>
> And here's an excerpt
>
> (define freexl-get-info
> (let* ((ptr (freexl-func "freexl_get_info"))
> (proc (pointer->procedure int ptr '(* int *)))
> ;;the int in the arguments list generates
> ;;a wrong argument type error when
> ;;loading the namespace at the REPL, like this
> ;;scheme@(guile-user)> ,m (freexl common)
> ;;While executing meta-command:
> ;;ERROR: In procedure pointer->procedure: Wrong type argument
> ;;in position 3: int
>
> )
> (lambda (handle-ptr what)
> (let* ((outcome-ptr (bytevector->pointer (make-bytevector (sizeof
> '*))))
> (result (proc handle-ptr what outcome-ptr)))
> (if (not (= result 0))
> (throw 'get-info-error 'error-code result)
> outcome-ptr)
> ))))
>
> Thanks in advance
I think your outcome-ptr should be (bytevector->pointer (make-bytevector (sizeof unsigned-int)))
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-09 20:52 ` Mike Gran
@ 2017-06-09 21:33 ` Catonano
0 siblings, 0 replies; 14+ messages in thread
From: Catonano @ 2017-06-09 21:33 UTC (permalink / raw)
To: Mike Gran; +Cc: guile-user
Mike,
2017-06-09 22:52 GMT+02:00 Mike Gran <spk121@yahoo.com>:
>
> It appears that when I did bindings for guile-aspell,
> I used the form (list '* int '*), so that that int was
> used as a syntax or variable.
>
> https://github.com/spk121/guile-aspell/blob/master/aspell.scm#L165
>
>
Your suggestion eliminated that error. Thanks
Admittedly I don't fully understand the reasoning, maybe because it's late
in the night
In case I will still not understand tomorrow morning, I will write again
here
> Good luck,
>
Thank you very much !
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-09 20:56 ` Matt Wette
@ 2017-06-09 21:39 ` Catonano
2017-06-09 22:33 ` Matt Wette
0 siblings, 1 reply; 14+ messages in thread
From: Catonano @ 2017-06-09 21:39 UTC (permalink / raw)
To: Matt Wette; +Cc: guile-user
2017-06-09 22:56 GMT+02:00 Matt Wette <matt.wette@gmail.com>:
>
>
I think your outcome-ptr should be (bytevector->pointer (make-bytevector
> (sizeof unsigned-int)))
Thank you, Matt
The reason why I wrote it that way is because the previous function
(freexl_open) takes a pointer (a handler) and then more or less arbitrarily
allocates stuff onto it
The handler is meant to be passed as an argument to subsequent calls to the
other funtiions of the library
So I tought that the same would have happened with this outcome thing
Maybe I'm wrong
I'll think about this tomorrow, too
Thank you very much for your suggestion !
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-09 21:39 ` Catonano
@ 2017-06-09 22:33 ` Matt Wette
2017-06-10 6:26 ` Catonano
0 siblings, 1 reply; 14+ messages in thread
From: Matt Wette @ 2017-06-09 22:33 UTC (permalink / raw)
To: Catonano; +Cc: guile-user
> On Jun 9, 2017, at 2:39 PM, Catonano <catonano@gmail.com> wrote:
>
>
>
> 2017-06-09 22:56 GMT+02:00 Matt Wette <matt.wette@gmail.com <mailto:matt.wette@gmail.com>>:
>
> I think your outcome-ptr should be (bytevector->pointer (make-bytevector (sizeof unsigned-int)))
>
> Thank you, Matt
>
> The reason why I wrote it that way is because the previous function (freexl_open) takes a pointer (a handler) and then more or less arbitrarily allocates stuff onto it
>
> The handler is meant to be passed as an argument to subsequent calls to the other funtiions of the library
>
> So I tought that the same would have happened with this outcome thing
>
> Maybe I'm wrong
>
> I'll think about this tomorrow, too
>
> Thank you very much for your suggestion !
I think Mike caught your real error: you were passing (list ‘* ‘int ‘*) and it wants (list ‘* int ‘*). `int’ is a variable defined by guile.
scheme@(guile-user)> (use-modules (system foreign))
scheme@(guile-user)> int
$1 = 8
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-09 22:33 ` Matt Wette
@ 2017-06-10 6:26 ` Catonano
2017-06-11 5:50 ` Mark H Weaver
0 siblings, 1 reply; 14+ messages in thread
From: Catonano @ 2017-06-10 6:26 UTC (permalink / raw)
To: Matt Wette; +Cc: guile-user
2017-06-10 0:33 GMT+02:00 Matt Wette <matt.wette@gmail.com>:
I think Mike caught your real error: you were passing (list ‘* ‘int ‘*) and
> it wants (list ‘* int ‘*). `int’ is a variable defined by guile.
>
And isn't `*' a variable defined in guile too ?
>
> scheme@(guile-user)> (use-modules (system foreign))
> scheme@(guile-user)> int
> $1 = 8
>
yes, and
scheme@(freexl common)> *
$14 = #<procedure * (#:optional _ _ . _)>
I took a look at the guile-gcrypt code again
it's full of things like
'(* * ,int ,size_t *)
that is, only asterisks (pointers) are quoted
Other types are not
So this must be an established convention
It just seems unconsistent to me
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-10 6:26 ` Catonano
@ 2017-06-11 5:50 ` Mark H Weaver
2017-06-11 13:07 ` Matt Wette
2017-06-11 17:15 ` Catonano
0 siblings, 2 replies; 14+ messages in thread
From: Mark H Weaver @ 2017-06-11 5:50 UTC (permalink / raw)
To: Catonano; +Cc: guile-user, Matt Wette
Catonano <catonano@gmail.com> writes:
> 2017-06-10 0:33 GMT+02:00 Matt Wette <matt.wette@gmail.com>:
>
> I think Mike caught your real error: you were passing (list ‘* ‘int ‘*) and
>> it wants (list ‘* int ‘*). `int’ is a variable defined by guile.
>>
>
> And isn't `*' a variable defined in guile too ?
>
>
>>
>> scheme@(guile-user)> (use-modules (system foreign))
>> scheme@(guile-user)> int
>> $1 = 8
>>
>
> yes, and
>
> scheme@(freexl common)> *
> $14 = #<procedure * (#:optional _ _ . _)>
'int' is a variable exported by (system foreign) whose sole purpose is
to represent a foreign type.
'*' is something completely different, namely a procedure to multiply
numbers. IMO, it would be a nasty hack for the FFI to check
specifically for a multiplication procedure and interpret that as a
pointer type.
> I took a look at the guile-gcrypt code again
>
> it's full of things like
>
> '(* * ,int ,size_t *)
>
> that is, only asterisks (pointers) are quoted
>
> Other types are not
>
> So this must be an established convention
>
> It just seems unconsistent to me
I agree that it's inconsistent, but '* is shorter than any descriptive
variable name that we might have chosen for this purpose, and pointers
are common enough to warrant a short name.
On the other hand, if we had used symbols uniformly for all foreign
types, then it would have been impossible to bind your own type names
(e.g. for struct types) without adding a global registry of foreign
types, which would have various nasty problems such as the potential for
collisions between unrelated libraries.
Regards,
Mark
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-11 5:50 ` Mark H Weaver
@ 2017-06-11 13:07 ` Matt Wette
2017-06-11 17:15 ` Catonano
1 sibling, 0 replies; 14+ messages in thread
From: Matt Wette @ 2017-06-11 13:07 UTC (permalink / raw)
To: Mark H Weaver; +Cc: guile-user
> On Jun 10, 2017, at 10:50 PM, Mark H Weaver <mhw@netris.org> wrote:
>
> Catonano <catonano@gmail.com <mailto:catonano@gmail.com>> writes:
>
>> 2017-06-10 0:33 GMT+02:00 Matt Wette <matt.wette@gmail.com>:
>>
>> I think Mike caught your real error: you were passing (list ‘* ‘int ‘*) and
>>> it wants (list ‘* int ‘*). `int’ is a variable defined by guile.
>>>
>>
>> And isn't `*' a variable defined in guile too ?
>>
>>
>>>
>>> scheme@(guile-user)> (use-modules (system foreign))
>>> scheme@(guile-user)> int
>>> $1 = 8
>>>
>>
>> yes, and
>>
>> scheme@(freexl common)> *
>> $14 = #<procedure * (#:optional _ _ . _)>
>
> 'int' is a variable exported by (system foreign) whose sole purpose is
> to represent a foreign type.
>
> '*' is something completely different, namely a procedure to multiply
> numbers. IMO, it would be a nasty hack for the FFI to check
> specifically for a multiplication procedure and interpret that as a
> pointer type.
>
>> I took a look at the guile-gcrypt code again
>>
>> it's full of things like
>>
>> '(* * ,int ,size_t *)
>>
>> that is, only asterisks (pointers) are quoted
>>
>> Other types are not
>>
>> So this must be an established convention
>>
>> It just seems unconsistent to me
>
> I agree that it's inconsistent, but '* is shorter than any descriptive
> variable name that we might have chosen for this purpose, and pointers
> are common enough to warrant a short name.
>
> On the other hand, if we had used symbols uniformly for all foreign
> types, then it would have been impossible to bind your own type names
> (e.g. for struct types) without adding a global registry of foreign
> types, which would have various nasty problems such as the potential for
> collisions between unrelated libraries.
>
> Regards,
> Mark
Yes. In the ffi-helper I’m working on, which is intended to help auto-generate ffi code from C headers, I use #:prefix to avoid clashes:
(define-module (cairo cairo)
#:use-module (ffi-help)
#:use-module ((system foreign) #:prefix ffi:)
#:use-module ((bytestructures guile) #:prefix bs:)
)
(define bs:struct bs:bs:struct)
…
;; cairo_matrix_t
(define cairo_matrix_t
(bs:struct
(list `(xx ,bs:double)
`(yx ,bs:double)
`(xy ,bs:double)
`(yy ,bs:double)
`(x0 ,bs:double)
`(y0 ,bs:double))))
(export cairo_matrix_t)
…
;; void cairo_line_to(cairo_t *cr, double x, double y);
(define cairo_line_to
(let ((f (ffi:pointer->procedure
ffi:void
(lib-func "cairo_line_to")
(list '* ffi:double ffi:double))))
(lambda (cr x y)
(let ((~cr ((unwrap-cairo_t* cr)))) (f ~cr x y)))))
(export cairo_line_to)
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-11 5:50 ` Mark H Weaver
2017-06-11 13:07 ` Matt Wette
@ 2017-06-11 17:15 ` Catonano
1 sibling, 0 replies; 14+ messages in thread
From: Catonano @ 2017-06-11 17:15 UTC (permalink / raw)
To: Mark H Weaver; +Cc: guile-user, Matt Wette
2017-06-11 7:50 GMT+02:00 Mark H Weaver <mhw@netris.org>:
> Catonano <catonano@gmail.com> writes:
>
> > 2017-06-10 0:33 GMT+02:00 Matt Wette <matt.wette@gmail.com>:
> >
> > I think Mike caught your real error: you were passing (list ‘* ‘int ‘*)
> and
> >> it wants (list ‘* int ‘*). `int’ is a variable defined by guile.
> >>
> >
> > And isn't `*' a variable defined in guile too ?
> >
> >
> >>
> >> scheme@(guile-user)> (use-modules (system foreign))
> >> scheme@(guile-user)> int
> >> $1 = 8
> >>
> >
> > yes, and
> >
> > scheme@(freexl common)> *
> > $14 = #<procedure * (#:optional _ _ . _)>
>
> 'int' is a variable exported by (system foreign) whose sole purpose is
> to represent a foreign type.
>
> '*' is something completely different, namely a procedure to multiply
> numbers. IMO, it would be a nasty hack for the FFI to check
> specifically for a multiplication procedure and interpret that as a
> pointer type.
>
Ok, there was a misunderstanding here
I thought that iin that context `*' was being exported from (system
foreign) too and it was bound to someting used to represent a C pointer
I hadn't understood that it is instead bound to the vanilla multiplication !
> > I took a look at the guile-gcrypt code again
> >
> > it's full of things like
> >
> > '(* * ,int ,size_t *)
> >
> > that is, only asterisks (pointers) are quoted
> >
> > Other types are not
> >
> > So this must be an established convention
> >
> > It just seems unconsistent to me
>
> I agree that it's inconsistent, but '* is shorter than any descriptive
> variable name that we might have chosen for this purpose, and pointers
> are common enough to warrant a short name.
>
sure. Now I understand better
>
> On the other hand, if we had used symbols uniformly for all foreign
> types, then it would have been impossible to bind your own type names
> (e.g. for struct types) without adding a global registry of foreign
> types, which would have various nasty problems such as the potential for
> collisions between unrelated libraries.
>
Right, right
Thanks for your remarks
Mark, would you mind to take a look at the other thread (#define SOMETHING
some_value) ?
I'm stuck in wrapping this funtion from Freexl
Thanks again !
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-09 20:36 type friction C <-> scheme Catonano
2017-06-09 20:52 ` Mike Gran
2017-06-09 20:56 ` Matt Wette
@ 2017-06-11 18:01 ` Matt Wette
2017-06-11 18:20 ` Catonano
2017-06-12 8:00 ` David Pirotte
2 siblings, 2 replies; 14+ messages in thread
From: Matt Wette @ 2017-06-11 18:01 UTC (permalink / raw)
To: Catonano; +Cc: guile-user
> On Jun 9, 2017, at 1:36 PM, Catonano <catonano@gmail.com> wrote:
>
> Here we go again
>
> After successfully wrapping freexl_open, I can't do the same with
> freexl_get_info
Note that my fyi-helper is not working yet, but here is the current output if I feed it freexl.h
;;
;; auto-generated by ffi-help.scm
;;
(define-module (freexl)
#:use-module (ffi-help)
#:use-module ((system foreign) #:prefix ffi:)
#:use-module ((bytestructures guile) #:prefix bs:)
)
(define bs:struct bs:bs:struct)
(define lib-link (dynamic-link #f))
(define (lib-func name) (dynamic-func name lib-link))
;; (struct . "FreeXL_CellValue_str")
;; ... failed.
;; "FreeXL_CellValue"
;; typedef struct FreeXL_CellValue_str FreeXL_CellValue;
(define-std-pointer-wrapper FreeXL_CellValue*)
;; "freexl_version"
;; extern const char *freexl_version(void);
(define freexl_version
(let ((f (ffi:pointer->procedure
'*
(lib-func "freexl_version")
(list))))
(lambda () (let () (identity (f))))))
(export freexl_version)
;; "freexl_open"
;; extern int freexl_open(const char *path, const void **xls_handle);
(define freexl_open
(let ((f (ffi:pointer->procedure
ffi:int
(lib-func "freexl_open")
(list '* '*))))
(lambda (path xls_handle)
(let ((~path (identity path))
(~xls_handle (identity xls_handle)))
(f ~path ~xls_handle)))))
(export freexl_open)
;; "freexl_open_info"
;; extern int freexl_open_info(const char *path, const void **xls_handle);
(define freexl_open_info
(let ((f (ffi:pointer->procedure
ffi:int
(lib-func "freexl_open_info")
(list '* '*))))
(lambda (path xls_handle)
(let ((~path (identity path))
(~xls_handle (identity xls_handle)))
(f ~path ~xls_handle)))))
(export freexl_open_info)
;; "freexl_close"
;; extern int freexl_close(const void *xls_handle);
(define freexl_close
(let ((f (ffi:pointer->procedure
ffi:int
(lib-func "freexl_close")
(list '*))))
(lambda (xls_handle)
(let ((~xls_handle (identity xls_handle)))
(f ~xls_handle)))))
(export freexl_close)
;; "freexl_get_info"
;; extern int freexl_get_info(const void *xls_handle, unsigned short what,
;; unsigned int *info);
(define freexl_get_info
(let ((f (ffi:pointer->procedure
ffi:int
(lib-func "freexl_get_info")
(list '* ffi:unsigned-short '*))))
(lambda (xls_handle what info)
(let ((~xls_handle (identity xls_handle))
(~info (identity info)))
(f ~xls_handle what ~info)))))
(export freexl_get_info)
;; "freexl_get_worksheet_name"
;; extern int freexl_get_worksheet_name(const void *xls_handle, unsigned short
;; sheet_index, const char **string);
(define freexl_get_worksheet_name
(let ((f (ffi:pointer->procedure
ffi:int
(lib-func "freexl_get_worksheet_name")
(list '* ffi:unsigned-short '*))))
(lambda (xls_handle sheet_index string)
(let ((~xls_handle (identity xls_handle))
(~string (identity string)))
(f ~xls_handle sheet_index ~string)))))
(export freexl_get_worksheet_name)
;; "freexl_select_active_worksheet"
;; extern int freexl_select_active_worksheet(const void *xls_handle,
;; unsigned short sheet_index);
(define freexl_select_active_worksheet
(let ((f (ffi:pointer->procedure
ffi:int
(lib-func "freexl_select_active_worksheet")
(list '* ffi:unsigned-short))))
(lambda (xls_handle sheet_index)
(let ((~xls_handle (identity xls_handle)))
(f ~xls_handle sheet_index)))))
(export freexl_select_active_worksheet)
;; "freexl_get_active_worksheet"
;; extern int freexl_get_active_worksheet(const void *xls_handle,
;; unsigned short *sheet_index);
(define freexl_get_active_worksheet
(let ((f (ffi:pointer->procedure
ffi:int
(lib-func "freexl_get_active_worksheet")
(list '* '*))))
(lambda (xls_handle sheet_index)
(let ((~xls_handle (identity xls_handle))
(~sheet_index (identity sheet_index)))
(f ~xls_handle ~sheet_index)))))
(export freexl_get_active_worksheet)
;; "freexl_worksheet_dimensions"
;; extern int freexl_worksheet_dimensions(const void *xls_handle, unsigned int
;; *rows, unsigned short *columns);
(define freexl_worksheet_dimensions
(let ((f (ffi:pointer->procedure
ffi:int
(lib-func "freexl_worksheet_dimensions")
(list '* '* '*))))
(lambda (xls_handle rows columns)
(let ((~xls_handle (identity xls_handle))
(~rows (identity rows))
(~columns (identity columns)))
(f ~xls_handle ~rows ~columns)))))
(export freexl_worksheet_dimensions)
;; "freexl_get_SST_string"
;; extern int freexl_get_SST_string(const void *xls_handle, unsigned short
;; string_index, const char **string);
(define freexl_get_SST_string
(let ((f (ffi:pointer->procedure
ffi:int
(lib-func "freexl_get_SST_string")
(list '* ffi:unsigned-short '*))))
(lambda (xls_handle string_index string)
(let ((~xls_handle (identity xls_handle))
(~string (identity string)))
(f ~xls_handle string_index ~string)))))
(export freexl_get_SST_string)
;; "freexl_get_FAT_entry"
;; extern int freexl_get_FAT_entry(const void *xls_handle, unsigned int
;; sector_index, unsigned int *next_sector_index);
(define freexl_get_FAT_entry
(let ((f (ffi:pointer->procedure
ffi:int
(lib-func "freexl_get_FAT_entry")
(list '* ffi:unsigned-int '*))))
(lambda (xls_handle sector_index next_sector_index)
(let ((~xls_handle (identity xls_handle))
(~next_sector_index (identity next_sector_index)))
(f ~xls_handle sector_index ~next_sector_index)))))
(export freexl_get_FAT_entry)
;; "freexl_get_cell_value"
;; extern int freexl_get_cell_value(const void *xls_handle, unsigned int row,
;; unsigned short column, FreeXL_CellValue *value);
(define freexl_get_cell_value
(let ((f (ffi:pointer->procedure
ffi:int
(lib-func "freexl_get_cell_value")
(list '* ffi:unsigned-int ffi:unsigned-short '*))))
(lambda (xls_handle row column value)
(let ((~xls_handle (identity xls_handle))
(~value (unwrap-FreeXL_CellValue* value)))
(f ~xls_handle row column ~value)))))
(export freexl_get_cell_value)
;; --- last line ---
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-11 18:01 ` Matt Wette
@ 2017-06-11 18:20 ` Catonano
2017-06-12 8:00 ` David Pirotte
1 sibling, 0 replies; 14+ messages in thread
From: Catonano @ 2017-06-11 18:20 UTC (permalink / raw)
To: Matt Wette; +Cc: guile-user
Matt,
thank you for spending some time on this
2017-06-11 20:01 GMT+02:00 Matt Wette <matt.wette@gmail.com>:
>
> > On Jun 9, 2017, at 1:36 PM, Catonano <catonano@gmail.com> wrote:
> >
> > Here we go again
> >
> > After successfully wrapping freexl_open, I can't do the same with
> > freexl_get_info
>
> Note that my fyi-helper is not working yet, but here is the current output
> if I feed it freexl.h
>
> ;;
> ;; auto-generated by ffi-help.scm
> ;;
>
> (define-module (freexl)
> #:use-module (ffi-help)
> #:use-module ((system foreign) #:prefix ffi:)
> #:use-module ((bytestructures guile) #:prefix bs:)
> )
> (define bs:struct bs:bs:struct)
>
> (define lib-link (dynamic-link #f))
> (define (lib-func name) (dynamic-func name lib-link))
>
> ;; (struct . "FreeXL_CellValue_str")
> ;; ... failed.
>
> ;; "FreeXL_CellValue"
>
> ;; typedef struct FreeXL_CellValue_str FreeXL_CellValue;
> (define-std-pointer-wrapper FreeXL_CellValue*)
>
> ;; "freexl_version"
>
> ;; extern const char *freexl_version(void);
> (define freexl_version
> (let ((f (ffi:pointer->procedure
> '*
> (lib-func "freexl_version")
> (list))))
> (lambda () (let () (identity (f))))))
> (export freexl_version)
>
> ;; "freexl_open"
>
> ;; extern int freexl_open(const char *path, const void **xls_handle);
> (define freexl_open
> (let ((f (ffi:pointer->procedure
> ffi:int
> (lib-func "freexl_open")
> (list '* '*))))
> (lambda (path xls_handle)
> (let ((~path (identity path))
> (~xls_handle (identity xls_handle)))
> (f ~path ~xls_handle)))))
> (export freexl_open)
>
Ok, my version of fffreexl_open does work
>
> ;; "freexl_open_info"
>
> ;; extern int freexl_open_info(const char *path, const void **xls_handle);
> (define freexl_open_info
>
> ;; "freexl_close"
>
> ;; extern int freexl_close(const void *xls_handle);
> (define freexl_close
>
I didn't attempt ffrexxl_open_info and frexxl_close yet
>
> ;; "freexl_get_info"
>
> ;; extern int freexl_get_info(const void *xls_handle, unsigned short what,
> ;; unsigned int *info);
> (define freexl_get_info
> (let ((f (ffi:pointer->procedure
> ffi:int
> (lib-func "freexl_get_info")
> (list '* ffi:unsigned-short '*))))
> (lambda (xls_handle what info)
> (let ((~xls_handle (identity xls_handle))
> (~info (identity info)))
> (f ~xls_handle what ~info)))))
> (export freexl_get_info)
>
this doesn't seem so different from what I did
I shoul try to call this one iin the REPL and see what happens
Thanks, I'll let you know
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-11 18:01 ` Matt Wette
2017-06-11 18:20 ` Catonano
@ 2017-06-12 8:00 ` David Pirotte
2017-06-12 12:45 ` Matt Wette
1 sibling, 1 reply; 14+ messages in thread
From: David Pirotte @ 2017-06-12 8:00 UTC (permalink / raw)
To: Matt Wette; +Cc: guile-user
[-- Attachment #1: Type: text/plain, Size: 772 bytes --]
Hello Matt
> ;; "FreeXL_CellValue"
>
> ;; typedef struct FreeXL_CellValue_str FreeXL_CellValue;
> (define-std-pointer-wrapper FreeXL_CellValue*)
> ...
Your ffi-help, snarf *.h is a nice project, but it would be, maybe, interesting that
you look at a way to 'schemefy' names, like it's done for guile-gnome and g-golf
http://git.savannah.gnu.org/cgit/guile-gnome.git/tree/glib/gnome/gobject/utils.scm
look for
StudlyCapsExpand ...
I simplified a bit that code for G-Golf, here:
http://git.savannah.gnu.org/cgit/g-golf.git/tree/g-golf/gi/utils.scm
look for
g-golf-gstudly-caps-expand
%g-golf-gtype-name->scm-name-exceptions
g-golf-gtype-name->scm-name
g-golf-gtype-name->class-name
...
Just an idea ...
Cheers,
David
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: type friction C <-> scheme
2017-06-12 8:00 ` David Pirotte
@ 2017-06-12 12:45 ` Matt Wette
0 siblings, 0 replies; 14+ messages in thread
From: Matt Wette @ 2017-06-12 12:45 UTC (permalink / raw)
To: David Pirotte; +Cc: guile-user
> On Jun 12, 2017, at 1:00 AM, David Pirotte <david@altosw.be> wrote:
>
> Hello Matt
>
>> ;; "FreeXL_CellValue"
>>
>> ;; typedef struct FreeXL_CellValue_str FreeXL_CellValue;
>> (define-std-pointer-wrapper FreeXL_CellValue*)
>> ...
>
> Your ffi-help, snarf *.h is a nice project, but it would be, maybe, interesting that
> you look at a way to 'schemefy' names, like it's done for guile-gnome and g-golf
>
> http://git.savannah.gnu.org/cgit/guile-gnome.git/tree/glib/gnome/gobject/utils.scm
>
> look for
> StudlyCapsExpand ...
>
> I simplified a bit that code for G-Golf, here:
>
> http://git.savannah.gnu.org/cgit/g-golf.git/tree/g-golf/gi/utils.scm
>
> look for
> g-golf-gstudly-caps-expand
> %g-golf-gtype-name->scm-name-exceptions
> g-golf-gtype-name->scm-name
> g-golf-gtype-name->class-name
> ...
>
> Just an idea ...
>
> Cheers,
> David
I can add a renamer option.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2017-06-12 12:45 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-09 20:36 type friction C <-> scheme Catonano
2017-06-09 20:52 ` Mike Gran
2017-06-09 21:33 ` Catonano
2017-06-09 20:56 ` Matt Wette
2017-06-09 21:39 ` Catonano
2017-06-09 22:33 ` Matt Wette
2017-06-10 6:26 ` Catonano
2017-06-11 5:50 ` Mark H Weaver
2017-06-11 13:07 ` Matt Wette
2017-06-11 17:15 ` Catonano
2017-06-11 18:01 ` Matt Wette
2017-06-11 18:20 ` Catonano
2017-06-12 8:00 ` David Pirotte
2017-06-12 12:45 ` Matt Wette
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).