Strategies for finding binary dependencies
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add cffi example

+59
+3
contrib/cffi/.gitignore
··· 1 + *.so 2 + *.c 3 + *.o
+11
contrib/cffi/REUSE.toml
··· 1 + version = 1 2 + 3 + [[annotations]] 4 + path = [ 5 + ".gitignore", 6 + "*.so", 7 + "*.c", 8 + "*.o", 9 + ] 10 + SPDX-FileCopyrightText = "NONE" 11 + SPDX-License-Identifier = "CC0-1.0"
+11
contrib/cffi/abi.py
··· 1 + # © NONE 2 + # SPDX-License-Identifier: CC0-1.0 3 + 4 + from cffi import FFI 5 + ffi = FFI() 6 + ffi.cdef(""" 7 + int printf(const char *format, ...); // copy-pasted from the man page 8 + """) 9 + C = ffi.dlopen(None) # loads the entire C namespace 10 + arg = ffi.new("char[]", b"world") # equivalent to C code: char arg[] = "world"; 11 + C.printf(b"hi there, %s.\n", arg) # call printf
+34
contrib/cffi/api.py
··· 1 + # © NONE 2 + # SPDX-License-Identifier: CC0-1.0 3 + 4 + from cffi import FFI 5 + ffibuilder = FFI() 6 + 7 + ffibuilder.set_source("_example", 8 + r""" // passed to the real C compiler, 9 + // contains implementation of things declared in cdef() 10 + #include <sys/types.h> 11 + #include <pwd.h> 12 + 13 + // We can also define custom wrappers or other functions 14 + // here (this is an example only): 15 + static struct passwd *get_pw_for_root(void) { 16 + return getpwuid(0); 17 + } 18 + """, 19 + libraries=[]) # or a list of libraries to link with 20 + # (more arguments like setup.py's Extension class: 21 + # include_dirs=[..], extra_objects=[..], and so on) 22 + 23 + ffibuilder.cdef(""" 24 + // declarations that are shared between Python and C 25 + struct passwd { 26 + char *pw_name; 27 + ...; // literally dot-dot-dot 28 + }; 29 + struct passwd *getpwuid(int uid); // defined in <pwd.h> 30 + struct passwd *get_pw_for_root(void); // defined in set_source() 31 + """) 32 + 33 + if __name__ == "__main__": 34 + ffibuilder.compile(verbose=True)