libCom/calc: Use epics(U)Int32 for all integer calculations
Adapted backport of 3.15 revision 12308
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "osiUnistd.h"
|
||||
#include "dbDefs.h"
|
||||
#include "epicsMath.h"
|
||||
#include "epicsTypes.h"
|
||||
#include "errlog.h"
|
||||
#include "postfix.h"
|
||||
#include "postfixPvt.h"
|
||||
@@ -43,7 +44,7 @@ epicsShareFunc long
|
||||
double stack[CALCPERFORM_STACK+1]; /* zero'th entry not used */
|
||||
double *ptop; /* stack pointer */
|
||||
double top; /* value from top of stack */
|
||||
int itop; /* integer from top of stack */
|
||||
epicsInt32 itop; /* integer from top of stack */
|
||||
int op;
|
||||
int nargs;
|
||||
|
||||
@@ -55,14 +56,14 @@ epicsShareFunc long
|
||||
switch (op){
|
||||
|
||||
case LITERAL_DOUBLE:
|
||||
memcpy((void *)++ptop, pinst, sizeof(double));
|
||||
memcpy(++ptop, pinst, sizeof(double));
|
||||
pinst += sizeof(double);
|
||||
break;
|
||||
|
||||
case LITERAL_INT:
|
||||
memcpy(&itop, pinst, sizeof(int));
|
||||
memcpy(&itop, pinst, sizeof(epicsInt32));
|
||||
*++ptop = itop;
|
||||
pinst += sizeof(int);
|
||||
pinst += sizeof(epicsInt32);
|
||||
break;
|
||||
|
||||
case FETCH_VAL:
|
||||
@@ -136,11 +137,11 @@ epicsShareFunc long
|
||||
break;
|
||||
|
||||
case MODULO:
|
||||
itop = (long) *ptop--;
|
||||
itop = (epicsInt32) *ptop--;
|
||||
if (itop)
|
||||
*ptop = (long) *ptop % itop;
|
||||
*ptop = (epicsInt32) *ptop % itop;
|
||||
else
|
||||
*ptop = epicsNAN; /* NaN */
|
||||
*ptop = epicsNAN;
|
||||
break;
|
||||
|
||||
case POWER:
|
||||
@@ -261,7 +262,7 @@ epicsShareFunc long
|
||||
|
||||
case NINT:
|
||||
top = *ptop;
|
||||
*ptop = (double)(long)(top >= 0 ? top + 0.5 : top - 0.5);
|
||||
*ptop = (double)(epicsInt32)(top >= 0 ? top + 0.5 : top - 0.5);
|
||||
break;
|
||||
|
||||
case RANDOM:
|
||||
@@ -283,33 +284,33 @@ epicsShareFunc long
|
||||
break;
|
||||
|
||||
case BIT_OR:
|
||||
itop = (long) *ptop--;
|
||||
*ptop = (long) *ptop | itop;
|
||||
itop = (epicsInt32) *ptop--;
|
||||
*ptop = (epicsInt32) *ptop | itop;
|
||||
break;
|
||||
|
||||
case BIT_AND:
|
||||
itop = (long) *ptop--;
|
||||
*ptop = (long) *ptop & itop;
|
||||
itop = (epicsInt32) *ptop--;
|
||||
*ptop = (epicsInt32) *ptop & itop;
|
||||
break;
|
||||
|
||||
case BIT_EXCL_OR:
|
||||
itop = (long) *ptop--;
|
||||
*ptop = (long) *ptop ^ itop;
|
||||
itop = (epicsInt32) *ptop--;
|
||||
*ptop = (epicsInt32) *ptop ^ itop;
|
||||
break;
|
||||
|
||||
case BIT_NOT:
|
||||
itop = (long) *ptop;
|
||||
itop = (epicsInt32) *ptop;
|
||||
*ptop = ~itop;
|
||||
break;
|
||||
|
||||
case RIGHT_SHIFT:
|
||||
itop = (long) *ptop--;
|
||||
*ptop = (long) *ptop >> itop;
|
||||
itop = (epicsInt32) *ptop--;
|
||||
*ptop = (epicsInt32) *ptop >> itop;
|
||||
break;
|
||||
|
||||
case LEFT_SHIFT:
|
||||
itop = (long) *ptop--;
|
||||
*ptop = (long) *ptop << itop;
|
||||
itop = (epicsInt32) *ptop--;
|
||||
*ptop = (epicsInt32) *ptop << itop;
|
||||
break;
|
||||
|
||||
case NOT_EQ:
|
||||
@@ -381,7 +382,7 @@ calcArgUsage(const char *pinst, unsigned long *pinputs, unsigned long *pstores)
|
||||
pinst += sizeof(double);
|
||||
break;
|
||||
case LITERAL_INT:
|
||||
pinst += sizeof(int);
|
||||
pinst += sizeof(epicsInt32);
|
||||
break;
|
||||
case MIN:
|
||||
case MAX:
|
||||
@@ -468,7 +469,7 @@ static int cond_search(const char **ppinst, int match)
|
||||
pinst += sizeof(double);
|
||||
break;
|
||||
case LITERAL_INT:
|
||||
pinst += sizeof(int);
|
||||
pinst += sizeof(epicsInt32);
|
||||
break;
|
||||
case MIN:
|
||||
case MAX:
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "dbDefs.h"
|
||||
#include "epicsStdlib.h"
|
||||
#include "epicsString.h"
|
||||
#include "epicsTypes.h"
|
||||
#include "postfix.h"
|
||||
#include "postfixPvt.h"
|
||||
#include "shareLib.h"
|
||||
@@ -216,7 +217,7 @@ epicsShareFunc long
|
||||
char * const pdest = pout;
|
||||
char *pnext;
|
||||
double lit_d;
|
||||
int lit_i;
|
||||
epicsInt32 lit_i;
|
||||
|
||||
if (psrc == NULL || *psrc == '\0' ||
|
||||
pout == NULL || perror == NULL) {
|
||||
@@ -249,27 +250,29 @@ epicsShareFunc long
|
||||
goto bad;
|
||||
}
|
||||
psrc = pnext;
|
||||
lit_i = (int) lit_d;
|
||||
lit_i = (epicsInt32) lit_d;
|
||||
if (lit_d != (double) lit_i) {
|
||||
*pout++ = pel->code;
|
||||
memcpy(pout, (void *)&lit_d, sizeof(double));
|
||||
memcpy(pout, &lit_d, sizeof(double));
|
||||
pout += sizeof(double);
|
||||
} else {
|
||||
*pout++ = LITERAL_INT;
|
||||
memcpy(pout, (void *)&lit_i, sizeof(int));
|
||||
pout += sizeof(int);
|
||||
memcpy(pout, &lit_i, sizeof(epicsInt32));
|
||||
pout += sizeof(epicsInt32);
|
||||
}
|
||||
}
|
||||
else {
|
||||
lit_i = strtoul(psrc, &pnext, 0);
|
||||
epicsUInt32 lit_ui;
|
||||
|
||||
lit_ui = (epicsUInt32) strtoul(psrc, &pnext, 0);
|
||||
if (pnext == psrc) {
|
||||
*perror = CALC_ERR_BAD_LITERAL;
|
||||
goto bad;
|
||||
}
|
||||
psrc = pnext;
|
||||
*pout++ = LITERAL_INT;
|
||||
memcpy(pout, (void *)&lit_i, sizeof(int));
|
||||
pout += sizeof(int);
|
||||
memcpy(pout, &lit_ui, sizeof(epicsUInt32));
|
||||
pout += sizeof(epicsUInt32);
|
||||
}
|
||||
|
||||
operand_needed = FALSE;
|
||||
@@ -594,18 +597,18 @@ epicsShareFunc void
|
||||
};
|
||||
char op;
|
||||
double lit_d;
|
||||
int lit_i;
|
||||
epicsInt32 lit_i;
|
||||
|
||||
while ((op = *pinst) != END_EXPRESSION) {
|
||||
switch (op) {
|
||||
case LITERAL_DOUBLE:
|
||||
memcpy((void *)&lit_d, ++pinst, sizeof(double));
|
||||
memcpy(&lit_d, ++pinst, sizeof(double));
|
||||
printf("\tDouble %g\n", lit_d);
|
||||
pinst += sizeof(double);
|
||||
break;
|
||||
case LITERAL_INT:
|
||||
memcpy((void *)&lit_i, ++pinst, sizeof(int));
|
||||
printf("\tInteger %d\n", lit_i);
|
||||
memcpy(&lit_i, ++pinst, sizeof(epicsInt32));
|
||||
printf("\tInteger %d (0x%x)\n", lit_i, lit_i);
|
||||
pinst += sizeof(int);
|
||||
break;
|
||||
case MIN:
|
||||
|
||||
Reference in New Issue
Block a user