public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Kaz Kylheku (libffi)" <382-725-6798@kylheku.com>
To: Cheng Jin <jincheng@ca.ibm.com>
Cc: libffi-discuss@sourceware.org
Subject: Re: Incorrect data detected in the nested float struct with x86/libffi on Linux/64bit
Date: Wed, 09 Jun 2021 16:48:37 -0700	[thread overview]
Message-ID: <dc1d82f0f6d2ca17d31448e20a5fb9fb@mail.kylheku.com> (raw)
In-Reply-To: <OF5D0877D1.6ACE238D-ON002586EF.0055990B-852586EF.005BA901@ibm.com>

On 2021-06-09 09:41, Cheng Jin via Libffi-discuss wrote:
> Hi,

Hi Cheng Jin,

A small matter on a tangent.

> 
> 	  cls_struct_fields1[0] = &ffi_type_float;
> 	  cls_struct_fields1[1] = &cls_struct_type2;
> 	  cls_struct_fields1[2] = NULL;

Indeed, the array describing the element types of a structure must be
null terminated, so this is required.

> 	  cls_struct_type1.size = 0;
> 	  cls_struct_type1.alignment = 0;
> 	  cls_struct_type1.type = FFI_TYPE_STRUCT;
> 	  cls_struct_type1.elements = cls_struct_fields1;

Note that here, the size of the object is not indicated. That's why
the extra null pointer is required to infer the size.

> 
> 	  dbl_arg_types[0] = &ffi_type_float;
> 	  dbl_arg_types[1] = &cls_struct_type1;
> 	  dbl_arg_types[2] = NULL;

But, for the argument array of a ffi_cif, no null termination is 
required.

> 	 ffi_prep_cif(&cif_temp, FFI_DEFAULT_ABI, 2, retType, dbl_arg_types);

No requirement for a null terminator is documented or appears in
examples. The 2 argument indicates the number of elements.

There is no harm in it; just pointing it out.

When I looked at your code, I went scrambling through documentation
to see if I was missing a required null terminator. :)

Cheers ...

  parent reply	other threads:[~2021-06-09 23:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-09 16:41 Cheng Jin
2021-06-09 16:50 ` Anthony Green
2021-06-09 17:53   ` Cheng Jin
2021-06-15 18:02   ` Jakub Jelinek
2021-06-15 19:02     ` Jakub Jelinek
2021-06-15 19:29       ` Anthony Green
2021-06-09 23:48 ` Kaz Kylheku (libffi) [this message]
2021-06-10  0:21   ` Cheng Jin
2021-06-10  2:05 ` Kaz Kylheku (libffi)
2021-06-10  2:39   ` Cheng Jin

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dc1d82f0f6d2ca17d31448e20a5fb9fb@mail.kylheku.com \
    --to=382-725-6798@kylheku.com \
    --cc=jincheng@ca.ibm.com \
    --cc=libffi-discuss@sourceware.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).