-
Notifications
You must be signed in to change notification settings - Fork 201
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
libnetplan: String helpers for the new API design + filepath transition #275
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.
Thank you very much! LGTM.
I left some minor inline comments that we should fix while rebasing the branch, before we merge it. Very nice handling of the deprecation warning and the python buffer allocation that is automatically increasing in size!
a0ccbb4
to
c4ecb0c
Compare
Codecov Report
@@ Coverage Diff @@
## main #275 +/- ##
==========================================
- Coverage 99.10% 99.04% -0.06%
==========================================
Files 61 61
Lines 11129 10893 -236
==========================================
- Hits 11029 10789 -240
- Misses 100 104 +4
Continue to review full report at Codecov.
|
This allows us to access safer string manipulation functions such as stpncpy (no that's not a type), which are available in the POSIX 2008 standard. This specific function will be useful in implementing the new API pattern of user-provided string buffers. In the newer versions of the POSIX standard, usleep has been deprecated then removed entirely, to be replaced by nanosleep, hence the change in dbus.c.
c4ecb0c
to
0c862be
Compare
Thank you very much. LGTM. Feel free to merge it! |
This function copies a NUL-terminated string into a sized buffer using the semantics decided in our API design document, with two small differences: * Except for the NULL case, the output buffer is systematically overwritten. * The return value isn't the last written byte, but the length of the NUL-terminated string *including the first NUL* (i.e. what can be safely memcpy-ed). That's because stpncpy writes NULs up 'til the end of the buffer. Those differences seemed minor enough not to be bothered with reimplementing a string manipulation function from scratch because of them. V2: added documentation on the netplan_copy_string function. V3: fix typo
As discussed, we rename the ambiguous filename field into filepath, as it denotes a full file patch, not the file base name. We introduce a new API for it that conforms to the API design guidelines (that should really be spelled out in the repo :-) ). The older function is kept around for ABI compatibility but moved out of the API, hence the API break warning.
0c862be
to
b03ce94
Compare
Description
This PR implements some infrastructure to easily implement new APIs according to our guidelines, especially regarding strings.
To demonstrate it, the last commit transition
netdef->filename
intonetdef->filepath
, implementing the new getter accordingly.Checklist
make check
successfully.make check-coverage
).