-
Notifications
You must be signed in to change notification settings - Fork 24
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
Define read, write, close, poll and ppoll with parameters #30
Comments
Sounds reasonable to me. Yeah, the current design has that problem with structs that contain members called So the downside with function like macros is that this code no longer works for "epoll-like" fds, right? #define close(fd) epoll_shim_close(fd)
int (*close_fp)(int) = &close;
close_fp(some_fd); I am not aware of any consumers of epoll-shim using that pattern, but now I am aware of consumers using I really don't want that valid code written for Linux that uses |
That would be correct. I assume you have read the issue linked by @cglogic (since your example looks like it was copied from there)? I just wanted to push the fact that we (foot) have worked around this and by no means depend on #31. It would be a nice-to-have, but I have no idea whether it would break other applications :) |
If there are no known consumers that work with pointers to functions this can help in porting software like foot. I'm not sure what is the best solution here. |
Another fun thing I noticed while playing around with this is that C's function like macros don't interact well with compound literals, so something like this errors out: I'm now looking at defining the wrapper macros like this: I can think of two more problems with that approach, but luckily there are workarounds:
int fd;
struct conflict conflict = {
.close = conflict_close,
.read = conflict_read,
};
(conflict.close)(fd);
#define NO_MACRO_EXPAND /**/
ssize_t
read NO_MACRO_EXPAND(int fd, void *buf, size_t count)
{
...
} The preprocessor will detect another token between the |
Nice catch. Dealing with all cases is a bit tricky. |
Found that #31 break building multimedia/v4l-utils on FreeBSD. |
Is it because of Luckily, such usages of echo " stream.close()" | sed -e 's|\([^[:space:]]*\.close\)(|(\1)(|g' In addition, I guess For example, in this case here, the #include <sys/epoll.h>
#include <fstream>
#include <iostream>
int main() {
std::ifstream f;
f.close();
int ep = epoll_create1(0);
close(ep);
}
We could have some way of deferring the definition of the wrapper macros, for example like this: #define EPOLL_SHIM_NO_WRAPPER_MACROS
#include <sys/epoll.h>
#include <fstream>
#include <iostream>
#include <epoll-shim/wrapper-macros.h>
int main() {
std::ifstream f;
(f.close)();
int ep = epoll_create1(0);
close(ep);
}
Even the insertion of the
|
Sorry for the delay. After adding parameters for the macro The error:
struct v4l_fd {
...
int (*close)(struct v4l_fd *f);
...
}; |
For corner cases like the above, the library now provides Closing this for now. |
Defining
close
and friends without arguments has border cases with include order.Maybe it has a sense to change the definitions from
#define close epoll_shim_close
to#define close(fd) epoll_shim_close(fd)
? But this change breaks function pointer assignments. What do you think? I can create pull request this change has sense for you.Please see for details https://codeberg.org/dnkl/foot/issues/500#issuecomment-197764
The text was updated successfully, but these errors were encountered: