-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make preprocess and getIncludePath const functions. #4785
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole thing around closeInput
is ugly, but that is a different problem. Or maybe just add a destructor to PreprocessorResult
that closes the FILE *
if necessary?
The destructor might close the file too early if not handled correctly. I added an explicit function instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of this mess comes from the incompatibility of popen with iostreams.
How could an explicit member function close it after the destructor? That would mean the object is already destructed and the member function can't be called. You might need to define a move operator though (the invalidates the source). |
Would be great if we could call into the preprocessors as a library, would solve a bunch of problems.
Instead of adding the file handle closing in the destructor I just added a member function that can be called. |
I can see that. My point is that you can't call a member function after a destructor. That would mean calling a function on a destructed object, which is UB. So a destructor can't be "too early". The only possible problem with destructor is that there might be multiple copies/moved versions of the same |
With too early I meant what you described, where you have multiple objects and the file handle gets closed prematurely because one of the copies is destroyed. It seems safer to make this explicit instead of worrying about copy/move semantics. |
33d7049
to
3494691
Compare
Well, making the object non-copyable will avoid that (and is much simpler) |
It makes working with the returned object itself a fair bit more involved though. I didn't want to make the return value of the call overly complicated. |
3494691
to
c1c375d
Compare
Usually it makes dealing with the returned object much simpler -- you just return by value and it "just works" and you don't need to do anything special. That's the whole point of movable-not-copyable objects. |
Okay for file handles this does make sense and after rewriting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the change. I suspect the move on the PreprocessorResult
is not used, but if it would, it would be wrong.
frontends/common/parser_options.h
Outdated
PreprocessorResult &operator=(PreprocessorResult &&) = default; | ||
PreprocessorResult(PreprocessorResult &&) = default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work. The default move will do memberwise move, but for primitive types that is just a copy. So we either need to disable the move constructor too (which would probably work, otherwise there is a double-close somewhere now), or explicitly set orig._file = nullptr
in the move operator/ctor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, maybe, one could use std::unique_ptr<FILE, decltype(&fclose)>
This way the owning semantics would be preserved.
Signed-off-by: fruffy <[email protected]>
Signed-off-by: fruffy <[email protected]>
cf9993a
to
70c3f92
Compare
Signed-off-by: fruffy <[email protected]>
70c3f92
to
d90c9f2
Compare
There is no compelling reason why the preprocessing function and the
getIncludePath
function should not be the const. I changed the interface such that these functions can be used as const functions. The only thing that doesn't work is `file = "", not clear to me how it is used.