From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Aidan Gauland Newsgroups: gmane.lisp.guile.user Subject: Parsing a struct within a struct Date: Tue, 8 Mar 2011 20:20:29 +1300 Message-ID: <20110308072028.GA11631@neko> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="NMuMz9nt05w80d4+" X-Trace: dough.gmane.org 1299568820 7186 80.91.229.12 (8 Mar 2011 07:20:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 8 Mar 2011 07:20:20 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Mar 08 08:20:16 2011 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PwrDG-0001JG-IZ for guile-user@m.gmane.org; Tue, 08 Mar 2011 08:20:10 +0100 Original-Received: from localhost ([127.0.0.1]:59607 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PwrDF-0001UX-D1 for guile-user@m.gmane.org; Tue, 08 Mar 2011 02:20:09 -0500 Original-Received: from [140.186.70.92] (port=51000 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PwrD4-0001Si-G6 for guile-user@gnu.org; Tue, 08 Mar 2011 02:20:01 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PwrD3-0001eB-Fv for guile-user@gnu.org; Tue, 08 Mar 2011 02:19:58 -0500 Original-Received: from jersey.rurallink.co.nz ([114.134.15.197]:42020 helo=smtp.rurallink.co.nz) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PwrD2-0001dg-VQ for guile-user@gnu.org; Tue, 08 Mar 2011 02:19:57 -0500 Original-Received: from 114-134-6-192.rurallink.co.nz ([114.134.6.192] helo=localhost) by smtp.rurallink.co.nz with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1PwrCs-0006H1-5c for guile-user@gnu.org; Tue, 08 Mar 2011 20:19:47 +1300 Mail-Followup-To: guile-user@gnu.org Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-Rurallink-Authenticated-User: aidalgol@no8wireless.co.nz X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 114.134.15.197 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:8488 Archived-At: --NMuMz9nt05w80d4+ Content-Type: multipart/mixed; boundary="XsQoSWH+UP9D9v3l" Content-Disposition: inline --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, I'm trying to write a game in Guile Scheme using SDL, and I'm having trouble parsing a C struct within a struct. (The files for my program are in the attached tarball, for those with the time to examine it that closely.) This is how the struct is parsed... (parse-c-struct event-pointer (list uint8 uint8 uint8 (list uint8 int int uint16 ))) =2E..which is called only when the event (an SDL event) is a key-down event. These are the relevant SDL structs... /** General event structure */ typedef union SDL_Event { Uint8 type; SDL_ActiveEvent active; SDL_KeyboardEvent key; SDL_MouseMotionEvent motion; SDL_MouseButtonEvent button; SDL_JoyAxisEvent jaxis; SDL_JoyBallEvent jball; SDL_JoyHatEvent jhat; SDL_JoyButtonEvent jbutton; SDL_ResizeEvent resize; SDL_ExposeEvent expose; SDL_QuitEvent quit; SDL_UserEvent user; SDL_SysWMEvent syswm; } SDL_Event; typedef struct SDL_KeyboardEvent { Uint8 type; /**< SDL_KEYDOWN or SDL_KEYUP */ Uint8 which; /**< The keyboard device index */ Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */ SDL_keysym keysym; } SDL_KeyboardEvent; typedef struct SDL_keysym { Uint8 scancode; /**< hardware specific scancode */ SDLKey sym; /**< SDL virtual keysym */ SDLMod mod; /**< current key modifiers */ Uint16 unicode; /**< translated character */ } SDL_keysym; SDLKey and SDLMod are declared as typedef enums. i.e. typedef enum { ... } SDLKey or SDLMod; In my program, I print the result of the above call to `parse-c-struct'. In the program's output, the value of the sym field is always a high-magnitude, negative number, but the value is unique for each key, and consistent for each key (i.e. a key-press of, say, A is always the same value). But the defined values of SDLKey range =66rom 0 to 322, so the parsed value is obviously incorrect. (I think the parsed value of the mod field is also incorrect.) Am I doing something wrong? Are the arguments to `parse-c-struct' incorrect? Am I neglecting some important detail of how structs are dealt with in C (such as alignment)? Or (heaven forbid) is it a bug in the FFI? Regards, Aidan Gauland --XsQoSWH+UP9D9v3l Content-Type: application/octet-stream Content-Disposition: attachment; filename="fruitflats.tar.gz" Content-Transfer-Encoding: base64 H4sICObGdU0CA2ZydWl0ZmxhdHMudGFyAO0aa3PbNtKf9SvW0oeQvdImqVeaXHOTaTy9zOTh Nmm/5igSsnGmSJUE7fh+fRcAH+BLolw5SW+wMxEdcLG7APYNrpOMsnXosfT85LHARljO5/zp LOe2+izgxHHm0/l0NnWXyxPbcZ3F/ATmJ18AspR5CcCJRwMv2oG37/3fFNbV+adBeJb6m8c5 /8Vs1nf+jjtz5fk7tuu4Lp4/KoJ9ArY+/0cHIyBrGhFrEwdZSMCo9AFQH8wRwLMs7XttbRN6 6zECfrzZxNFQbHJLIpYOxb6lAYlbyOl9ysgG1nFC6JXkTD5v44SBQSPKrEL4hFi1cUENX6iw jcPQEkI1Xogxi91vSeeLbUwjRhLrxS3xWZyY5miUbycUMuA8o0TbJrFPgizBNcU0aJAswAju I29DfWudRT6MP7x68+k1EhuLPYlXZt+0kKYMMuQ0dU1Vkj+yI0rySzZQEi7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wIyq/5YAFAAAA== --XsQoSWH+UP9D9v3l-- --NMuMz9nt05w80d4+ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAk112LwACgkQjyzTRvYJmaW6tQCghNPLPtTVMqBnIOGWnBdQyhe4 kWwAmwQGHWjuOUjZ+9FxRWz/PXQVeLYU =ftzi -----END PGP SIGNATURE----- --NMuMz9nt05w80d4+--