Unverified Commit a7e5627b by Marek Milkovič Committed by GitHub

Added check for stdbool.h header and forcing its use (#159)

When compiling YARA without Python bindings, stdbool.h is actually used
if it can be used. However Python bindings completely ignore it resulting
in YARA defining its own bool type with sizeof(bool) == sizeof(int).
However before [#1377](https://github.com/VirusTotal/yara/pull/1377), this
can result in different compilation units using different sizes of
bool type and chaos ensues.
parent b6ed9fc3
......@@ -87,6 +87,23 @@ def has_function(function_name, libraries=None):
return result
def has_header(header_name):
compiler = distutils.ccompiler.new_compiler()
with muted(sys.stdout, sys.stderr):
with tempfile.NamedTemporaryFile(mode='w', prefix=header_name, delete=False, suffix='.c') as f:
f.write("""
#include <{}>
int main() {{ return 0; }}
""".format(header_name))
f.close()
try:
compiler.compile([f.name])
except distutils.errors.CompileError:
return False
return True
class BuildCommand(build):
user_options = build.user_options + OPTIONS
......@@ -221,6 +238,9 @@ class BuildExtCommand(build_ext):
module.define_macros.append(('USE_NO_PROC', '1'))
module.extra_compile_args.append('-std=c99')
if has_header('stdbool.h'):
module.define_macros.append(('HAVE_STDBOOL_H', '1'))
if has_function('memmem'):
module.define_macros.append(('HAVE_MEMMEM', '1'))
if has_function('strlcpy'):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment