Functions returning structs are not thread-safe

Bug #1474211 reported by Elias Martenson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
CFFI
In Progress
Undecided
Unassigned

Bug Description

When DEFCFUN is used to declare a function that returns a struct, the resulting function calls CFFI:FOREIGN-FUNCALL which expands into a call to CFFI:PREPARE-FUNCTION. This function is not thread-safe since it can alter the content of *CIF-TABLE*.

Note that this code-path is only followed for functions that are called through libffi (i.e. functions that returns structs). Plain functions are not affected by this.

PREPARE-FUNCTION should use a mutex or other mechanism to prevent parallel access to *CIF-TABLE*.

Another potential solution would be to run DEFCFUN during compile-time, although I don't know the implications of this.

Revision history for this message
Luís Oliveira (luismbo) wrote :

Liam's fix at https://github.com/cffi/cffi/commit/bb5577baffae0137ae4087ee95cbd2df31b7ca87 (and discussion on IRC) suggests this is only an issue during compilation, but this bug report suggests otherwise. Which is which?

Changed in cffi:
status: New → In Progress
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.