Skip to content

[libc][c11] implement ctime #107285

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

Merged
merged 63 commits into from
Sep 16, 2024
Merged

[libc][c11] implement ctime #107285

merged 63 commits into from
Sep 16, 2024

Conversation

zimirza
Copy link
Contributor

@zimirza zimirza commented Sep 4, 2024

This is an implementation of ctime and includes ctime_r.

According to documentation, ctime and ctime_r are defined as the following:

char *ctime(const time_t *timep);
char *ctime_r(const time_t *restrict timep, char buf[restrict 26]);

closes #86567

remove buffer length
fix: buffer length
add buffer length
fix: ctime implementation
fix: function declaration
format code with `clang-format`
implement `ctime_r`
fix: `ctime_r` header file
add `ctime_r` to `cmake`
Copy link

github-actions bot commented Sep 4, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

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 permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

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.

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start, but I think we can simplify the code a bit. You'll also need to update the build system in a few places:

Feel free to reach out if you have questions on how to do any of this, and thank you for the contribution!

add `ctime` and `ctime_r` to build system
refactor `ctime` and `ctime_r` to use `asctime`
add `ctime` and `ctime_r` to `aarch64` and `riscv` architecture
add `ctime` and `ctime_r` to more architectures
- add symbols for `ctime` and `ctime_r`
- add `ctime` and `ctime_r` to clang formatted files list
- add `ctime` to env32-c test
@zimirza zimirza marked this pull request as ready for review September 5, 2024 12:25
@zimirza zimirza marked this pull request as draft September 5, 2024 12:31
add header for `time_t`
removed `ctime` from analysis test
fix: `time_t` definition in `stdc.td`
fix: removed `ctime_s`
add `ctime` and `ctime_r` to unsafe functions check
use asctime constants and remove ctime constants
use `TimeTTypePtr` and remove `StructTimeTPtr`
@zimirza
Copy link
Contributor Author

zimirza commented Sep 11, 2024

Thank you for the thorough feedback. I apologize for going back and forth in this pull request. I will try to double check my work in future pull requests.

Copy link

github-actions bot commented Sep 11, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@michaelrj-google
Copy link
Contributor

All good, review is a normal part of LLVM development. Now that this is approved, do you need me to merge it for you?

@zimirza
Copy link
Contributor Author

zimirza commented Sep 11, 2024

That would be great, since I cannot merge in LLVM.

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the tests locally and ran into some issues, these need to be fixed before we can merge this.

@zimirza
Copy link
Contributor Author

zimirza commented Sep 12, 2024

I am so sorry about this. I have now fixed them all.

@michaelrj-google
Copy link
Contributor

it's fine, just make sure you run the tests to see what's working and what's broken. I usually just run ninja check-libc but if you're using make it should be make check-libc. There are a couple more places where things are broken, I'll add comments in a bit when I get a chance.

@michaelrj-google
Copy link
Contributor

also before I forget: If the tests aren't running for you it might be because these tests only run in full build mode: https://libc.llvm.org/full_host_build.html

When switching to full build mode you'll need to clean out your build folder because otherwise there are some confusing errors.

@zimirza
Copy link
Contributor Author

zimirza commented Sep 12, 2024

Sure, I will try to run the full build mode. I will let you know when this is ready.

@zimirza
Copy link
Contributor Author

zimirza commented Sep 13, 2024

I am testing locally and did find some issues. I will be fixing it now.

@zimirza
Copy link
Contributor Author

zimirza commented Sep 13, 2024

Tests for ctime and ctime_r are now good.

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this, it's all working on my machine now so I'll plan on landing it on Monday (since I don't want to land right before I get off work on Friday).

I really appreciate you working through this and getting it completed. I know it took a lot of effort but it's worth it at the end to have something high quality like this.

@zimirza
Copy link
Contributor Author

zimirza commented Sep 13, 2024

Thank you for the thorough review. I really do appreciate it. I have a question. Since this pull request is a new API feature implementation, should I also update documentation for ctime and ctime_r?

@michaelrj-google
Copy link
Contributor

You're welcome, and yes updating the docs for ctime and ctime_r would be good. I don't know if there's an existing page tracking the status of the time functions (it'd be in libc/docs). If there isn't then you can skip it. Adding a whole new page for the time functions should probably be a separate patch.

@michaelrj-google michaelrj-google merged commit 000a3f0 into llvm:main Sep 16, 2024
7 checks passed
Copy link

@zimirza 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 by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

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. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@zimirza zimirza deleted the ctime_86567 branch September 16, 2024 19:41
@nickdesaulniers
Copy link
Member

Looks like #109892 was a follow up to this PR.

@zimirza
Copy link
Contributor Author

zimirza commented Sep 27, 2024

That is correct. Unfortunately, I did not compare my implementation with glibc's ctime. So, I created a new issue for this. Hope it is ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libc][c11] implement ctime
4 participants