From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32306 invoked by alias); 28 May 2017 03:14:39 -0000 Mailing-List: contact libffi-discuss-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libffi-discuss-owner@sourceware.org Received: (qmail 32151 invoked by uid 89); 28 May 2017 03:14:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=enclosure, Hx-spam-relays-external:64.59.136.139, H*RU:64.59.136.139, HTo:U*libffi-discuss X-HELO: smtp-out-so.shaw.ca Received: from smtp-out-so.shaw.ca (HELO smtp-out-so.shaw.ca) (64.59.136.139) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 28 May 2017 03:14:28 +0000 Received: from kylheku.com ([70.79.163.252]) by shaw.ca with SMTP id EoexduHlueQWUEoezdtGpE; Sat, 27 May 2017 21:14:30 -0600 X-Authority-Analysis: v=2.2 cv=UpATD64B c=1 sm=1 tr=0 a=95A0EdhkF1LMGt25d7h1IQ==:117 a=95A0EdhkF1LMGt25d7h1IQ==:17 a=IkcTkHD0fZMA:10 a=SMorJkV_YP8A:10 a=tJ8p9aeEuA8A:10 a=qa2X-8J0nrxisJ1XitMA:9 a=QEXdDO2ut3YA:10 Received: from www-data by kylheku.com with local (Exim 4.72) (envelope-from ) id 1dEoes-0002bW-VR for libffi-discuss@sourceware.org; Sat, 27 May 2017 20:14:23 -0700 To: libffi-discuss@sourceware.org Subject: Help: correct way to handle struct return values. X-PHP-Originating-Script: 501:rcmail.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Date: Sun, 28 May 2017 03:14:00 -0000 From: Kaz Kylheku Message-ID: X-Sender: kaz@kylheku.com User-Agent: Roundcube Webmail/0.9.2 X-CMAE-Envelope: MS4wfLvE4YSxPre1ziU8wEc7APykt5Lypo2rjwhllJUw9fzGWajZgXtJozf6hEvIQSXf7rB6gNG6GMq7ejr5PnBxC0EWqY5dfC4IXiqNet9Xb+5RYmyZqcKy 1hQ3RSx7jbaQxeFu1LarEoAI7SKPtPxg52YTmyi6wGFENdDXIoyWVHyVKFa0Tcw57U5hQMFBjqjLzg== X-SW-Source: 2017/txt/msg00007.txt.bz2 Hi all, In the current texinfo doc, the callback stub does this to return a value of type int: /* Acts like puts with the file given at time of enclosure. */ void puts_binding(ffi_cif *cif, void *ret, void* args[], void *stream) { *(ffi_arg *)ret =3D fputs(*(char **)args[0], (FILE *)stream); } Can someone show what the code would look like for a function that returns the following type, and work everywhere: all supported platforms, big or little endian: struct little { char a, b }; Obvously, this can't be used: *(ffi_arg *)ret =3D fun_returning_struct_little(...); After everything, I'm not confident that this is correct, either: *(struct little *)ret =3D fun_returning_struct_little(...); Also, can someone show how to extract "struct little" in after a ffi down call? If the type is int, we can do this: ffi_arg rc_buf; int rc; ffi_call(&cif, puts, &rc_buf, values); rc =3D rc_buf; But what if rc is of type "little struct"? Again, we can't just use a=20 cast. Lastly, how does any of this change for struct bigger_struct { long x,=20 y, z; }? Thanks.