Skip to content

Commit f2fb1bd

Browse files
committed
renamed functions libraries and build products
1 parent 570ef0e commit f2fb1bd

File tree

11 files changed

+37
-39
lines changed

11 files changed

+37
-39
lines changed

python-bindings/overview_article/c_function.h

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python3
2-
import _c_function
2+
import cffi_example
33

44
if __name__ == "__main__":
55
# sample data for our call:
66
x, y = 6, 2.3
77

8-
answer = _c_function.c_function(x, y)
8+
answer = cffi_example.lib.cmult(x, y)
99
print(f" In Python: int: {x} float {y:.1f} return val {answer:.1f}")

python-bindings/overview_article/c_function.c renamed to python-bindings/overview_article/cmult.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include <stdio.h>
2-
#include "c_function.h"
2+
#include "cmult.h"
33

44

5-
float c_function(int int_param, float float_param) {
5+
float cmult(int int_param, float float_param) {
66
float return_value = int_param * float_param;
7-
printf(" In c_func: int: %d float %.1f returning %.1f\n", int_param,
7+
printf(" In cmult : int: %d float %.1f returning %.1f\n", int_param,
88
float_param, return_value);
99
return int_param * float_param;
1010
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
float cmult(int int_param, float float_param);

python-bindings/overview_article/cpp_function.hpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

python-bindings/overview_article/cpp_function.cpp renamed to python-bindings/overview_article/cppmult.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include <stdio.h>
2-
#include "cpp_function.hpp"
2+
#include "cppmult.hpp"
33

44

5-
float cpp_mult(int int_param, float float_param) {
5+
float cppmult(int int_param, float float_param) {
66
float return_value = int_param * float_param;
7-
printf(" In c_func: int: %d float %.1f returning %.1f\n", int_param,
7+
printf(" In cppmul: int: %d float %.1f returning %.1f\n", int_param,
88
float_param, return_value);
99
return int_param * float_param;
1010
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
float cppmult(int int_param, float float_param);

python-bindings/overview_article/ctypes_test.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,22 @@
66

77
if __name__ == "__main__":
88
# load the shared library into c types.
9-
libname = pathlib.Path().absolute() / "libc_function.so"
9+
libname = pathlib.Path().absolute() / "libcmult.so"
1010
c_lib = ctypes.CDLL(libname)
1111

1212
# sample data for our call:
13-
x = 6
14-
y = 2.3
13+
x, y = 6, 2.3
1514

1615
# This will not work:
17-
# answer = c_lib.c_function(6, 2.3)
16+
# answer = c_lib.cmult(x, y)
1817

1918
# This produces a bad answer:
20-
answer = c_lib.c_function(6, ctypes.c_float(2.3))
19+
answer = c_lib.cmult(x, ctypes.c_float(y))
2120
print(f" In Python: int: {x} float {y:.1f} return val {answer:.1f}")
2221
print()
2322

2423
# You need tell ctypes that the function returns a float
25-
c_function = c_lib.c_function
26-
c_function.restype = ctypes.c_float
27-
answer = c_function(6, ctypes.c_float(2.3))
24+
c_lib.cmult.restype = ctypes.c_float
25+
answer = c_lib.cmult(x, ctypes.c_float(y))
2826
print(f" In Python: int: {x} float {y:.1f} return val {answer:.1f}")
2927

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env python
22
""" Simple examples of calling C functions through ctypes module. """
3-
import example
3+
import pybind11_example
44

55

66
if __name__ == "__main__":
77
# sample data for our call:
88
x = 6
99
y = 2.3
1010

11-
answer = example.cpp_function(x, y)
11+
answer = pybind11_example.cpp_function(x, y)
1212
print(f" In Python: int: {x} float {y:.1f} return val {answer:.1f}")
1313

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <pybind11/pybind11.h>
2-
#include <cpp_function.hpp>
2+
#include <cppmult.hpp>
33

44

5-
PYBIND11_MODULE(example, m) {
5+
PYBIND11_MODULE(pybind11_example, m) {
66
m.doc() = "pybind11 example plugin"; // optional module docstring
7-
m.def("cpp_function", &cpp_mult, "A function which multiplies two numbers");
7+
m.def("cpp_function", &cppmult, "A function which multiplies two numbers");
88
}
99

0 commit comments

Comments
 (0)