feat(bindings/c): framework of add basic io and init logics#1861
feat(bindings/c): framework of add basic io and init logics#1861Xuanwo merged 4 commits intoapache:mainfrom
Conversation
|
Also, I would appreciate it if anyone can share some ideas on the construction of hashmap used to construct operator, since cbindgen does not support HashMap. Storing it by pointer is obviously not 100% safe since the hashmap might be reallocated upon insertion and deletion. But IMO that might be acceptable since the map will only be used to construct operator. I have another idea might be better, which is it could accept a sequence of Key-Value pairs separately in the argument and construct the hashmap in our Rust code. |
That's a good question. I don't have any ideas yet, but we could focus on implementing memory service support first. Ideally, we should avoid supporting initialization backends through hashmaps in C. |
f52c6d6 to
e2db532
Compare
* Add the init logics for operator * Add the basic io operations (r/w) * Add the test for basicio Fixes: apache#1201 Signed-off-by: Ji-Xinyou <jerryji0414@outlook.com>
* The hello_opendal() works as a place holder for c binding, remove it since it will not be used anymore Signed-off-by: Ji-Xinyou <jerryji0414@outlook.com>
* Previously the type opendal_operator_ptr uses a C layout, i.e., it STORES a pointer inside it. This commit changes it to transparent layout, which guarantees it has the SAME layout of the inner pointer. This allows the opendal_operator_ptr uses native boolean operation to check validity. e.g. (!ptr) means invalid. Signed-off-by: Ji-Xinyou <jerryji0414@outlook.com>
849d253 to
d65a3c3
Compare
|
I have added the Some explainations:
I would really appreciate any review and suggestions on the PR and feel free to contact me for any changes or questions. |
|
Hi @Xuanwo , I think carefully about the so called
struct opendal_operator_builder* opendal_operator_new(char* scheme);
opendal_code opendal_operator_build(opendal_operator_builder* builder);
struct opendal_operator_builder {
struct opendal_operator_ptr ptr;
char* scheme;
...
}let the builder stores the actual
|
Good idea. I do think we need some builder things in c bindings too. But we can leave this to further PRs. Python/Node.js/Java has similiar problems too. Maybe we should do some code generation to address this issue. And for now, I think it's Ok to have a
No, this error kind is Bindings should handle all error kinds. And everytime we add a new error, we should update all bindings. It's not a heavy work and we won't add new kinds every day.
Yep, agreed. |
In the binding codes, the matching has to have a |
Sorry for my mistake. Please just leave a |
Sorry for my mistake. I have updated my previous comment. |
e9343b8 to
c7be052
Compare
|
The s3 cpp sdk: bool AwsDoc::S3::PutObject(const Aws::String &bucketName,
const Aws::String &fileName,
const Aws::Client::ClientConfiguration &clientConfig) {
Aws::S3::S3Client s3_client(clientConfig);
Aws::S3::Model::PutObjectRequest request;
request.SetBucket(bucketName);
//We are using the name of the file as the key for the object in the bucket.
//However, this is just a string and can be set according to your retrieval needs.
request.SetKey(fileName);
std::shared_ptr<Aws::IOStream> inputData =
Aws::MakeShared<Aws::FStream>("SampleAllocationTag",
fileName.c_str(),
std::ios_base::in | std::ios_base::binary);
if (!*inputData) {
std::cerr << "Error unable to read file " << fileName << std::endl;
return false;
}
request.SetBody(inputData);
Aws::S3::Model::PutObjectOutcome outcome =
s3_client.PutObject(request);
if (!outcome.IsSuccess()) {
std::cerr << "Error: PutObject: " <<
outcome.GetError().GetMessage() << std::endl;
}
else {
std::cout << "Added object '" << fileName << "' to bucket '"
<< bucketName << "'.";
}
return outcome.IsSuccess();
}Seems we do have to return |
Yeah, looks like this is the common practice. But fortunately there isn't that much operations and we only need one for each of them... |
Sorry for my misleading. Let's do this. This PR is good enough to get merged after #1861 (comment) addressed. We can add them in future PRs. |
|
Last work: please make our checks happy. |
Every commit of mine passes the |
* Add error code opendal_error for error handling, which decouples the od::ErrorKind Signed-off-by: Ji-Xinyou <jerryji0414@outlook.com>
Please fix https://github.com/apache/incubator-opendal/actions/runs/4638141339/jobs/8207676488?pr=1861 |
Sorry, I forget there should be a newline after the licence. That should be fixed now. |
Xuanwo
left a comment
There was a problem hiding this comment.
Thanks a lot! Let's keep moving.
Fixes: #1201
I want to raise this PR for further discussions. And I think(maybe?) a user guide and developer guide for C bindings is needed for style consistency.
Some explainations:
Why we have an
OperatorPtrtype.Operator's address inside the pointer, and useget_refto provide a immutable reference to its underlyingBlockingOperator.In C, librarys normally have prefix, I naively uses
odas the function prefix andopendalas struct prefix.Why we have a
Vectortype.Vec<T>from Rust, therefore I uses a quite brute force way of a C-compatible alternative.