Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- file testc.py:
- #!/usr/bin/env python3
- from ctypes import *
- lib = cdll.LoadLibrary('./libtestas.so.1.0')
- f_array_1 = (c_float * 16)(*range(16))
- f_array_2 = (c_float * 16)(*range(16))
- print("f_array_1:");
- for i in range(0,16):
- print(f_array_1[i], ' ', end = '', flush=True)
- print("\nf_array_2 (before):")
- for i in range(0,16):
- f_array_2[i] = 0.0
- print(f_array_2[i], ' ', end = '', flush=True)
- retval = c_bool()
- lib.arrTst.restype=c_bool
- retval = lib.arrTst(byref(f_array_1), byref(f_array_2), 16)
- if retval:
- print("\nERROR: arrTst")
- else:
- print("\nf_array_2 (after):")
- for i in range(0,16):
- print(f_array_2[i], ' ', end = '', flush=True)
- print(" ")
- */
- /*
- build shared library:
- gcc -fPIC -c testas.c
- ld -shared -soname libtestas.so.1 -o libtestas.so.1.0 -lc testas.o
- file testc.py, make executable:
- chmod +x testc.py
- run:
- ./testc.py
- */
- //file testas.c:
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <stdint.h>
- void _init()
- {
- printf("init\n");
- }
- void _fini()
- {
- printf("fini\n");
- }
- bool arrTst(float *inp, float *outp, uint32_t numOfE)
- {
- uint32_t offset = 0;
- if(offset<numOfE)
- {
- for(; offset<numOfE; ++offset)
- {
- outp[offset] = inp[offset];
- }
- }
- else return 1;
- return 0;
- }
- /*
- output:
- init
- f_array_1:
- 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0
- f_array_2 (before):
- 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
- f_array_2 (after):
- 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0
- fini
- */
Advertisement
Add Comment
Please, Sign In to add comment