Skip to content

Commit

Permalink
fix up linux and only destroy work pool if work pool exists
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrh committed Nov 19, 2018
1 parent e9c58a2 commit 7abee8f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions c/py/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
class BrotliEncoderWorkPool(ctypes.Structure):
pass
BrotliEncoderWorkPool= ctypes.POINTER(BrotliEncoderWorkPool)

brotli_library=ctypes.CDLL("../target/release/libbrotli_ffi.dylib")
try:
brotli_library=ctypes.CDLL("../target/release/libbrotli_ffi.dylib")
except OSError:
brotli_library=ctypes.CDLL("../target/release/libbrotli_ffi.so")
_BrotliEncoderCreateWorkPool = brotli_library.BrotliEncoderCreateWorkPool
_BrotliEncoderCreateWorkPool.restype = POINTER(BrotliEncoderWorkPool)
_BrotliEncoderCompressWorkPool = brotli_library.BrotliEncoderCompressWorkPool
Expand Down Expand Up @@ -212,6 +214,7 @@ def main():
BROTLI_PARAM_CATABLE: 0,
BROTLI_PARAM_SIZE_HINT: len(data),
},4 )
BrotliEncoderDestroyWorkPool(work_pool)
else:
encoded = BrotliEncoderCompress(data, {
BROTLI_PARAM_QUALITY:11,
Expand All @@ -222,7 +225,6 @@ def main():
BROTLI_PARAM_SIZE_HINT: len(data),
},4 )
sys.stdout.write(encoded)
BrotliEncoderDestroyWorkPool(work_pool)

if __name__ == "__main__":
main()
Expand Down

0 comments on commit 7abee8f

Please sign in to comment.