Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
r->m_numInvokes = count;
}
/* Logging */
#include
void (*python_log_callback)(int level, char *msg);
void c_log_callback(int level, const char *fmt, va_list args) {
char buf[2048];
vsprintf(buf, fmt, args);
python_log_callback(level, buf);
}
"""
verifier = Verifier(ffi, preamble, libraries=["rtmp"],
ext_package="librtmp_ffi", modulename="_binding",
sources=["src/librtmp/amf.c"])
def test_write_source(self):
ffi = FFI()
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!*/\n#include \n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
libraries=[self.lib_m])
v.write_source()
with open(v.sourcefilename, 'r') as f:
data = f.read()
assert csrc in data
def test_compile_module_explicit_filename(self):
ffi = FFI()
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!2*/\n#include \n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
libraries=[self.lib_m])
basename = self.__class__.__name__ + 'test_compile_module'
v.modulefilename = filename = str(udir.join(basename + '.so'))
v.compile_module()
assert filename == v.modulefilename
assert v.get_module_name() == basename
if v.generates_python_module():
mod = imp.load_dynamic(v.get_module_name(), v.modulefilename)
assert hasattr(mod, '_cffi_setup')
def test_verifier_args(self):
ffi = FFI()
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!4*/#include "test_verifier_args.h"\n' % self
udir.join('test_verifier_args.h').write('#include \n')
v = Verifier(ffi, csrc, include_dirs=[str(udir)],
force_generic_engine=self.generic,
libraries=[self.lib_m])
library = v.load_library()
assert library.sin(12.3) == math.sin(12.3)
# case that anonymous enums would produce '$enum_$1', which was
# used as part of a function name. GCC accepts such names, but it's
# apparently non-standard.
_r_comment = re.compile(r"/\*.*?\*/|//.*?$", re.DOTALL | re.MULTILINE)
_r_string = re.compile(r'\".*?\"')
def _write_source_and_check(self, file=None):
base_write_source(self, file)
if file is None:
f = open(self.sourcefilename)
data = f.read()
f.close()
data = _r_comment.sub(' ', data)
data = _r_string.sub('"skipped"', data)
assert '$' not in data
base_write_source = cffi.verifier.Verifier._write_source
cffi.verifier.Verifier._write_source = _write_source_and_check
def test_load_library(self):
ffi = FFI()
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!3*/\n#include \n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
libraries=[self.lib_m])
library = v.load_library()
assert library.sin(12.3) == math.sin(12.3)
_FILE_PATH = os.path.dirname(os.path.realpath(__file__))
os.chdir(_FILE_PATH)
os.chdir(os.pardir)
#use the absolute path to load the file here so we don't have to worry about working directory issues
_CDEF = open("{}/py_fourd.h".format(_FILE_PATH)).read()
ffi.cdef(_CDEF)
_SOURCE = """
#include "fourd.h"
"""
source_files = glob.glob('lib4d_sql/*.c')
ffi.verifier = Verifier(ffi, _SOURCE,
modulename=_create_modulename(_CDEF, _SOURCE, sys.version),
sources=source_files,
include_dirs=['lib4d_sql', 'py4d/lib4d_sql'])
#ffi.verifier.compile_module = _compile_module
#ffi.verifier._compile_module = _compile_module
lib4d_sql = LazyLoadLib(ffi)
os.chdir(_CWD)
########################################################################
########################################################################
## Error Classes
########################################################################
int crypto_hash_sha512(unsigned char *out, const unsigned char *in, unsigned long long inlen);
"""
# Secure Random
"""
void randombytes(unsigned char * const buf, const unsigned long long buf_len);
"""
# Low Level - Scalar Multiplication
"""
int crypto_scalarmult_curve25519_base(unsigned char *q, const unsigned char *n);
"""
)
ffi.verifier = cffi.verifier.Verifier(ffi,
"#include ",
# We need to link to the sodium library
libraries=["sodium"],
# Our ext_package is nacl so look for it
ext_package="nacl",
)
# This works around a bug in PyPy where CFFI exposed functions do not have a
# __name__ attribute. See https://bugs.pypy.org/issue1452
def wraps(wrapped):
def inner(func):
if hasattr(wrapped, "__name__"):
return functools.wraps(wrapped)(func)