-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
add file operation #1068
add file operation #1068
Conversation
9183c86
to
eace55d
Compare
OK, this is pretty good. I will leave a few comments in the code review, but there is a real chance this gets merged. |
lib/lz4file.h
Outdated
#include <stdio.h> | ||
#include "lz4frame.h" | ||
|
||
typedef void LZ4F_file; |
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.
Prefer an incomplete type.
It remains opaque, but it can't be confused with any other pointer type, allowing the compiler to participate in code validation. This is more important than it sounds, as many typical programming errors can be detected this way, saving precious debug time.
In this case, you already have LZ4_readFile_t
and LZ4_writeFile_t
defined in lz4file.c
.
Keep them there, just rename them struct LZ4_XxxFile_s {... };
,
and here, in the header : typedef struct LZ4_readFile_s LZ4_readFile_t;
.
The downside is that you have now 2 different types, for read and write operations.
I don't see that as a problem, I actually like this distinction.
But if your goal is to mimic <stdio.h>
, where the same FILE*
object is used for all I/O operations, you may want to refactor your type. A simpler adaptation could be to use a union
, and there are many variations around this theme.
I would, personally, keep them separate, because it matches the API's capabilities, which are solely read and write. You even have separated LZ4F_readClose()
and LZ4F_writeClose()
, so not even this operation is shared (while <stdio.h>
has a single fclose()
), and there are no additional capability planned. So really no gain in increasing confusion with a common pointer object between read and write operations.
|
||
#ifndef LZ4FILE_H | ||
#define LZ4FILE_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.
API which are not yet considered "stable", as in "guaranteed to be present with exact same ABI in future versions of the library", are guarded by the macro LZ4F_STATIC_LINKING_ONLY
.
I would recommend doing the same here, because it's a completely new API, and it still has to receive feedback from users. Besides, increasing the surface of the stable public API by anything is a major operation, requiring the update of version number (1.9 => 1.10
).
In the future, when this new API feels "ready", the guard will be removed, the version increased, and it will become part of the public API.
I would recommend adding a test, somewhere, that uses this new API. |
lib/lz4file.h
Outdated
* `lz4f` will set a lz4file handle. | ||
* `fp` must be the return value of the lz4 file opened by fopen. | ||
*/ | ||
LZ4FLIB_API LZ4F_errorCode_t LZ4F_readOpen(LZ4F_file** lz4f, FILE* fp); |
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.
When guard LZ4_STATIC_LINKING_ONLY
is added, the declaration prefix becomes LZ4FLIB_STATIC_API
.
How can you invoke Without error, For example, Lines 288 to 310 in 68f9c6e
Since intention of new API set is simplification, perhaps I mean
|
Thank you for your suggestions, I will modify the code later. |
946c849
to
bf20874
Compare
some ci hava problem |
Since all CI errors are at setup or @Cyan4973 could you restart GH-Actions again? If Cyann is busy, @anjiahao1 may be able to try empty push to invoke CI. |
Tests are restarted |
What about adding an example ? And use it as a form of small test ? |
ok i'll add tests and examples this weekend 👌 |
Note: please avoid adding the produced binary Otherwise, the rest of the PR looks in pretty good shape. |
OK, I believe the code is in good shape. The last issue I can think of is a bit complex, and I probably will have to look into it myself. Anyway, I believe the code itself is ready to merge, the question is more : |
ok,merge into |
As for So, I think it's okay to state that |
I fully agree. I'm slightly more concerned by integration at static library level. Btw, I'm wondering how I could check that. |
Introducing new compile-time feature macro
It depends on capability of compiler/linker. But they may be impacted if all of their code and dependent libraries don't rely on any standard C library. For freestanding target, I think we should strongly recommend them to use LZ4 as a library in source code form.
Maybe we can implement freestanding environment test with the following compile switches.
|
f9e71fb
to
e7b6551
Compare
operate lz4 compressed files as a general files Signed-off-by: anjiahao <anjiahao@xiaomi.com>
I agree.
That's a good idea !
I like |
@anjiahao1 : I believe the remaining efforts are essentially documentation related, there might also be some follow up, with new tests and new build capabilities, but these are all actions we'll take care on our side. I noticed you recently updated your PR. Is there anything worthwhile mentioning ? Do you still intend to work a bit on this PR ? |
oh,this a error in LZ4F_write,it use dtsMaxSzie to contrl chunk,is error.need use maxWriteSize to contrl chunk |
operate lz4 compressed files as a general files
Signed-off-by: anjiahao anjiahao@xiaomi.com