diff options
Diffstat (limited to 'src/OpenSSL/_util.py')
-rw-r--r-- | src/OpenSSL/_util.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/OpenSSL/_util.py b/src/OpenSSL/_util.py index cdcacc8..d8e3f66 100644 --- a/src/OpenSSL/_util.py +++ b/src/OpenSSL/_util.py @@ -145,3 +145,17 @@ def text_to_bytes_and_warn(label, obj): ) return obj.encode('utf-8') return obj + + +try: + # newer versions of cffi free the buffer deterministically + with ffi.from_buffer(b""): + pass + from_buffer = ffi.from_buffer +except AttributeError: + # cffi < 0.12 frees the buffer with refcounting gc + from contextlib import contextmanager + + @contextmanager + def from_buffer(*args): + yield ffi.from_buffer(*args) |