Skip to content

Commit 73563ff

Browse files
committed
Add Doxygen-style documentation to C NIF code
Add documentation to all C source files: - py_nif.h: Architecture overview, type definitions with field docs, function declarations with @param/@return/@note - py_convert.c: Type mapping tables, memory management notes, detailed conversion behavior - py_exec.c: GIL management patterns, execution flow diagrams, timeout mechanism explanation - py_callback.c: Suspension/resume flow diagram, callback module usage examples Documentation follows Doxygen conventions with @file, @brief, @author, @defgroup, @Par, @pre, @warning, @see for cross-references.
1 parent 90ec280 commit 73563ff

4 files changed

Lines changed: 1283 additions & 178 deletions

File tree

c_src/py_callback.c

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,73 @@
1+
/**
2+
* @file py_callback.c
3+
* @brief Erlang callback support and asyncio integration
4+
* @author Benoit Chesneau
5+
* @copyright 2026 Benoit Chesneau. Licensed under Apache License 2.0.
6+
*
7+
* @ingroup cb
8+
*
9+
* This module implements bidirectional calling between Python and Erlang,
10+
* enabling Python code to invoke Erlang functions and await their results.
11+
*
12+
* @par Features
13+
*
14+
* - **erlang module**: Python module providing `erlang.call()` and `erlang.func()`
15+
* - **Suspension/Resume**: Reentrant callbacks without blocking dirty schedulers
16+
* - **Asyncio support**: Background event loop for async Python operations
17+
*
18+
* @par Suspension Mechanism
19+
*
20+
* When Python calls `erlang.call('func', args)`:
21+
*
22+
* ```
23+
* ┌────────────┐ ┌─────────────┐ ┌──────────────┐
24+
* │ Python │ raises │ Executor │ returns │ Erlang │
25+
* │ Code │ ──────> │ Catches │ ──────> │ Callback │
26+
* └────────────┘ Suspend │ Exception │ suspend └──────────────┘
27+
* └─────────────┘ │ │
28+
* │ │ result
29+
* ┌─────────────┐ │ │
30+
* │ Resume │ <──────────────┘
31+
* │ Replay │
32+
* └─────────────┘
33+
* │
34+
* v
35+
* ┌────────────┐
36+
* │ Continue │
37+
* │ Python │
38+
* └────────────┘
39+
* ```
40+
*
41+
* @par Why Suspension?
42+
*
43+
* Without suspension, Python calling Erlang would block a dirty scheduler
44+
* while waiting for the Erlang callback to complete. With suspension:
45+
*
46+
* 1. Dirty scheduler is released immediately
47+
* 2. Erlang callback runs on normal scheduler
48+
* 3. Result is stored, Python is replayed on dirty scheduler
49+
*
50+
* @par The 'erlang' Python Module
51+
*
52+
* Provides two calling syntaxes:
53+
*
54+
* ```python
55+
* # Explicit call
56+
* result = erlang.call('my_function', arg1, arg2)
57+
*
58+
* # Attribute-style call (via __getattr__)
59+
* result = erlang.my_function(arg1, arg2)
60+
* ```
61+
*
62+
* @par Thread Safety
63+
*
64+
* - Thread-local storage tracks current worker and suspended state
65+
* - Async event loop runs in dedicated thread
66+
* - Pending futures queue protected by mutex
67+
*
68+
* @note This file is included from py_nif.c (single compilation unit)
69+
*/
70+
171
/*
272
* Copyright 2026 Benoit Chesneau
373
*
@@ -14,19 +84,6 @@
1484
* limitations under the License.
1585
*/
1686

17-
/**
18-
* py_callback.c - Erlang callback module and asyncio support
19-
*
20-
* This module handles:
21-
* - Erlang callback module for Python (erlang.call())
22-
* - Suspended state for reentrant callbacks
23-
* - Resume callback NIFs
24-
* - Asyncio event loop and futures
25-
* - Sub-interpreter support
26-
*/
27-
28-
/* Note: This file is included from py_nif.c after py_nif.h, py_convert.c, py_exec.c */
29-
3087
/* ============================================================================
3188
* Suspended state management
3289
* ============================================================================ */

0 commit comments

Comments
 (0)