Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 44ca0b1

Browse filesBrowse files
committed
Added clib interface file; populated ctypes
1 parent cee124e commit 44ca0b1
Copy full SHA for 44ca0b1

File tree

Expand file treeCollapse file tree

1 file changed

+42
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+42
-0
lines changed

‎docs/scenarios/clibs.rst

Copy file name to clipboard
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Interfacing with C/C++ Libraries
2+
================================
3+
4+
5+
ctypes
6+
------
7+
8+
`ctypes <https://docs.python.org/3/library/ctypes.html>`_ is the de facto
9+
library for interfacing with C/C++, and it provides not only full access to
10+
the native C interface of most major operating systems (e.g., kernel32 on
11+
Windows, or libc on *nix), but also provides support for loading and
12+
interfacing with dynamic libraries, such as DLLs or shared objects at runtime.
13+
It does bring along with it a whole host of types for interacting with system
14+
APIs, and allows you to rather easily define your own complex types, such
15+
as structs and unions, and allows you to modify things such as padding and
16+
alignment, if needed. It can be a bit crufty to use, but in conjunction with
17+
the `struct <https://docs.python.org/3.5/library/struct.html>`_ module, you
18+
are essentially provided full control over how your data types get translated
19+
into something something usable by a C(++).
20+
21+
Struct Equivalents
22+
~~~~~~~~~~~~~~~~~~
23+
24+
:file:`MyStruct.h`
25+
26+
.. code-block:: c
27+
:linenos:
28+
29+
struct my_struct {
30+
int a;
31+
int b;
32+
};
33+
34+
:file:`MyStruct.py`
35+
36+
.. code-block:: python
37+
:linenos:
38+
39+
import ctypes
40+
class my_struct(ctypes.Structure):
41+
_fields_ = [("a", c_int),
42+
("b", c_int)]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.