-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Be more careful with move semantics in type casters
This commit addresses a serious issue involving combinations of bound types (e.g., ``T``) and type casters (e.g., ``std::vector<T>``), where nanobind was too aggressive in its use of move semantics. Calling a bound function from Python taking such a list (e.g., ``f([t1, t2, ..])``) would lead to the destruction of the Python objects ``t1, t2, ..`` if the type ``T`` exposed a move constructor, which is highly non-intuitive. This commit fixes, simplifies, and documents the rules of this process. In particular, ``type_caster::Cast`` continues to serve its role to infer what types a type caster can and wants to produce. It aggressively tries to move, but now only does so when this is legal (i.e., when the type caster created a temporary copy that is safe to move without affecting program state elsewhere). This involves two new default casting rules: ``movable_cast_t`` (adapted to be more aggressive with moves) and ``precise_cast_t`` for bound types that does not involve a temporary and consequently should only move when this was explicitly requested by the user. The fix also revealed inefficiencies in the previous implementation where moves were actually possible but not done (e.g. for functions taking an STL list by value). Some binding projects may see speedups as a consequence of this change. Fixes issue #307.
- Loading branch information
Showing
22 changed files
with
205 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.