contrib/python-zstandard/make_cffi.py
branchstable
changeset 37788 ed5448edcbfa
parent 37495 b1fb341d8a61
child 40121 73fef626dae3
--- a/contrib/python-zstandard/make_cffi.py	Wed Apr 04 10:35:09 2018 -0400
+++ b/contrib/python-zstandard/make_cffi.py	Wed Apr 18 15:32:08 2018 -0400
@@ -27,6 +27,11 @@
     'compress/fse_compress.c',
     'compress/huf_compress.c',
     'compress/zstd_compress.c',
+    'compress/zstd_double_fast.c',
+    'compress/zstd_fast.c',
+    'compress/zstd_lazy.c',
+    'compress/zstd_ldm.c',
+    'compress/zstd_opt.c',
     'compress/zstdmt_compress.c',
     'decompress/huf_decompress.c',
     'decompress/zstd_decompress.c',
@@ -38,7 +43,6 @@
 # Headers whose preprocessed output will be fed into cdef().
 HEADERS = [os.path.join(HERE, 'zstd', *p) for p in (
     ('zstd.h',),
-    ('compress', 'zstdmt_compress.h'),
     ('dictBuilder', 'zdict.h'),
 )]
 
@@ -80,7 +84,9 @@
 def preprocess(path):
     with open(path, 'rb') as fh:
         lines = []
-        for l in fh:
+        it = iter(fh)
+
+        for l in it:
             # zstd.h includes <stddef.h>, which is also included by cffi's
             # boilerplate. This can lead to duplicate declarations. So we strip
             # this include from the preprocessor invocation.
@@ -137,18 +143,21 @@
 
 
 ffi = cffi.FFI()
+# zstd.h uses a possible undefined MIN(). Define it until
+# https://github.com/facebook/zstd/issues/976 is fixed.
 # *_DISABLE_DEPRECATE_WARNINGS prevents the compiler from emitting a warning
 # when cffi uses the function. Since we statically link against zstd, even
 # if we use the deprecated functions it shouldn't be a huge problem.
 ffi.set_source('_zstd_cffi', '''
-#include "mem.h"
+#define MIN(a,b) ((a)<(b) ? (a) : (b))
 #define ZSTD_STATIC_LINKING_ONLY
-#include "zstd.h"
+#include <zstd.h>
 #define ZDICT_STATIC_LINKING_ONLY
 #define ZDICT_DISABLE_DEPRECATE_WARNINGS
-#include "zdict.h"
-#include "zstdmt_compress.h"
-''', sources=SOURCES, include_dirs=INCLUDE_DIRS)
+#include <zdict.h>
+''', sources=SOURCES,
+     include_dirs=INCLUDE_DIRS,
+     extra_compile_args=['-DZSTD_MULTITHREAD'])
 
 DEFINE = re.compile(b'^\\#define ([a-zA-Z0-9_]+) ')