Pass progress message to cli_progress_bar#897
Pass progress message to cli_progress_bar#897pepijn-devries wants to merge 2 commits intofirelab:mainfrom
Conversation
|
Thanks. I had a couple of concerns with how this might be implemented but I think you've handled it already. This is mainly to check my understanding and confirm what the usage patterns should be.
In other cases we do processing that manages the progress bar directly, updating Line 788 in 5e01782 We don't want to pass the message string in each call to In that first usage mentioned above where we pass a function pointer to GDAL for callback, we could potentially do the same thing and initialize the progress bar ( One other question about the code in |
|
I made an edit above, it should be
instead of |
The message argument will be ignored if it is set to nullptr. There are cases were there is a message is passed to the progress bar:
The message is only set once, for each progress bar (when it is R_NilValue, or when the dfComplete is still 0). In addition, you are not sending a copy of the message with each call, just a pointer to the message. But when dfComplete > 0, the message is ignored anyway, so it is fine to just pass the nullptr.
Do you have example of where GDAL uses the callback and sets the message itself? Then we can test (and possibly fix) the behaviour.
I don't think this setup is causing memory leaks, and I'll explain below why I think this. But it's always better to test if the expected behaviour is also the observed behaviour. I think this can be tested by initiating a progress bar twice (and letting it complete in both cases). If valgrind isn't reporting memory leaks for this test, we are all set. I'm on a Windows machine, so it is really a dread to run those tests. Do you have a CI workflow setup for this package that uses valgrind? So this is what I expect happens: But again, this is what I think happens. But to be sure you can test with valgrind. |
You're right, I think GDAL will pass back non-null pointer in some or all cases, but it should be empty string. I'll try to confirm whether it may be either/or.
We have tests already that create two or more progress bars, one after the other (like a series of tests for a given function, within one test block). Those passed valgrind checks on the first PR, and I can run them again on this one. By default,
I've been running valgrind only manually using the |
It looks like GDAL will pass back either or sometimes both in the same file, e.g., https://github.com/OSGeo/gdal/blob/master/gcore/rasterio.cpp
Right my bad, we would not incur overhead even if the message were passed inside the loop as pointer to the string. When I update the existing code to add message strings, I think it should follow a consistent pattern of initializing |
|
asan, ubsan and valgrind pass on the existing test set |
|
You are correct. This behaviour is problematic when a progress bar is terminated prematurely, and a next progress bar is not initialised with The root cause is that the GDAL API uses 1 callback function for handling the progress bar, and not dedicated functions for initialising and terminating them. At least, I don't think there are. Maybe, close this PR for now until we can come up with a better sollution. |
|
Sure no problem, thanks for investigating it this far. I'll test with it some more before deciding to close if that's alright. I named the At the same time it's tempting to learn how something new works and whether there are implications for the existing code or tests. For example as I mentioned above, it revealed a couple of places where the existing progress bar is managed directly but |
Now includes message to progress bar. As everything has to fit on 1 line, the message is abbreviated to 23 characters.
I also added
CLI_SHOULD_TICKto make sure the progress bar isn't updated unnecessarily. Don't think it was really necessary, but just in case...