Skip to content

Commit

Permalink
More idiomatic variant
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Jun 7, 2023
1 parent 0343292 commit f4f905a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cffi/array_printer_5/call_via_cffi2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pathlib

from cffi import FFI

ffi = FFI()

def load_header(filename):
directory = pathlib.Path().absolute()
header = directory / filename
with open(header) as fin:
return fin.read()


def load_library(library_name):
return ffi.dlopen(library_name)


ffi.cdef(load_header("array_printer.h"))

array = ffi.new("vector_t[10]")

for i, item in enumerate(array):
item.x = i
item.y = 2*i
item.z = 1 / (1+i)

printer = load_library("libaprinter.so")
printer.print_array(array, len(array))

0 comments on commit f4f905a

Please sign in to comment.