-
Notifications
You must be signed in to change notification settings - Fork 14.2k
[libc][docs] Generate docs for signal.h & optimized is_implemented func #88028
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
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-libc Author: Xu Zhang (simonzgx) ChangesFixes #87835 Full diff: https://github.com/llvm/llvm-project/pull/88028.diff 3 Files Affected:
diff --git a/libc/docs/signal.rst b/libc/docs/signal.rst
new file mode 100644
index 00000000000000..a994645ce3c260
--- /dev/null
+++ b/libc/docs/signal.rst
@@ -0,0 +1,41 @@
+signal.h Functions
+==================
+
+.. list-table::
+ :widths: auto
+ :align: center
+ :header-rows: 1
+
+ * - Function
+ - Implemented
+ - Standard
+ * - kill
+ - |check|
+ -
+ * - raise
+ - |check|
+ - 7.14.2.1
+ * - sigaction
+ - |check|
+ -
+ * - sigaddset
+ - |check|
+ -
+ * - sigaltstack
+ - |check|
+ -
+ * - sigdelset
+ - |check|
+ -
+ * - sigemptyset
+ - |check|
+ -
+ * - sigfillset
+ - |check|
+ -
+ * - signal
+ - |check|
+ - 7.14.1.1
+ * - sigprocmask
+ - |check|
+ -
diff --git a/libc/utils/docgen/docgen.py b/libc/utils/docgen/docgen.py
index 7411b4506f082f..213ed7e6cc5ec8 100755
--- a/libc/utils/docgen/docgen.py
+++ b/libc/utils/docgen/docgen.py
@@ -23,12 +23,21 @@ def load_api(hname: str) -> Dict:
# TODO: we may need to get more sophisticated for less generic implementations.
# Does libc/src/{hname minus .h suffix}/{fname}.cpp exist?
def is_implemented(hname: str, fname: str) -> bool:
- return Path(
+ path = Path(
Path(__file__).parent.parent.parent,
"src",
- hname.rstrip(".h"),
- fname + ".cpp",
- ).exists()
+ hname.rstrip(".h")
+ )
+ source_file_name = fname + ".cpp"
+ if path.joinpath(source_file_name).exists():
+ return True
+
+ # Attempt to search in the subfolders with 1-depth.
+ for sub_dir in path.iterdir():
+ if (sub_dir.joinpath(source_file_name)).exists():
+ return True
+
+ return False
def print_functions(header: str, functions: Dict):
diff --git a/libc/utils/docgen/signal.json b/libc/utils/docgen/signal.json
new file mode 100644
index 00000000000000..366fb87d0a293a
--- /dev/null
+++ b/libc/utils/docgen/signal.json
@@ -0,0 +1,21 @@
+{
+ "macros": [
+ "__STDC_VERSION_FENV_H__"
+ ],
+ "functions": {
+ "kill": null,
+ "sigaction": null,
+ "sigaddset": null,
+ "sigaltstack": null,
+ "sigdelset": null,
+ "sigemptyset": null,
+ "sigfillset": null,
+ "sigprocmask": null,
+ "signal": {
+ "defined": "7.14.1.1"
+ },
+ "raise": {
+ "defined": "7.14.2.1"
+ }
+ }
+}
\ No newline at end of file
|
"sigdelset": null, | ||
"sigemptyset": null, | ||
"sigfillset": null, | ||
"sigprocmask": null, |
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.
So I was thinking about these POSIX defined functions (none of this needs to be solved in this PR, but is perhaps worth thinking about how we can do something better for POSIX functions in the future).
It is possible to create a hyperlink to a page about them, example: https://pubs.opengroup.org/onlinepubs/009604499/functions/kill.html
Perhaps we either add more specialized handling of the 'defined' field to support URLs, or use a different field. IDK yet.
libc/utils/docgen/docgen.py
Outdated
# Attempt to search in the subfolders with 1-depth. | ||
for sub_dir in path.iterdir(): | ||
if (sub_dir.joinpath(source_file_name)).exists(): |
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.
Elegant. Last week I was wondering about this since we have some cases where the subdir is a target ISA like x86_64, aarch64, etc. (i.e. src/math/
, and other cases we have an OS like linux, darwin, windows (i.e. src/__support/OSUtil
).
I guess src/__support/OSUtil and src/sys are cases where we'd need to recurse deeper. But for now, I'm happy with this addition. It makes sense to retain the TODO at the top of this function since we'll probably be revisiting this imminently.
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 just update the patch and now we can recursively search through all the subdirectories.
9f5784e
to
08d9480
Compare
d02a2a8
to
ca093c6
Compare
ca093c6
to
9a82d2b
Compare
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 patch! Need me to merge?
Sure, thanks for your help! |
@simonzgx Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Fixes #87835
This patch added the documentation for the POSIX functions
according to n3096 Section 7.14, and gives the docgen.py script a
more elegant is_implemented function.