Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 52 additions & 16 deletions contrib/single_file_libs/build_decoder_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,56 @@ OUT_FILE="tempbin"
# Optional temporary compiled WebAssembly
OUT_WASM="temp.wasm"

# Source files to compile using Emscripten.
IN_FILES="examples/emscripten.c"

# Emscripten build using emcc.
emscripten_emcc_build() {
# Compile the the same example as above
CC_FLAGS="-Wall -Wextra -Werror -Os -g0 -flto"
emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
# Did compilation work?
if [ $? -ne 0 ]; then
echo "Compiling ${IN_FILES}: FAILED"
exit 1
fi
echo "Compiling ${IN_FILES}: PASSED"
rm -f $OUT_WASM
}

# Emscripten build using docker.
emscripten_docker_build() {
docker container run --rm \
--volume $PWD:/code \
--workdir /code \
trzeci/emscripten \
emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
# Did compilation work?
if [ $? -ne 0 ]; then
echo "Compiling ${IN_FILES} (using docker): FAILED"
exit 1
fi
echo "Compiling ${IN_FILES} (using docker): PASSED"
rm -f $OUT_WASM
}

# Try Emscripten build using emcc or docker.
try_emscripten_build() {
which emcc > /dev/null
if [ $? -eq 0 ]; then
emscripten_emcc_build
return $?
fi

which docker > /dev/null
if [ $? -eq 0 ]; then
emscripten_docker_build
return $?
fi

echo "(Skipping Emscripten test)"
}

# Amalgamate the sources
./create_single_file_decoder.sh
# Did combining work?
Expand Down Expand Up @@ -35,21 +85,7 @@ if [ $retVal -ne 0 ]; then
fi
echo "Running simple.c: PASSED"

# Is Emscripten available?
which emcc > /dev/null
if [ $? -ne 0 ]; then
echo "(Skipping Emscripten test)"
else
# Compile the Emscripten example
CC_FLAGS="-Wall -Wextra -Werror -Os -g0 -flto --llvm-lto 3 -lGL -DNDEBUG=1"
emcc $CC_FLAGS -s WASM=1 -o $OUT_WASM examples/emscripten.c
# Did compilation work?
if [ $? -ne 0 ]; then
echo "Compiling emscripten.c: FAILED"
exit 1
fi
echo "Compiling emscripten.c: PASSED"
rm -f $OUT_WASM
fi
# Try Emscripten build if emcc or docker command is available.
try_emscripten_build

exit 0
68 changes: 52 additions & 16 deletions contrib/single_file_libs/build_library_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,56 @@ OUT_FILE="tempbin"
# Optional temporary compiled WebAssembly
OUT_WASM="temp.wasm"

# Source files to compile using Emscripten.
IN_FILES="zstd.c examples/roundtrip.c"

# Emscripten build using emcc.
emscripten_emcc_build() {
# Compile the the same example as above
CC_FLAGS="-Wall -Wextra -Werror -Os -g0 -flto"
emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
# Did compilation work?
if [ $? -ne 0 ]; then
echo "Compiling ${IN_FILES}: FAILED"
exit 1
fi
echo "Compiling ${IN_FILES}: PASSED"
rm -f $OUT_WASM
}

# Emscripten build using docker.
emscripten_docker_build() {
docker container run --rm \
--volume $PWD:/code \
--workdir /code \
trzeci/emscripten \
emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
# Did compilation work?
if [ $? -ne 0 ]; then
echo "Compiling ${IN_FILES} (using docker): FAILED"
exit 1
fi
echo "Compiling ${IN_FILES} (using docker): PASSED"
rm -f $OUT_WASM
}

# Try Emscripten build using emcc or docker.
try_emscripten_build() {
which emcc > /dev/null
if [ $? -eq 0 ]; then
emscripten_emcc_build
return $?
fi

which docker > /dev/null
if [ $? -eq 0 ]; then
emscripten_docker_build
return $?
fi

echo "(Skipping Emscripten test)"
}

# Amalgamate the sources
./create_single_file_library.sh
# Did combining work?
Expand Down Expand Up @@ -41,21 +91,7 @@ if [ $retVal -ne 0 ]; then
fi
echo "Running roundtrip.c: PASSED"

# Is Emscripten available?
which emcc > /dev/null
if [ $? -ne 0 ]; then
echo "(Skipping Emscripten test)"
else
# Compile the the same example as above
CC_FLAGS="-Wall -Wextra -Werror -Os -g0 -flto"
emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM zstd.c examples/roundtrip.c
# Did compilation work?
if [ $? -ne 0 ]; then
echo "Compiling emscripten.c: FAILED"
exit 1
fi
echo "Compiling emscripten.c: PASSED"
rm -f $OUT_WASM
fi
# Try Emscripten build if emcc or docker command is available.
try_emscripten_build

exit 0
8 changes: 4 additions & 4 deletions lib/common/pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque)
struct POOL_ctx_s {
int dummy;
};
static POOL_ctx g_ctx;
static POOL_ctx g_poolCtx;

POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
Expand All @@ -311,11 +311,11 @@ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customM
(void)numThreads;
(void)queueSize;
(void)customMem;
return &g_ctx;
return &g_poolCtx;
}

void POOL_free(POOL_ctx* ctx) {
assert(!ctx || ctx == &g_ctx);
assert(!ctx || ctx == &g_poolCtx);
(void)ctx;
}

Expand All @@ -337,7 +337,7 @@ int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque) {

size_t POOL_sizeof(POOL_ctx* ctx) {
if (ctx==NULL) return 0; /* supports sizeof NULL */
assert(ctx == &g_ctx);
assert(ctx == &g_poolCtx);
return sizeof(*ctx);
}

Expand Down
10 changes: 5 additions & 5 deletions lib/dictBuilder/cover.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ typedef struct {
} COVER_ctx_t;

/* We need a global context for qsort... */
static COVER_ctx_t *g_ctx = NULL;
static COVER_ctx_t *g_coverCtx = NULL;

/*-*************************************
* Helper functions
Expand Down Expand Up @@ -267,11 +267,11 @@ static int COVER_cmp8(COVER_ctx_t *ctx, const void *lp, const void *rp) {

/**
* Same as COVER_cmp() except ties are broken by pointer value
* NOTE: g_ctx must be set to call this function. A global is required because
* NOTE: g_coverCtx must be set to call this function. A global is required because
* qsort doesn't take an opaque pointer.
*/
static int WIN_CDECL COVER_strict_cmp(const void *lp, const void *rp) {
int result = COVER_cmp(g_ctx, lp, rp);
int result = COVER_cmp(g_coverCtx, lp, rp);
if (result == 0) {
result = lp < rp ? -1 : 1;
}
Expand All @@ -281,7 +281,7 @@ static int WIN_CDECL COVER_strict_cmp(const void *lp, const void *rp) {
* Faster version for d <= 8.
*/
static int WIN_CDECL COVER_strict_cmp8(const void *lp, const void *rp) {
int result = COVER_cmp8(g_ctx, lp, rp);
int result = COVER_cmp8(g_coverCtx, lp, rp);
if (result == 0) {
result = lp < rp ? -1 : 1;
}
Expand Down Expand Up @@ -612,7 +612,7 @@ static size_t COVER_ctx_init(COVER_ctx_t *ctx, const void *samplesBuffer,
/* qsort doesn't take an opaque pointer, so pass as a global.
* On OpenBSD qsort() is not guaranteed to be stable, their mergesort() is.
*/
g_ctx = ctx;
g_coverCtx = ctx;
#if defined(__OpenBSD__)
mergesort(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
Expand Down