Conversation
|
Thanks. Do we need to free this memory? Can you please run with sanitizers to double-check? |
Ah, yes. Right, we need free. Mixing different languages during the day makes me forgetting about this. |
|
Yes, we'll need There are two kinds of functions, which are not currently distinguished by their naming, but they probably should:
An example of a top-level function that this PR touches is An example of an internal function is It would be good to eventually start distinguishing them by using different naming, as they need to handle errors differently. Inside of internal functions, always wrap any igraph function that returns an error code in int R_SEXP_to_vector_int_copy(SEXP sv, igraph_vector_int_t *v) {
long int i, n=GET_LENGTH(sv);
int *svv=INTEGER(sv);
IGRAPH_CHECK(igraph_vector_int_init(v, n)); // this needed an IGRAPH_CHECK
for (i = 0; i<n; i++) {
VECTOR(*v)[i] = svv[i];
}
return IGRAPH_SUCCESS; // use IGRAPH_SUCCESS instead of 0 for clarity
}Question to @krlmlr and @Antonov548 regarding At this point, the R code should be passing a |
|
Now regarding top-level functions, I'll have to think a little bit about the correct approach here: Is it safe to just wrap internal functions in |
Yes, it expects I'm agree that we need to have separate top-level function and internal functions to have more proper error handling. Maybe even split them do different files. I suggest to not make refactoring in this pull request if you (@szhorvat) don't mind. Because we could go really deep and stuck with refactoring of error handling. Maybe it make sense to do this after 0.10. |
|
Tested with sanitizer. No errors 👍 |
Agreed. My point is that when you write new code, make sure it already handles errors properly, so it wouldn't have to be refactored again. |
|
Thanks. Do we now need to do the same for numeric vectors? |
|
We will need to copy "from" and "to" vectors, but we can memory-map, e.g., weights and other numeric vectors. |
For 0.10 integer type will be
int64and on R side such vectors should be copied with conversion to double typefor: #840