From: Park SungMin <byulparan_eng@icloud.com>
To: guile-user@gnu.org
Subject: Re: how to access c-array member in c-structure?
Date: Thu, 31 Mar 2016 01:01:32 +0900 [thread overview]
Message-ID: <03BD8AC3-D107-43A0-8332-FF567724E3A6@icloud.com> (raw)
In-Reply-To: <87r3esxrq2.fsf@T420.taylan>
>> If I understood Park SungMin right, the problem is rather with the
>> representation of a huge array as a list?
>
correct! (sorry..my poor english)
I think huge c-array should be representation as bytevector or pointer object.
(define type (list int (make-list 10 int)))
(define struct (make-c-struct type (list 42 (make-list 10 42))))
(parse-c-struct struct (list int '*))
=> (42 #<pointer 0x2a0000002a>)
but….when i access to that pointer object
(pointer->bytevector (cadr (parse-c-struct struct (list int '*)))
(* 10 (sizeof int)))
=> shutdown guile!
with my test C function..
typedef struct {
int a;
int b;
int c[2000];
} Foo;
Foo make_foo(int a, int b) {
Foo foo = {.a = a, .b = b};
return foo;
}
((pointer->procedure
(list int int '*)
(dynamic-func "make_foo" libfoo)
(list int int))
10 10)
shutdown…. I also test in SBCL(cffi-libffi)
(cffi:defcstruct foo
(a :int)
(b :int)
(c :int :count 2000))
(cffi:defcfun "make_foo" (:struct foo)
(a :int)
(b :int))
(make-foo 10 20) => (C #.(SB-SYS:INT-SAP #X0CC6C0A8) B 20 A 10)
but when I change to
(cffi:defcstruct foo
(a :int)
(b :int)
(c :pointer))
when call (make-foo 10 20), then shut down.
but It seems consequent, array and pointer are different type.
> On Mar 30, 2016, at 6:03 PM, Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com> wrote:
>
> <tomas@tuxteam.de> writes:
>
>> On Wed, Mar 30, 2016 at 10:03:28AM +0200, Taylan Ulrich Bayırlı/Kammer wrote:
>>> Park SungMin <byulparan_eng@icloud.com> writes:
>>>
>>>> (let ((c-type (list int int (make-list 20000 int))))
>>>> (parse-c-struct
>>>> ((pointer->procedure
>>>> c-type
>>>> (dynamic-func "make_foo" libfoo)
>>>> (list int int))
>>>> 4 11)
>>>> c-type))
>>>>
>>>> also run well…but seems less effective.(if more bigger size…2000000??)
>>>
>>> You could create the type object once at program startup and use it
>>> many times.
>>>
>>> (define foo-type
>>> (list int int (make-list 2000000 int)))
>>
>> If I understood Park SungMin right, the problem is rather with the
>> representation of a huge array as a list?
>
> Oh I see.
>
> For me, the following works:
>
> (define type (list int (make-list 10 int)))
>
> (define struct (make-c-struct type (list 42 (make-list 10 42))))
>
> (parse-c-struct struct (list int '*))
> => (1 #<pointer 0x200000002>)
>
> Is it different when the struct really comes from the C library?
>
> Taylan
>
next prev parent reply other threads:[~2016-03-30 16:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-30 0:13 how to access c-array member in c-structure? Park SungMin
2016-03-30 8:03 ` Taylan Ulrich Bayırlı/Kammer
2016-03-30 8:07 ` tomas
2016-03-30 9:03 ` Taylan Ulrich Bayırlı/Kammer
2016-03-30 16:01 ` Park SungMin [this message]
2016-03-30 19:54 ` Taylan Ulrich Bayırlı/Kammer
2016-03-31 3:02 ` Park SungMin
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=03BD8AC3-D107-43A0-8332-FF567724E3A6@icloud.com \
--to=byulparan_eng@icloud.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).