From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Park SungMin Newsgroups: gmane.lisp.guile.user Subject: Re: how to access c-array member in c-structure? Date: Thu, 31 Mar 2016 01:01:32 +0900 Message-ID: <03BD8AC3-D107-43A0-8332-FF567724E3A6@icloud.com> References: <9FB905A2-E625-4B23-BBB3-18831A9535EC@icloud.com> <87zitgxui7.fsf@T420.taylan> <20160330080741.GA28334@tuxteam.de> <87r3esxrq2.fsf@T420.taylan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 9.2 \(3112\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1459353753 5134 80.91.229.3 (30 Mar 2016 16:02:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 30 Mar 2016 16:02:33 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Mar 30 18:02:19 2016 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1alIZW-0007TV-Nd for guile-user@m.gmane.org; Wed, 30 Mar 2016 18:02:18 +0200 Original-Received: from localhost ([::1]:55572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alIZS-0000BH-KM for guile-user@m.gmane.org; Wed, 30 Mar 2016 12:02:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alIZA-00005H-1f for guile-user@gnu.org; Wed, 30 Mar 2016 12:01:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alIZ4-0000kW-38 for guile-user@gnu.org; Wed, 30 Mar 2016 12:01:55 -0400 Original-Received: from pv33p04im-asmtp002.me.com ([17.143.181.11]:37178) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alIZ3-0000jS-R8 for guile-user@gnu.org; Wed, 30 Mar 2016 12:01:50 -0400 Original-Received: from [192.168.0.5] (unknown [110.11.250.108]) by pv33p04im-asmtp002.me.com (Oracle Communications Messaging Server 7.0.5.36.0 64bit (built Sep 8 2015)) with ESMTPSA id <0O4V00F560IL7H40@pv33p04im-asmtp002.me.com> for guile-user@gnu.org; Wed, 30 Mar 2016 16:01:36 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-03-30_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1015 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1510270003 definitions=main-1603300233 In-reply-to: <87r3esxrq2.fsf@T420.taylan> X-Mailer: Apple Mail (2.3112) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 17.143.181.11 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 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-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:12526 Archived-At: >> If I understood Park SungMin right, the problem is rather with the >> representation of a huge array as a list? >=20 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 '*)) =3D> (42 #) but=E2=80=A6.when i access to that pointer object (pointer->bytevector (cadr (parse-c-struct struct (list int '*))) (* 10 (sizeof int))) =3D> 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 =3D {.a =3D a, .b =3D b}; return foo; } ((pointer->procedure (list int int '*) (dynamic-func "make_foo" libfoo) (list int int)) 10 10) shutdown=E2=80=A6. 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) =3D> (C #.(SB-SYS:INT-SAP #X0CC6C0A8) B 20 A 10) but when I change to=20 (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=C4=B1rl=C4=B1/Kammer = wrote: >=20 > writes: >=20 >> On Wed, Mar 30, 2016 at 10:03:28AM +0200, Taylan Ulrich = Bay=C4=B1rl=C4=B1/Kammer wrote: >>> Park SungMin writes: >>>=20 >>>> (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)) >>>>=20 >>>> also run well=E2=80=A6but seems less effective.(if more bigger = size=E2=80=A62000000??)=20 >>>=20 >>> You could create the type object once at program startup and use it >>> many times. >>>=20 >>> (define foo-type >>> (list int int (make-list 2000000 int))) >>=20 >> If I understood Park SungMin right, the problem is rather with the >> representation of a huge array as a list? >=20 > Oh I see. >=20 > For me, the following works: >=20 > (define type (list int (make-list 10 int))) >=20 > (define struct (make-c-struct type (list 42 (make-list 10 42)))) >=20 > (parse-c-struct struct (list int '*)) > =3D> (1 #)=20 >=20 > Is it different when the struct really comes from the C library? >=20 > Taylan >=20