-
Notifications
You must be signed in to change notification settings - Fork 1.3k
generate errno definitions from CSV #15579
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
base: master
Are you sure you want to change the base?
Conversation
[Experimental Bot, please feedback here] Fill In The Commit Message: This PR contains a Commit with an Empty Commit Message. Please fill in the Commit Message with the PR Summary. This PR does not fully meet the NuttX requirements. While it provides a summary of what is being changed, it lacks crucial details. Here's what's missing:
The PR needs to provide significantly more detail to be considered complete. Addressing the above points will make it easier for reviewers to understand and evaluate the change. |
i have a question: is python acceptable for this kind of tools these days? |
I don't think so, or I missed something. If the build system is to depend on python, then this is a more serious issue to discuss in the community. Or was it introduced quietly and no one noticed? EDIT: if python is used to generate the file, but not when build process, then it's probably OK? |
the script this PR added (mkerrno.py) is not meant to be used during a build. otoh, some of existing python scripts in the tools dir seem to be used during a build. |
then it's definitely ok.
yeah, I just saw this. So it was introduced without much discussion and even requirements in the documentation hasn't been updated. I see it's only for the case when KASAN is enabled, but this doesn't change the fact that python is now required to build.... |
@yamt what's the benefit to generate the errno from a csv, but not modify errno.h direclty? |
i want to generate other things as well, which are difficult or impossible with C preprocessor. #if defined(EPERM)
case EPERM: return NUTTX_EPERM;
#endif |
I still can't fully understand what you want to achieve with this code snippet, could you explain more? In most case, it's be better to complish the generation work as macro as we can. |
but why not generate automatically?
both(kasan.py and mkallsyms.py) are advanced features, which are disabled by default. so python isn't required before you enable these from defconfig. But, I need mention that shell script(include the tools invoked in it) is hard to work in Windows native environment. If we want to improve the Windows native develop experience, python is the best script we can choice. |
convert host errno to nuttx errno.
i can't think of any way to do the equivalent with C preprocessor alone. |
why not simply define EINVAL_LINUX, EINVAL_MACOS, EINVAL_WINDOWS directly, instead through errno_xxx.csv and mkerrno.py.
sorry, I don't see any hard block issue to implement the conversion in c entirely. |
EPREM in the above snippet is the host one. (just use the host errno.h)
well, of course, i can keep the csv and script private and only submit the generated C files to nuttx. |
because
|
Does your solution share one errno.csv for all OS or have the seperate errno.csv for each OS? The complex of include/errno.csv and include/errno.h is almost same, so whether we can share the same errno.csv is a key point. |
errno.csv only defines things for nuttx. i have no plan to have csv files for other OSes. (linux, macos, etc) |
So, why do we introduce errno.csv? It's more simple to modify errno.h directly to add/remove/change errno.
Sorry, I still can't understand how csv could help to fix hostfs issue. With the current patchset, I don't see any benefit to generate errno.h from mkerrno.py and errno.csv. |
because, as explained in the commit message, i want to generate more than errno.h (and automatically keep them consistent)
there is no benefit from this PR alone because it only generates errno.h at this point. |
could you provide other patch? so I can understand the whole picture. |
ok. (it might take a bit long to find time to work on this.) |
done. i just added changes for sim hostfs to this PR. |
hm, the latest nxstyle seems more nervous than the binary i happened to have. let me fix. |
this is a machine-friendly version of errno.h using this file, i plan to generate: * the corresponding C definitions in errno.h. * strerror tables. * host <-> nuttx errno conversion logic for sim. Signed-off-by: YAMAMOTO Takashi <[email protected]>
Signed-off-by: YAMAMOTO Takashi <[email protected]>
Signed-off-by: YAMAMOTO Takashi <[email protected]>
Signed-off-by: YAMAMOTO Takashi <[email protected]>
a0e9537
to
38246e7
Compare
done |
@@ -0,0 +1,311 @@ | |||
/**************************************************************************** | |||
* include/errno_defs.h |
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.
it's better to generate errno_defs.h automatically instead adding to git, to simplify the process of errno modification.
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.
it would be very rare to modify the definitions.
IMO, it doesn't warrant the effort to write C programs to avoid build-time python dependencies.
@@ -0,0 +1,77 @@ | |||
#!/usr/bin/env python3 | |||
############################################################################ | |||
# tools/mkerrno.py |
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.
we can achieve the similar result by c macro instead python script, please check how syscall is implemented:
https://github.com/apache/nuttx/blob/master/include/sys/syscall.h
https://github.com/apache/nuttx/blob/master/include/sys/syscall_lookup.h
https://github.com/apache/nuttx/blob/master/syscall/syscall_wraps.h
https://github.com/apache/nuttx/blob/master/syscall/syscall_names.c
https://github.com/apache/nuttx/blob/master/syscall/syscall_stublookup.c
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.
sorry, can you explain how you can generate an equivalent of C code in this PR,
eg.
#if defined(EPERM)
case EPERM:
return 1;
#endif
with the approach?
i suppose you mean to have
ERRNO_ITEM(EPERM, 1, "Operation not permitted")
but i'm not sure how you can define ERRNO_ITEM
which expands to an equivalent of the above mentioned snippet.
also, the syscall stuff actually has another list: syscall.csv. having multiple lists which we need to maintain the consistency is what i want to avoid.
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.
sorry, can you explain how you can generate an equivalent of C code in this PR, eg.
#if defined(EPERM) case EPERM: return 1; #endifwith the approach?
it's hard to add #if defined
in macro definition, but could doable with the macro trick like this:
https://stackoverflow.com/questions/72266480/can-ifdef-be-used-inside-a-macro
i suppose you mean to have
ERRNO_ITEM(EPERM, 1, "Operation not permitted")but i'm not sure how you can define
ERRNO_ITEM
which expands to an equivalent of the above mentioned snippet.also, the syscall stuff actually has another list: syscall.csv. having multiple lists which we need to maintain the consistency is what i want to avoid.
syscall.csv define the function prototype, but errno doesn't need it, so the header file is enough.
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.
sorry, can you explain how you can generate an equivalent of C code in this PR, eg.
#if defined(EPERM) case EPERM: return 1; #endifwith the approach?
it's hard to add
#if defined
in macro definition, but could doable with the macro trick like this: https://stackoverflow.com/questions/72266480/can-ifdef-be-used-inside-a-macro
well, it might work for a single macro like DEBUG.
however, in this case, we have to test every Exxx macros.
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.
we can use ERRNO_ITEM to iterate each EXXX and generate individual macro.
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.
we can use ERRNO_ITEM to iterate each EXXX and generate individual macro.
how?
i couldn't think of any reasonable implementations.
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.
I will find some time in the weekend to try the pure macro solution.
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.
thank you.
here's what i managed to write so far: https://github.com/yamt/garbage/tree/master/c/cpp1
i feel it isn't a reasonable implementation though.
cmake build is failing because it requires the host sources under posix or win. |
this has two purposes: * reduce linux assumptions in sim (this is a follow-up of apache#15552) * demonstrate errno.csv can be used for other purposes Signed-off-by: YAMAMOTO Takashi <[email protected]>
this is a follow-up of apache#15552 Signed-off-by: YAMAMOTO Takashi <[email protected]>
this is a follow-up of apache#15552 Signed-off-by: YAMAMOTO Takashi <[email protected]>
tested with ELOOP, which is 62 on macOS and 40 on NuttX, on sim/macOS. ```shell spacetanuki% ln -s a a spacetanuki% cat a cat: a: Too many levels of symbolic links spacetanuki% ./nuttx NuttShell (NSH) NuttX-10.4.0 nsh> mount -t hostfs -o fs=. /mnt nsh> cat /mnt/a nsh: cat: open failed: 40 nsh> ``` this is a follow-up of apache#15552 this fixes a non-linux regression in apache#15535 Signed-off-by: YAMAMOTO Takashi <[email protected]>
done |
Summary
generate errno definitions from a CSV file for flexibility.
i plan to use this CSV file for other things like host <-> nuttx errno conversion logic.
Impact
Testing