Skip to content

Conversation

@dzobbe
Copy link
Contributor

@dzobbe dzobbe commented Sep 27, 2022

…clang++

Copy link
Contributor

@loganek loganek left a comment

Choose a reason for hiding this comment

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

Having #ifdef __cplusplus in .c files is a bi unusual; could you tell us about your usecase and explain why C file is compiled with C++ compiler?

@dzobbe
Copy link
Contributor Author

dzobbe commented Sep 28, 2022

We are running WolfSSL into Wasm (look here -> https://github.com/JamesMenetrey/wolfssl-examples/tree/wasm/Wasm) and at the same time I need some features from C++.

__wasi_addr_t wasi_addr {} ;
#else
__wasi_addr_t wasi_addr = { 0 };
#endif
Copy link
Collaborator

@wenyongh wenyongh Sep 29, 2022

Choose a reason for hiding this comment

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

@dzobbe Shall we use memset to initialize it here so as to avoid introducing __cplusplus?

    __wasi_addr_t wasi_addr;
    ...
    memset(&wasi_addr, 0, sizeof(wasi_addr));

__wasi_addr_t wasi_addr {} ;
#else
__wasi_addr_t wasi_addr = { 0 };
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above


switch (optname) {
case SO_RCVTIMEO:
case SO_RCVTIMEO: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should put { to the next line, or CI code guideline check will report error:

        case SO_RCVTIMEO:
        {
            assert(optlen == sizeof(struct timeval));
            timeout_us = timeval_to_time_us(*(struct timeval *)optval);
            error = __wasi_sock_set_recv_timeout(sockfd, timeout_us);
            HANDLE_ERROR(error);
            return error;
        }

@dzobbe
Copy link
Contributor Author

dzobbe commented Sep 29, 2022

Done. Thank you.

{
__wasi_addr_t wasi_addr = { 0 };
__wasi_addr_t wasi_addr;
memset(&wasi_addr, 0, sizeof(wasi_addr));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please put memset after line 144 (had better make it a line with an empty line above and below), here it is C source code, we usually align with the C coding style.

{
__wasi_addr_t wasi_addr = { 0 };
__wasi_addr_t wasi_addr;
memset(&wasi_addr, 0, sizeof(wasi_addr));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above.

@dzobbe
Copy link
Contributor Author

dzobbe commented Sep 29, 2022

Take a look now

}

aibuf_res = calloc(1, addr_info_size * sizeof(struct aibuf));
aibuf_res = (aibuf *) calloc(1, addr_info_size * sizeof(struct aibuf));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be (struct aibuf *), or compilation error occurs in Ubuntu.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is done

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, and please help format the coding style by using clang-format-12:
clang-format-12 -i --style=file <this file>

@wenyongh
Copy link
Collaborator

Take a look now

@dzobbe One comment from me.

And also could you please use clang-format-12 to format the code:
Refer to https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/3150185668/jobs/5122933217:

Use clang-format-[12](https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/3150185668/jobs/5122933217#step:3:13) or git-clang-format-12 to check code format of
the PR, with a commit range specified. It is required to format the
code before committing the PR, or it might fail to pass the CI check:

1. Install clang-format-12.0.0
Normally we can install it by `sudo apt-get install clang-format-12`,
or download the `clang+llvm-12.0.0-xxx-tar.xz` package from
  https://github.com/llvm/llvm-project/releases/tag/llvmorg-12.0.0
and install it

2. Format the C/C++ source file
``` shell
cd path/to/wamr/root
clang-format-12 --style file -i path/to/file
```

memset(&wasi_addr, 0, sizeof(wasi_addr));

error = __wasi_sock_accept(sockfd, 0, &new_sockfd);
error = __wasi_sock_accept(sockfd, &new_sockfd);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should not change this line, refer to: #1531

@wenyongh
Copy link
Collaborator

LGTM

@wenyongh wenyongh merged commit 3fad613 into bytecodealliance:main Sep 29, 2022
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
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.

3 participants