This is an automated email from the ASF dual-hosted git repository.

psiace pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 7525ccda feat(binding/C): add clang-format for c binding (#2003)
7525ccda is described below

commit 7525ccdad499a643051acc5a43205b5d88377917
Author: xyJi <[email protected]>
AuthorDate: Sat Apr 15 16:43:48 2023 +0800

    feat(binding/C): add clang-format for c binding (#2003)
    
    * feat(binding/c): add clang-format of google style
    
    Signed-off-by: Ji-Xinyou <[email protected]>
    
    * feat(bindings/c): format all C source code and headers
    
    * Format all C source code and headers using clang-format
    
    Signed-off-by: Ji-Xinyou <[email protected]>
    
    * feat(binding/c): add make format using clang-format
    
    * Remove the space of assigning envvar in Makefile
    * Add `make format` command to format all "*.c" and ".h"
      file under the c binding directory
    
    Signed-off-by: Ji-Xinyou <[email protected]>
    
    * docs(binding/C): add make format in readme
    
    Signed-off-by: Ji-Xinyou <[email protected]>
    
    * remove the clang-format file and use WebKit style instead
    
    Signed-off-by: Ji-Xinyou <[email protected]>
    
    ---------
    
    Signed-off-by: Ji-Xinyou <[email protected]>
---
 bindings/c/Makefile          |  10 ++-
 bindings/c/README.md         |   1 +
 bindings/c/include/opendal.h | 160 ++++++++++++++++++++++---------------------
 bindings/c/tests/basicio.c   |   8 ++-
 4 files changed, 94 insertions(+), 85 deletions(-)

diff --git a/bindings/c/Makefile b/bindings/c/Makefile
index 28e391c3..4394d357 100644
--- a/bindings/c/Makefile
+++ b/bindings/c/Makefile
@@ -16,14 +16,18 @@
 # under the License.
 
 RPATH=$(PWD)/../../target/debug
-CFLAGS = -I./include
-LDFLAGS = -L$(RPATH) -Wl,-rpath,$(RPATH)
-LIBS = -lopendal_c
+CFLAGS=-I./include
+LDFLAGS=-L$(RPATH) -Wl,-rpath,$(RPATH)
+LIBS=-lopendal_c
 OBJ_DIR=./build
 
 .PHONY: all
 all: build test
 
+.PHONY: format
+format:
+       find . \( -name '*.c' -o -name '*.h' \) -exec clang-format -i 
--style=WebKit --verbose {} \;
+
 .PHONY: build
 build:
        mkdir -p $(OBJ_DIR)
diff --git a/bindings/c/README.md b/bindings/c/README.md
index adbcf1e2..fbe7c554 100644
--- a/bindings/c/README.md
+++ b/bindings/c/README.md
@@ -4,6 +4,7 @@
 
 ```bash
 make
+make format
 make build
 make test
 ```
diff --git a/bindings/c/include/opendal.h b/bindings/c/include/opendal.h
index f4ad4704..e177cb71 100644
--- a/bindings/c/include/opendal.h
+++ b/bindings/c/include/opendal.h
@@ -17,66 +17,66 @@
  * under the License.
  */
 
-
 #ifndef _OPENDAL_H
 #define _OPENDAL_H
 
-#include <stdint.h>
-#include <stddef.h>
 #include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
 
 /*
  The error code for opendal APIs in C binding
  */
 typedef enum opendal_code {
-  /*
-   All is well
-   */
-  OPENDAL_OK,
-  /*
-   General error
-   */
-  OPENDAL_ERROR,
-  /*
-   returning it back. For example, s3 returns an internal service error.
-   */
-  OPENDAL_UNEXPECTED,
-  /*
-   Underlying service doesn't support this operation.
-   */
-  OPENDAL_UNSUPPORTED,
-  /*
-   The config for backend is invalid.
-   */
-  OPENDAL_CONFIG_INVALID,
-  /*
-   The given path is not found.
-   */
-  OPENDAL_NOT_FOUND,
-  /*
-   The given path doesn't have enough permission for this operation
-   */
-  OPENDAL_PERMISSION_DENIED,
-  /*
-   The given path is a directory.
-   */
-  OPENDAL_IS_A_DIRECTORY,
-  /*
-   The given path is not a directory.
-   */
-  OPENDAL_NOT_A_DIRECTORY,
-  /*
-   The given path already exists thus we failed to the specified operation on 
it.
-   */
-  OPENDAL_ALREADY_EXISTS,
-  /*
-   Requests that sent to this path is over the limit, please slow down.
-   */
-  OPENDAL_RATE_LIMITED,
-  /*
-   The given file paths are same.
-   */
-  OPENDAL_IS_SAME_FILE,
+    /*
+     All is well
+     */
+    OPENDAL_OK,
+    /*
+     General error
+     */
+    OPENDAL_ERROR,
+    /*
+     returning it back. For example, s3 returns an internal service error.
+     */
+    OPENDAL_UNEXPECTED,
+    /*
+     Underlying service doesn't support this operation.
+     */
+    OPENDAL_UNSUPPORTED,
+    /*
+     The config for backend is invalid.
+     */
+    OPENDAL_CONFIG_INVALID,
+    /*
+     The given path is not found.
+     */
+    OPENDAL_NOT_FOUND,
+    /*
+     The given path doesn't have enough permission for this operation
+     */
+    OPENDAL_PERMISSION_DENIED,
+    /*
+     The given path is a directory.
+     */
+    OPENDAL_IS_A_DIRECTORY,
+    /*
+     The given path is not a directory.
+     */
+    OPENDAL_NOT_A_DIRECTORY,
+    /*
+     The given path already exists thus we failed to the specified operation on
+     it.
+     */
+    OPENDAL_ALREADY_EXISTS,
+    /*
+     Requests that sent to this path is over the limit, please slow down.
+     */
+    OPENDAL_RATE_LIMITED,
+    /*
+     The given file paths are same.
+     */
+    OPENDAL_IS_SAME_FILE,
 } opendal_code;
 
 /*
@@ -121,7 +121,7 @@ typedef struct BlockingOperator BlockingOperator;
  to check its validity by native boolean operator.
  e.g. you could check by (!ptr) on a [`opendal_operator_ptr`]
  */
-typedef const struct BlockingOperator *opendal_operator_ptr;
+typedef const struct BlockingOperator* opendal_operator_ptr;
 
 /*
  The [`opendal_bytes`] type is a C-compatible substitute for [`Vec`]
@@ -130,8 +130,8 @@ typedef const struct BlockingOperator *opendal_operator_ptr;
  to free the heap memory to avoid memory leak.
  */
 typedef struct opendal_bytes {
-  const uint8_t *data;
-  uintptr_t len;
+    const uint8_t* data;
+    uintptr_t len;
 } opendal_bytes;
 
 /*
@@ -141,8 +141,8 @@ typedef struct opendal_bytes {
  and the error code is NOT OPENDAL_OK.
  */
 typedef struct opendal_result_read {
-  struct opendal_bytes *data;
-  enum opendal_code code;
+    struct opendal_bytes* data;
+    enum opendal_code code;
 } opendal_result_read;
 
 /*
@@ -151,8 +151,8 @@ typedef struct opendal_result_read {
  corresponding error code.
  */
 typedef struct opendal_result_is_exist {
-  bool is_exist;
-  enum opendal_code code;
+    bool is_exist;
+    enum opendal_code code;
 } opendal_result_is_exist;
 
 #ifdef __cplusplus
@@ -160,17 +160,19 @@ extern "C" {
 #endif // __cplusplus
 
 /*
- Returns a result type [`opendal_result_op`], with operator_ptr. If the 
construction succeeds
- the error is nullptr, otherwise it contains the error information.
+ Returns a result type [`opendal_result_op`], with operator_ptr. If the
+ construction succeeds the error is nullptr, otherwise it contains the error
+ information.
 
  # Safety
 
  It is [safe] under two cases below
- * The memory pointed to by `scheme` must contain a valid nul terminator at 
the end of
-   the string.
- * The `scheme` points to NULL, this function simply returns you a null 
opendal_operator_ptr
+ * The memory pointed to by `scheme` must contain a valid nul terminator at the
+ end of the string.
+ * The `scheme` points to NULL, this function simply returns you a null
+ opendal_operator_ptr
  */
-opendal_operator_ptr opendal_operator_new(const char *scheme);
+opendal_operator_ptr opendal_operator_new(const char* scheme);
 
 /*
  Free the allocated operator pointed by [`opendal_operator_ptr`]
@@ -178,22 +180,22 @@ opendal_operator_ptr opendal_operator_new(const char 
*scheme);
 void opendal_operator_free(opendal_operator_ptr op_ptr);
 
 /*
- Write the data into the path blockingly by operator, returns the error code 
OPENDAL_OK
- if succeeds, others otherwise
+ Write the data into the path blockingly by operator, returns the error code
+ OPENDAL_OK if succeeds, others otherwise
 
  # Safety
 
  It is [safe] under two cases below
- * The memory pointed to by `path` must contain a valid nul terminator at the 
end of
-   the string.
+ * The memory pointed to by `path` must contain a valid nul terminator at the
+ end of the string.
 
  # Panic
 
  * If the `path` points to NULL, this function panics
  */
 enum opendal_code opendal_operator_blocking_write(opendal_operator_ptr op_ptr,
-                                                  const char *path,
-                                                  struct opendal_bytes bytes);
+    const char* path,
+    struct opendal_bytes bytes);
 
 /*
  Read the data out from path into a [`Bytes`] blockingly by operator, returns
@@ -203,15 +205,15 @@ enum opendal_code 
opendal_operator_blocking_write(opendal_operator_ptr op_ptr,
  # Safety
 
  It is [safe] under two cases below
- * The memory pointed to by `path` must contain a valid nul terminator at the 
end of
-   the string.
+ * The memory pointed to by `path` must contain a valid nul terminator at the
+ end of the string.
 
  # Panic
 
  * If the `path` points to NULL, this function panics
  */
-struct opendal_result_read opendal_operator_blocking_read(opendal_operator_ptr 
op_ptr,
-                                                          const char *path);
+struct opendal_result_read opendal_operator_blocking_read(
+    opendal_operator_ptr op_ptr, const char* path);
 
 /*
  Check whether the path exists.
@@ -224,20 +226,20 @@ struct opendal_result_read 
opendal_operator_blocking_read(opendal_operator_ptr o
  # Safety
 
  It is [safe] under two cases below
- * The memory pointed to by `path` must contain a valid nul terminator at the 
end of
-   the string.
+ * The memory pointed to by `path` must contain a valid nul terminator at the
+ end of the string.
 
  # Panic
 
  * If the `path` points to NULL, this function panics
  */
-struct opendal_result_is_exist opendal_operator_is_exist(opendal_operator_ptr 
op_ptr,
-                                                         const char *path);
+struct opendal_result_is_exist opendal_operator_is_exist(
+    opendal_operator_ptr op_ptr, const char* path);
 
 /*
  Frees the heap memory used by the [`opendal_bytes`]
  */
-void opendal_bytes_free(const struct opendal_bytes *self);
+void opendal_bytes_free(const struct opendal_bytes* self);
 
 #ifdef __cplusplus
 } // extern "C"
diff --git a/bindings/c/tests/basicio.c b/bindings/c/tests/basicio.c
index aff1b49f..765669f2 100644
--- a/bindings/c/tests/basicio.c
+++ b/bindings/c/tests/basicio.c
@@ -27,7 +27,8 @@
 // * A valid ptr is given
 // * The blocking write operation is successful
 // * The blocking read operation is successful and works as expected
-void test_operator_rw(opendal_operator_ptr ptr) {
+void test_operator_rw(opendal_operator_ptr ptr)
+{
     // have to be valid ptr
     assert(ptr);
 
@@ -36,7 +37,7 @@ void test_operator_rw(opendal_operator_ptr ptr) {
     char content[] = "Hello World";
     const opendal_bytes data = {
         .len = sizeof(content) - 1,
-        .data = (uint8_t *)content,
+        .data = (uint8_t*)content,
     };
     opendal_code code = opendal_operator_blocking_write(ptr, path, data);
     assert(code == OPENDAL_OK);
@@ -54,7 +55,8 @@ void test_operator_rw(opendal_operator_ptr ptr) {
     opendal_bytes_free(r.data);
 }
 
-int main(int argc, char *argv[]) {
+int main(int argc, char* argv[])
+{
     // construct the memory operator
     char scheme1[] = "memory";
     opendal_operator_ptr p1 = opendal_operator_new(scheme1);

Reply via email to