Skip to content

Commit 2ba5a95

Browse files
authored
Merge pull request #12 from nervosnetwork/use-cxx-compatible-restrict
feat: Use cxx compatible restrict
2 parents 271d65b + 2f53740 commit 2ba5a95

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
default: fmt clippy test bench-test check test-c-impl
1+
default: fmt clippy test bench-test check test-c-impl test-cxx-build
22

33
test:
44
cargo test --all --all-features
@@ -18,3 +18,6 @@ check:
1818
test-c-impl:
1919
git submodule update --init --recursive
2020
cd c/rust-tests && cargo test
21+
22+
test-cxx-build:
23+
g++ -c c/rust-tests/src/tests/ckb_smt.c -I c -o smt.o && rm -rf smt.o

c/ckb_smt.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
#ifndef _CKB_SPARSE_MERKLE_TREE_H_
88
#define _CKB_SPARSE_MERKLE_TREE_H_
99

10+
#ifdef __GNUC__
11+
#define RESTRICT __restrict__
12+
#else
13+
#define RESTRICT
14+
#endif
15+
1016
// The faster version of memset & memcpy implementations used here are from
1117
// the awesome musl libc project: https://www.musl-libc.org/
1218
void *_smt_fast_memset(void *dest, int c, size_t n)
@@ -97,7 +103,7 @@ void *_smt_fast_memset(void *dest, int c, size_t n)
97103
return dest;
98104
}
99105

100-
void *_smt_fast_memcpy(void *restrict dest, const void *restrict src, size_t n)
106+
void *_smt_fast_memcpy(void * RESTRICT dest, const void * RESTRICT src, size_t n)
101107
{
102108
unsigned char *d = (unsigned char *)dest;
103109
const unsigned char *s = (unsigned char *)src;
@@ -218,6 +224,8 @@ void *_smt_fast_memcpy(void *restrict dest, const void *restrict src, size_t n)
218224
return dest;
219225
}
220226

227+
#undef RESTRICT
228+
221229
// users can define a new stack size if needed
222230
#ifndef SMT_STACK_SIZE
223231
#define SMT_STACK_SIZE 257

0 commit comments

Comments
 (0)