C and C++ interface¶
C and C++ code reaches a box through two headers that come with the
sharedbox wheel, in the folder that get_include
returns. This page says where each one is specified; to get started, follow
How to accept a box in a C++ extension
instead.
| Header | What it declares | Specified in |
|---|---|---|
sharedbox/sharedbox.hpp, which includes core.hpp and box.hpp |
the C++20 API: sharedbox::handle, sharedbox::result, sharedbox::error, sharedbox::status, sharedbox::type_view and the encode_* and decode_* functions of the value types; the inline namespace is v3 |
sharedbox.hpp |
sharedbox/sharedbox_c.h |
the sbx_* C functions, including sbx_field_desc and the typed reads and writes, and the status codes |
sharedbox_c.h |
| both | sbx_handle, the struct a capsule holds |
Capsule handle |
A C++ program that changes a field from what the box holds, such as an
increment, holds the write lock across its read and its write with
handle::begin_record_write, held_bytes, write_held and
end_record_write, or abort_record_write to give the lock back unchanged;
sharedbox.hpp specifies them. The C
functions have no counterpart.
The Python side of the exchange, __sharedbox_box__ and the capsule it
returns, is specified in
The PyCapsule interface. The
CMake targets are in Build and packaging.
Thread safety¶
Which calls you may make from several threads on one
handle is the same whether you use
sharedbox::handle or an sbx_handle with the C functions. The rules are
listed in sharedbox.hpp.
Errors¶
- Implementation language:
sharedbox::result<T>, which every C++ call that can fail returns, itssharedbox::error, andto_expectedandfrom_expectedon C++23 sharedbox.hpp: what eachsharedbox::statusmeans, includingstatus::os,status::kind_mismatch(a segment of another kind),status::foreign(a magic this version does not know) andstatus::unsupported(a kind this version does not know, inside a field or as a stream item)sharedbox_c.h: theSBX_OKandSBX_E_*codes the C functions return, includingSBX_E_KIND(-11),SBX_E_FOREIGN(-12) andSBX_E_UNSUPPORTED(-18)