In my attempt to debug Segmentation fault when running test example neatopack.c (#1800) · Issues · graphviz / graphviz · GitLab I’ve started to remove warnings in parts of the source code that the backtrace touches.
I’ve now started to touch things related to sizes. There are an enormous amount of warnings like:
warning: conversion to ‘size_t {aka long unsigned int}’ from ‘int’ may change the sign of the result [-Wsign-conversion]
I don’t think we can rule out that no real bugs are hiding behind such warnings and I would like to get rid of them. Just casting int
to size_t
upon usage would just hide potential bugs and therefore I would like to change also the types of arguments and local variables to size_t
where appropriate. In order for this to be doable, I would like to change the public API to use size_t
for sizes where it today uses int or long. As an example:
-Agraph_t** ccomps (Agraph_t*, int*, char*);
+Agraph_t** ccomps (Agraph_t*, size_t*, char*);
Obviously, this would be a breaking change of the API and I guess we would need to step the Graphviz major version to 3 if we were to actually do this.
How do you feel about doing such a change?
Making a breaking change is not something we would want to do often, so if we are going to do it I think we should revise the whole API with respect to types so that it can remain stable once the work is finished
If we were to do it, it would be a quite substantial amount of work and it would take some time before it’s finished, but the code would be much more robust afterwards.
Another example that is not as straightforward is aginit
where the rec_size
argument means that aginit
should do a recursive init if it’s negative. To be able to change the type to size_t
, we need to also add a new argument for the recursive option:
-void aginit(Agraph_t * g, int kind, char *rec_name, int rec_size, int move_to_front);
+void aginit(Agraph_t * g, int kind, char *rec_name, size_t rec_size, int recur, int move_to_front);
I’ve pushed two commits containing more elaborate versions of the above changes to Commits · use-size_t-in-public-api · Magnus Jacobsson / graphviz · GitLab so you can more easily review what I mean. Obviously it doesn’t compile since I haven’t changed the call sites of aginit
.
Please let me know your thoughts.