diff options
author | Anthony Green <green@moxielogic.com> | 2019-11-20 06:15:55 -0500 |
---|---|---|
committer | Anthony Green <green@moxielogic.com> | 2019-11-20 06:15:55 -0500 |
commit | 31543c799a224ef446cef19a2372b054ecad3822 (patch) | |
tree | 82ee28bf983d651a44043ff1b0b43221a0cc90d8 /src | |
parent | bd3a4687c0743076f420dee2a02075fd64fa547e (diff) | |
download | libffi-31543c799a224ef446cef19a2372b054ecad3822.tar.gz |
Add work-around for users who manage their own closure memory
As suggested by DJ
Diffstat (limited to 'src')
-rw-r--r-- | src/closures.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/closures.c b/src/closures.c index 86e74c2..5120021 100644 --- a/src/closures.c +++ b/src/closures.c @@ -1,5 +1,6 @@ /* ----------------------------------------------------------------------- - closures.c - Copyright (c) 2007, 2009, 2010 Red Hat, Inc. + closures.c - Copyright (c) 2019 Anthony Green + Copyright (c) 2007, 2009, 2010 Red Hat, Inc. Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc Copyright (c) 2011 Plausible Labs Cooperative, Inc. @@ -936,7 +937,14 @@ void * ffi_data_to_code_pointer (void *data) { msegmentptr seg = segment_holding (gm, data); - return add_segment_exec_offset (data, seg); + /* We expect closures to be allocated with ffi_closure_alloc(), in + which case seg will be non-NULL. However, some users take on the + burden of managing this memory themselves, in which case this + we'll just return data. */ + if (seg) + return add_segment_exec_offset (data, seg); + else + return data; } /* Release a chunk of memory allocated with ffi_closure_alloc. If |