From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.user Subject: Re: unsigned-int Date: Fri, 23 Jun 2017 08:37:07 -0400 Message-ID: <87tw36hocs.fsf@netris.org> References: <87efuchu4b.fsf@netris.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1498221460 25484 195.159.176.226 (23 Jun 2017 12:37:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 23 Jun 2017 12:37:40 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cc: guile-user@gnu.org To: Catonano Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jun 23 14:37:37 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dONqC-0006RL-C4 for guile-user@m.gmane.org; Fri, 23 Jun 2017 14:37:36 +0200 Original-Received: from localhost ([::1]:35333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dONqH-00057w-KQ for guile-user@m.gmane.org; Fri, 23 Jun 2017 08:37:41 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dONpq-00050V-II for guile-user@gnu.org; Fri, 23 Jun 2017 08:37:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dONpl-00085l-Kz for guile-user@gnu.org; Fri, 23 Jun 2017 08:37:14 -0400 Original-Received: from world.peace.net ([50.252.239.5]:49155) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dONpl-00085c-Gs for guile-user@gnu.org; Fri, 23 Jun 2017 08:37:09 -0400 Original-Received: from [10.1.10.104] (helo=jojen) by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dONhU-0000wX-V7; Fri, 23 Jun 2017 08:28:36 -0400 In-Reply-To: (catonano@gmail.com's message of "Thu, 22 Jun 2017 21:33:31 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 50.252.239.5 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:13875 Archived-At: Catonano writes: > 2017-06-22 21:13 GMT+02:00 Catonano : >> >> >> 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