From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 110348 invoked by alias); 27 Apr 2015 17:37:54 -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 110338 invoked by uid 89); 27 Apr 2015 17:37:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f54.google.com Received: from mail-wg0-f54.google.com (HELO mail-wg0-f54.google.com) (74.125.82.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 27 Apr 2015 17:37:52 +0000 Received: by wgin8 with SMTP id n8so123991748wgi.0 for ; Mon, 27 Apr 2015 10:37:49 -0700 (PDT) X-Received: by 10.180.74.238 with SMTP id x14mr23069382wiv.81.1430156268932; Mon, 27 Apr 2015 10:37:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.33.135 with HTTP; Mon, 27 Apr 2015 10:37:28 -0700 (PDT) In-Reply-To: <553E6D2E.7060403@redhat.com> References: <553E6D2E.7060403@redhat.com> From: Bruce Korb Date: Mon, 27 Apr 2015 17:37:00 -0000 Message-ID: Subject: Re: pass by value and also snprintf() To: Richard Henderson Cc: libffi-discuss@sourceware.org Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2015/txt/msg00066.txt.bz2 Like this then: #include #include #include #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 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~