Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def verify(ffi, module_name, source, *args, **kwds):
no_cpp = kwds.pop('no_cpp', False)
kwds.setdefault('undef_macros', ['NDEBUG'])
module_name = '_CFFI_' + module_name
ffi.set_source(module_name, source)
if not os.environ.get('NO_CPP') and not no_cpp: # test the .cpp mode too
kwds.setdefault('source_extension', '.cpp')
source = 'extern "C" {\n%s\n}' % (source,)
elif sys.platform != 'win32':
# add '-Werror' to the existing 'extra_compile_args' flags
kwds['extra_compile_args'] = (kwds.get('extra_compile_args', []) +
['-Werror'])
return recompiler._verify(ffi, module_name, source, *args, **kwds)
def verify(self, preamble='', *args, **kwds):
# HACK to reuse the tests from ../cffi0/test_verify.py
FFI._verify_counter += 1
module_name = 'verify%d' % FFI._verify_counter
try:
del self._assigned_source
except AttributeError:
pass
self.set_source(module_name, preamble)
return recompiler._verify(self, module_name, preamble, *args,
extra_compile_args=self._extra_compile_args,
**kwds)
def build_cffi(base_path, **extra):
# dylib
dylib = self.dylib()
if callable(dylib):
dylib = dylib()
log.info('copying dylib %s', os.path.basename(dylib))
shutil.copy2(dylib, os.path.join(base_path, self.lib_filename))
# generate cffi module
ffi = make_ffi()
log.info('generating cffi module for %r' % self.module_path)
py_file = os.path.join(
base_path, self.cffi_module_path.split('.')[-1]) + '.py'
updated = cffi_recompiler.make_py_source(
ffi, self.cffi_module_path, py_file)
if not updated:
log.info('already up-to-date')
# wrapper
log.info('generating wrapper for %r' % self.module_path)
with open(os.path.join(base_path, self.name + '.py'), 'wb') as f:
f.write((MODULE_PY % {
'cffi_module_path': self.cffi_module_path,
'lib_filename': self.lib_filename,
'rtld_flags': self.rtld_flags,
}).encode('utf-8'))
self.spec.add_build_func(build_cffi, module_base=self.module_base)
def generate_mod(py_file):
log.info("generating cffi module %r" % py_file)
mkpath(os.path.dirname(py_file))
updated = recompiler.make_py_source(ffi, module_name, py_file)
if not updated:
log.info("already up-to-date")
def generate_mod(py_file):
log.info("generating cffi module %r" % py_file)
mkpath(os.path.dirname(py_file))
updated = recompiler.make_py_source(ffi, module_name, py_file)
if not updated:
log.info("already up-to-date")
def generate_mod(py_file):
log.info("generating cffi module %r" % py_file)
mkpath(os.path.dirname(py_file))
updated = recompiler.make_py_source(ffi, module_name, py_file)
if not updated:
log.info("already up-to-date")