From: Mark H Weaver <mhw@netris.org>
To: Catonano <catonano@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: unsigned-int
Date: Fri, 23 Jun 2017 08:37:07 -0400 [thread overview]
Message-ID: <87tw36hocs.fsf@netris.org> (raw)
In-Reply-To: <CAJ98PDyDicSvXWDpo0q3--u-xSp3_hsT0yfNwabTw0HuZbEc3Q@mail.gmail.com> (catonano@gmail.com's message of "Thu, 22 Jun 2017 21:33:31 +0200")
Catonano <catonano@gmail.com> writes:
> 2017-06-22 21:13 GMT+02:00 Catonano <catonano@gmail.com>:
>>
>>
>> I apologize if my questions are naive.
>> I wrote my last scrap of C code in about 2004 and it never was my thing
>> Also the manual is a great reference but not a great tutorial and I'm not
> a great reader, probably.
>
> Something that is concerning me is that in the example a "rows" variable
> and a "columns" variable get declared as
>
> unsigned int rows;
> unsigned short columns;
>
> and then they get passed as arguments to freexl_worksheet_dimensions as
>
> &rows, &columns
>
> like this
>
> ret = freexl_worksheet_dimensions (handle, &rows, &columns);
>
> In scheme I am NOT declaring anything because I don't now how to
> I am just passing void pointers to freexl_worksheet_dimensions
No, you need to allocate the memory where 'rows' and 'columns' will be
stored, and pass pointers to that memory. freexl_worksheet_dimensions
will then store the values in those locations.
I looked at your code, and I see you've updated the code since you
posted these messages, but it's still not right:
> (define freexl-worksheet-dimensions
> (let* ((ptr (freexl-func "freexl_worksheet_dimensions"))
> (proc (pointer->procedure int ptr (list '* '* '*))))
> (lambda (handle-ptr)
> (let* ((rows-ptr (bytevector->pointer (make-bytevector (sizeof '*))))
> (columns-ptr (bytevector->pointer (make-bytevector (sizeof '*))))
In the two lines above, instead of (sizeof '*), it should be
(sizeof unsigned-int) for the rows bytevector, and
(sizeof unsigned-short) for the columns bytevector.
> (result (proc (unwrap-handler handle-ptr) rows-ptr columns-ptr)))
> (if (not (= result 0))
> (throw 'get-worksheet-dimensions-error 'error-code result)
> ;;(list (dereference-pointer rows-ptr) (dereference-pointer columns-ptr))
> (list
> (pointer->bytevector
> rows-ptr (sizeof unsigned-int))
>
>
>
> (pointer->bytevector
> columns-ptr (sizeof unsigned-short))
> ))
This returns a list of two bytevectors. Wouldn't it be better to return
the actual values? Also, instead of using 'pointer->bytevector' here,
it would be better to have saved the bytevectors that you created in the
first place. Maybe something like this (untested):
(define freexl-worksheet-dimensions
(let* ((ptr (freexl-func "freexl_worksheet_dimensions"))
(proc (pointer->procedure int ptr (list '* '* '*))))
(lambda (handle-ptr)
(let* ((rows-bv (make-bytevector (sizeof unsigned-int)))
(columns-bv (make-bytevector (sizeof unsigned-short)))
(result (proc (unwrap-handler handle-ptr)
(bytevector->pointer rows-bv)
(bytevector->pointer columns-bv))))
(unless (zero? result)
(throw 'get-worksheet-dimensions-error 'error-code result))
(list (bytevector-uint-ref rows-bv 0 (native-endianness)
(sizeof unsigned-int))
(bytevector-uint-ref columns-bv 0 (native-endianness)
(sizeof unsigned-short)))))))
Mark
next prev parent reply other threads:[~2017-06-23 12:37 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-22 9:42 unsigned-int Catonano
2017-06-22 9:56 ` unsigned-int Catonano
2017-06-22 16:20 ` unsigned-int Mark H Weaver
2017-06-22 19:13 ` unsigned-int Catonano
2017-06-22 19:33 ` unsigned-int Catonano
2017-06-22 19:55 ` unsigned-int Catonano
2017-06-22 20:01 ` unsigned-int Catonano
2017-06-22 20:53 ` unsigned-int Catonano
2017-06-23 12:37 ` Mark H Weaver [this message]
2017-06-23 12:16 ` unsigned-int Mark H Weaver
2017-06-24 9:17 ` unsigned-int Catonano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tw36hocs.fsf@netris.org \
--to=mhw@netris.org \
--cc=catonano@gmail.com \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).