From 9a2d9685773a967b46633718a10f1a9f98a8086a Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 31 Jul 2021 12:53:55 +0200 Subject: [PATCH] When transferring boolean data over the ABI, keep them as boolean types, not integer Replace the type of all boolean variables around the ABI by NG_BOOL. NG_BOOL is typedefed to _Bool, when compiling shared ngspice. When sharedspice.h is use externally NG_BOOL is typdefed to bool --- src/include/ngspice/sharedspice.h | 14 +++++++++++--- src/sharedspice.c | 10 +++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/include/ngspice/sharedspice.h b/src/include/ngspice/sharedspice.h index 5d90ade2a..dad7381c2 100644 --- a/src/include/ngspice/sharedspice.h +++ b/src/include/ngspice/sharedspice.h @@ -87,7 +87,8 @@ ngspice.dll should never call exit() directly, but handle either the 'quit' request to the caller or an request for exiting upon error, done by callback function ngexit(). -All boolean signals (NG_BOOL) are of type int. +All boolean signals (NG_BOOL) are of type _Bool, if ngspice is compiled. They +are of type bool if sharedspice.h is used externally. */ #ifndef NGSPICE_PACKAGE_VERSION @@ -134,8 +135,15 @@ struct ngcomplex { typedef struct ngcomplex ngcomplex_t; #endif -/* ngspice traditionally treats a boolean var as int */ -typedef int NG_BOOL; +/* NG_BOOL is the boolean variable at the ngspice interface. + When ompiling ngspice shared module, typedef to _BOOL, which is boolean in C, + when used externally, keep it to be of type bool, + as has been available in the past. */ +#ifndef SHARED_MODULE +typedef bool NG_BOOL; +#else +typedef _Bool NG_BOOL; +#endif /* vector info obtained from any vector in ngspice.dll. Allows direct access to the ngspice internal vector structure, diff --git a/src/sharedspice.c b/src/sharedspice.c index 4c0ae86c1..bdf293362 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -378,8 +378,8 @@ static bool nobgtrwanted = FALSE; static bool wantvdat = FALSE; static bool wantidat = FALSE; static bool wantsync = FALSE; -static bool immediate = FALSE; -static bool coquit = FALSE; +static NG_BOOL immediate = FALSE; +static NG_BOOL coquit = FALSE; static jmp_buf errbufm, errbufc; static int intermj = 1; #ifdef XSPICE @@ -452,7 +452,7 @@ SIMinit(IFfrontEnd* frontEnd, IFsimulator** simulator) static threadId_t tid, printtid, tid2; static bool fl_running = FALSE; -static bool fl_exited = TRUE; +static NG_BOOL fl_exited = TRUE; static bool printstopp = FALSE; static bool ps_exited = TRUE; @@ -776,7 +776,7 @@ read_initialisation_file(const char *dir, const char *name) /* Checks if ngspice is running in the background */ IMPEXP -bool +NG_BOOL ngSpice_running (void) { return (fl_running && !fl_exited); @@ -1231,7 +1231,7 @@ static int bkpttmpsize = 0; /* set a breakpoint in ngspice */ IMPEXP -bool ngSpice_SetBkpt(double time) +NG_BOOL ngSpice_SetBkpt(double time) { int error; CKTcircuit *ckt = NULL;