aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin D. Howard <gavin@gavinhoward.com>2023-03-02 16:32:59 -0700
committerGavin D. Howard <gavin@gavinhoward.com>2023-03-02 20:32:25 -0700
commit284e329bc419a75470dcb63c03052b8dafcf0976 (patch)
treeb5e2ed7d1be192080ed1a2f82c4fefb4f42eb06d
parent18c2901417dd0965d8ad348c84f5a36b4164943c (diff)
downloadbc-284e329bc419a75470dcb63c03052b8dafcf0976.tar.gz
Fix a possible library build problem
Signed-off-by: Gavin D. Howard <gavin@gavinhoward.com>
-rw-r--r--include/vm.h4
-rw-r--r--src/library.c10
-rw-r--r--src/vm.c2
3 files changed, 16 insertions, 0 deletions
diff --git a/include/vm.h b/include/vm.h
index dd21d43f..c56cc8e7 100644
--- a/include/vm.h
+++ b/include/vm.h
@@ -560,9 +560,13 @@ typedef struct BcVm
/// The vector for creating strings to pass to the client.
BcVec out;
+#if BC_ENABLE_EXTRA_MATH
+
/// The PRNG.
BcRNG rng;
+#endif // BC_ENABLE_EXTRA_MATH
+
/// The current error.
BclError err;
diff --git a/src/library.c b/src/library.c
index 008a0439..cc32a3a3 100644
--- a/src/library.c
+++ b/src/library.c
@@ -217,10 +217,14 @@ bcl_init(void)
bc_vec_init(&vm->ctxts, sizeof(BclContext), BC_DTOR_NONE);
bc_vec_init(&vm->out, sizeof(uchar), BC_DTOR_NONE);
+#if BC_ENABLE_EXTRA_MATH
+
// We need to seed this in case /dev/random and /dev/urandom don't work.
srand((unsigned int) time(NULL));
bc_rand_init(&vm->rng);
+#endif // BC_ENABLE_EXTRA_MATH
+
err:
BC_FUNC_FOOTER(vm, e);
@@ -285,7 +289,9 @@ bcl_free(void)
vm->refs -= 1;
if (vm->refs) return;
+#if BC_ENABLE_EXTRA_MATH
bc_rand_free(&vm->rng);
+#endif // BC_ENABLE_EXTRA_MATH
bc_vec_free(&vm->out);
for (i = 0; i < vm->ctxts.len; ++i)
@@ -1411,6 +1417,8 @@ bcl_string_keep(BclNumber n)
return bcl_string_helper(n, false);
}
+#if BC_ENABLE_EXTRA_MATH
+
static BclNumber
bcl_irand_helper(BclNumber a, bool destruct)
{
@@ -1755,4 +1763,6 @@ bcl_rand_bounded(BclRandInt bound)
return (BclRandInt) bc_rand_bounded(&vm->rng, (BcRand) bound);
}
+#endif // BC_ENABLE_EXTRA_MATH
+
#endif // BC_ENABLE_LIBRARY
diff --git a/src/vm.c b/src/vm.c
index 3a7913e3..29c2715d 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -643,12 +643,14 @@ bc_vm_shutdown(void)
if (vm->catalog != BC_VM_INVALID_CATALOG) catclose(vm->catalog);
#endif // BC_ENABLE_NLS
+#if !BC_ENABLE_LIBRARY
#if BC_ENABLE_HISTORY
// This must always run to ensure that the terminal is back to normal, i.e.,
// has raw mode disabled. But we should only do it if we did not have a bad
// terminal because history was not initialized if it is a bad terminal.
if (BC_TTY && !vm->history.badTerm) bc_history_free(&vm->history);
#endif // BC_ENABLE_HISTORY
+#endif // !BC_ENABLE_LIBRARY
#if BC_DEBUG
#if !BC_ENABLE_LIBRARY