Converting from R to C
- No work needs to be done, the native igraph object is stored as an external pointer in the
igraph_t_idx_env part of the data structure.
- When the R graph object is destroyed, it will be garbage-collected eventually. This triggers the finalizer of the external pointer object, which can be made to call destructors in igraph/C.
Converting from C to R
- We keep the native
igraph_t object and store it as an external pointer in the igraph_t_idx_env part of the data structure.
- We also keep all the information needed to recreate the native
igraph_t object in the igraph_t_idx_n, igraph_t_idx_directed, igraph_t_idx_from and igraph_t_idx_to components
- The native
igraph_t object may be lost, e.g., during serialization. In this case, we recreate the native igraph_t object from the igraph_t_idx_n, igraph_t_idx_directed, igraph_t_idx_from and igraph_t_idx_to components
Attributes
All attributes are still handled only from R for now. But because the native igraph_t object may cache R-level attributes, we need to be especially careful about this.
Implementation steps
Follow-up to #783.
Converting from R to C
igraph_t_idx_envpart of the data structure.Converting from C to R
igraph_tobject and store it as an external pointer in theigraph_t_idx_envpart of the data structure.igraph_tobject in theigraph_t_idx_n,igraph_t_idx_directed,igraph_t_idx_fromandigraph_t_idx_tocomponentsigraph_tobject may be lost, e.g., during serialization. In this case, we recreate the nativeigraph_tobject from theigraph_t_idx_n,igraph_t_idx_directed,igraph_t_idx_fromandigraph_t_idx_tocomponentsAttributes
All attributes are still handled only from R for now.
But because the nativeigraph_tobject may cache R-level attributes, we need to be especially careful about this.Implementation steps
unclass(g)useigraph_t_idx_*, no magic numbers (chore: Ensure we're always using named indexes to access the internal data structure #784)igraph_t_idx_n,igraph_t_idx_directed,igraph_t_idx_fromandigraph_t_idx_toin Cigraph_t_idx_*from R, at all (we can keep usingigraph_attr_idx_*)igraph_tas external pointer inigraph_t_idx_envigraph_tis an external pointer stored inunclass(graph)[[igraph_t_idx_env]]$igraphigraph_tigraph_tfromigraph_t_idx_n,igraph_t_idx_directed,igraph_t_idx_fromandigraph_t_idx_toif the external pointer is goneunserialize(serialize(graph, NULL))to testigraph_t_idx_oi...igraph_t_idx_isin Rigraph_t_idx_fromandigraph_t_idx_to(requires R 4.0)INOUTinfunctions.yaml)Follow-up to #783.