Commit 42e6ce74 by Victor M. Alvarez

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](VirusTotal/yara#1377), this
can result in different compilation units using different sizes of
bool type and chaos ensues.
parents 4ab60585 a7e5627b
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
# limitations under the License. # limitations under the License.
# #
from setuptools import setup, Command, Extension
from distutils.command.build import build from distutils.command.build import build
from distutils.command.build_ext import build_ext from distutils.command.build_ext import build_ext
from setuptools import setup, Command, Extension
from codecs import open from codecs import open
import distutils.errors import distutils.errors
...@@ -87,6 +87,23 @@ def has_function(function_name, libraries=None): ...@@ -87,6 +87,23 @@ def has_function(function_name, libraries=None):
return result 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): class BuildCommand(build):
user_options = build.user_options + OPTIONS user_options = build.user_options + OPTIONS
...@@ -221,6 +238,9 @@ class BuildExtCommand(build_ext): ...@@ -221,6 +238,9 @@ class BuildExtCommand(build_ext):
module.define_macros.append(('USE_NO_PROC', '1')) module.define_macros.append(('USE_NO_PROC', '1'))
module.extra_compile_args.append('-std=c99') module.extra_compile_args.append('-std=c99')
if has_header('stdbool.h'):
module.define_macros.append(('HAVE_STDBOOL_H', '1'))
if has_function('memmem'): if has_function('memmem'):
module.define_macros.append(('HAVE_MEMMEM', '1')) module.define_macros.append(('HAVE_MEMMEM', '1'))
if has_function('strlcpy'): if has_function('strlcpy'):
...@@ -240,6 +260,9 @@ class BuildExtCommand(build_ext): ...@@ -240,6 +260,9 @@ class BuildExtCommand(build_ext):
module.define_macros.append(('HASH_MODULE', '1')) module.define_macros.append(('HASH_MODULE', '1'))
module.define_macros.append(('HAVE_LIBCRYPTO', '1')) module.define_macros.append(('HAVE_LIBCRYPTO', '1'))
module.libraries.append('crypto') module.libraries.append('crypto')
elif building_for_windows:
module.define_macros.append(('HASH_MODULE', '1'))
module.define_macros.append(('HAVE_WINCRYPT_H', '1'))
else: else:
exclusions.append('yara/libyara/modules/hash/hash.c') exclusions.append('yara/libyara/modules/hash/hash.c')
......
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