public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Bruce Korb <bruce.korb@gmail.com>
To: Richard Henderson <rth@redhat.com>
Cc: libffi-discuss@sourceware.org
Subject: Re: pass by value and also snprintf()
Date: Mon, 27 Apr 2015 17:37:00 -0000	[thread overview]
Message-ID: <CAKRnqNJtEj_VvXNrF=QXteJAwAYmKZ3K1PAxtb35hY43Nr0ezw@mail.gmail.com> (raw)
In-Reply-To: <553E6D2E.7060403@redhat.com>

Like this then:


#include <stdint.h>
#include <stdio.h>
#include <ffi.h>

#define UCONST(_p)  ((void *)(uintptr_t)_p)

int
main(int argc, char ** argv)
{
        char       buffer[0x1000];
        size_t     bufsz  = sizeof(buffer);
        char const fmt[]  = "Allocated sblock_id=%d for band_id=%d\n";
        int32_t    sblock = 1;
        int32_t    band   = 1;
        void *     fn     = sprintf;

        if (sizeof(bufsz) != sizeof(uint64_t))
                return 1;

        ffi_type * typ[5] = {
                [0] = &ffi_type_pointer,
                [1] = &ffi_type_uint64,
                [2] = &ffi_type_pointer,
                [3] = &ffi_type_sint32,
                [4] = &ffi_type_sint32 };

        void * values[5] = {
                [0] = buffer,
                [1] = &bufsz,
                [2] = UCONST(fmt),
                [3] = &sblock,
                [4] = &band };

        ffi_cif cif;

        if (ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 3, 5,
&ffi_type_uint32, typ) == FFI_OK) {
uint32_t ret_val;

ffi_call(&cif, fn, &ret_val, values);
                fputs(buffer, stdout);
                return 0;
        }
        return 1;
}

$ cc -o ffi-test ffi-test.c -lffi
$ ./ffi-test
Segmentation fault

On Mon, Apr 27, 2015 at 10:09 AM, Richard Henderson <rth@redhat.com> wrote:
> On 04/27/2015 09:59 AM, Bruce Korb wrote:
>> I hope
>> there is an
>> obvious answer to what I am missing:
>
> Certainly there's no way we can help you further without a complete test case.
>
>
> r~

  reply	other threads:[~2015-04-27 17:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-27 16:59 Bruce Korb
2015-04-27 17:09 ` Richard Henderson
2015-04-27 17:37   ` Bruce Korb [this message]
2015-04-27 17:45     ` Bruce Korb
2015-04-27 17:48       ` Bruce Korb
2015-04-27 18:02     ` Richard Henderson
2015-04-27 18:54       ` Bruce Korb

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='CAKRnqNJtEj_VvXNrF=QXteJAwAYmKZ3K1PAxtb35hY43Nr0ezw@mail.gmail.com' \
    --to=bruce.korb@gmail.com \
    --cc=libffi-discuss@sourceware.org \
    --cc=rth@redhat.com \
    /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).