PH7
PH7 copied to clipboard
Cleaner compiles (with diffs)
In Solaris, MAP_FILE doesn't exist, so I added this:
typedef unsigned long long int sxu64; /* 64 bits(8 bytes) unsigned int64 */
#endif /* _MSC_VER */
+
+/* Solaris additions */
+#ifndef MAP_FILE
+# define MAP_FILE 0
+#endif
+
/* Signature of the consumer routine */
typedef int (*ProcConsumer)(const void *,unsigned int,void *);
The function flock() doesn't seem to exist there. The best solution would be to use some other mechanism, but for now I simply disabled it:
@@ -25318,8 +25327,13 @@
/* int (*xLock)(void *,int) */
static int UnixFile_Lock(void *pUserData,int lock_type)
{
- int fd = SX_PTR_TO_INT(pUserData);
int rc = PH7_OK; /* cc warning */
+#ifdef SOLARIS
+ (void) pUserData;
+ (void) lock_type;
+#else
+ int fd = SX_PTR_TO_INT(pUserData);
+
if( lock_type < 0 ){
/* Unlock the file */
rc = flock(fd,LOCK_UN);
@@ -25332,6 +25346,7 @@
rc = flock(fd,LOCK_SH);
}
}
+#endif
return !rc ? PH7_OK : -1;
}
/* ph7_int64 (*xTell)(void *) */
Gcc doesn't like large constants without a suffix:
@@ -875,8 +881,8 @@
#define SXU16_HIGH 0xFFFF
#define SXI32_HIGH 0x7FFFFFFF
#define SXU32_HIGH 0xFFFFFFFF
-#define SXI64_HIGH 0x7FFFFFFFFFFFFFFF
-#define SXU64_HIGH 0xFFFFFFFFFFFFFFFF
+#define SXI64_HIGH 0x7FFFFFFFFFFFFFFFLL
+#define SXU64_HIGH 0xFFFFFFFFFFFFFFFFUL
#if !defined(TRUE)
#define TRUE 1
#endif
These are related to the previous, to avoid duplication:
@@ -32846,7 +32861,7 @@
/* Ticket 1433-003 */
if( longvalue < 0 ){
/* Overflow */
- longvalue= 0x7FFFFFFFFFFFFFFF;
+ longvalue= SXI64_HIGH;
}
prefix = '-';
}else if( flag_plussign ) prefix = '+';
@@ -32858,7 +32873,7 @@
/* Ticket 1433-003 */
if( longvalue < 0 ){
/* Overflow */
- longvalue= 0x7FFFFFFFFFFFFFFF;
+ longvalue= SXI64_HIGH;
}
}
prefix = 0;
@@ -55279,7 +55296,7 @@
/* Ticket 1433-003 */
if( iVal < 0 ){
/* Overflow */
- iVal= 0x7FFFFFFFFFFFFFFF;
+ iVal= SXI64_HIGH;
}
prefix = '-';
}else if( flag_plussign ) prefix = '+';
@@ -55291,7 +55308,7 @@
/* Ticket 1433-003 */
if( iVal < 0 ){
/* Overflow */
- iVal= 0x7FFFFFFFFFFFFFFF;
+ iVal= SXI64_HIGH;
}
}
prefix = 0;
To be able to compile with -Wwrite-strings, a few obvious ones are needed:
@@ -5034,7 +5040,7 @@
{
SyBlob *pWorker = &pVm->sWorker;
SyString *pFile;
- char *zErr;
+ const char *zErr;
sxi32 rc;
if( !pVm->bErrReport ){
/* Don't bother reporting errors */
@@ -5083,7 +5089,7 @@
{
SyBlob *pWorker = &pVm->sWorker;
SyString *pFile;
- char *zErr;
+ const char *zErr;
sxi32 rc;
if( !pVm->bErrReport ){
/* Don't bother reporting errors */
@@ -22083,7 +22092,7 @@
const ph7_io_stream *pStream;
struct csv_data sCsv;
io_private *pDev;
- char *zEol;
+ const char *zEol;
int eolen;
if( nArg < 2 || !ph7_value_is_resource(apArg[0]) || !ph7_value_is_array(apArg[1]) ){
/* Missing/Invalid arguments,return FALSE */
@@ -22083,7 +22092,7 @@
const ph7_io_stream *pStream;
struct csv_data sCsv;
io_private *pDev;
- char *zEol;
+ const char *zEol;
int eolen;
if( nArg < 2 || !ph7_value_is_resource(apArg[0]) || !ph7_value_is_array(apArg[1]) ){
/* Missing/Invalid arguments,return FALSE */
@@ -32603,8 +32618,8 @@
sxu8 base; /* The base for radix conversion */
int flags; /* One or more of SXFLAG_ constants below */
sxu8 type; /* Conversion paradigm */
- char *charset; /* The character set for conversion */
- char *prefix; /* Prefix on non-zero values in alt format */
+ const char *charset; /* The character set for conversion */
+ const char *prefix; /* Prefix on non-zero values in alt format */
};
typedef struct SyFmtConsumer SyFmtConsumer;
struct SyFmtConsumer
@@ -32868,7 +32883,7 @@
}
bufpt = &buf[SXFMT_BUFSIZ-1];
{
- register char *cset; /* Use registers for speed */
+ register const char *cset; /* Use registers for speed */
register int base;
cset = infop->charset;
base = infop->base;
@@ -32883,7 +32898,8 @@
}
if( prefix ) *(--bufpt) = prefix; /* Add sign */
if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */
- char *pre, x;
+ const char *pre;
+ char x;
pre = infop->prefix;
if( *bufpt!=pre[0] ){
for(pre=infop->prefix; (x=(*pre))!=0; pre++) *(--bufpt) = x;
@@ -54996,8 +55012,8 @@
sxu8 base; /* The base for radix conversion */
int flags; /* One or more of PH7_FMT_FLAG_ constants below */
sxu8 type; /* Conversion paradigm */
- char *charset; /* The character set for conversion */
- char *prefix; /* Prefix on non-zero values in alt format */
+ const char *charset; /* The character set for conversion */
+ const char *prefix; /* Prefix on non-zero values in alt format */
};
#ifndef PH7_OMIT_FLOATING_POINT
/*
@@ -55301,7 +55318,7 @@
}
zBuf = &zWorker[PH7_FMT_BUFSIZ-1];
{
- register char *cset; /* Use registers for speed */
+ register const char *cset; /* Use registers for speed */
register int base;
cset = pInfo->charset;
base = pInfo->base;
@@ -55316,7 +55333,8 @@
}
if( prefix ) *(--zBuf) = (char)prefix; /* Add sign */
if( flag_alternateform && pInfo->prefix ){ /* Add "0" or "0x" */
- char *pre, x;
+ const char *pre;
+ char x;
pre = pInfo->prefix;
if( *zBuf!=pre[0] ){
for(pre=pInfo->prefix; (x=(*pre))!=0; pre++) *(--zBuf) = x;
There were a couple of more complicated places, which ideally should be handled by having a separate "char_" and a "const char_". Many of these are quite similar, so perhaps they can be refactored into something common? For now, this also works to get the compiler to shut up:
@@ -32924,7 +32940,7 @@
while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
if( exp>350 || exp<-350 ){
- bufpt = "NaN";
+ bufpt = (char*) "NaN";
length = 3;
break;
}
@@ -33045,7 +33061,7 @@
case SXFMT_STRING:
bufpt = va_arg(ap,char*);
if( bufpt==0 ){
- bufpt = " ";
+ bufpt = (char*) " ";
length = (int)sizeof(" ")-1;
break;
}
@@ -33060,7 +33076,7 @@
/* Symisc extension */
SyString *pStr = va_arg(ap,SyString *);
if( pStr == 0 || pStr->zString == 0 ){
- bufpt = " ";
+ bufpt = (char*) " ";
length = (int)sizeof(char);
break;
}
@@ -55240,7 +55257,7 @@
zBuf = (char *)ph7_value_to_string(pArg,&length);
}
if( length < 1 ){
- zBuf = " ";
+ zBuf = (char*) " ";
length = (int)sizeof(char);
}
if( precision>=0 && precision<length ){
@@ -55369,7 +55387,7 @@
while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
if( exp>350 || exp<-350 ){
- zBuf = "NaN";
+ zBuf = (char*) "NaN";
length = 3;
break;
}
Also, sizeof() is unsigned, while ph7_int64 is signed, so these two are needed (the second one is nicer, I think):
@@ -20543,7 +20549,9 @@
* limit is reached.
*/
for(;;){
- n = pStream->xRead(pDev->pHandle,zBuf,(nMaxLen > 0 && nMaxLen < sizeof(zBuf)) ? nMaxLen : si
zeof(zBuf));
+ n = pStream->xRead(pDev->pHandle, zBuf,
+ (nMaxLen > 0 && nMaxLen < (ph7_int64) sizeof(zBuf)) ?
+ nMaxLen : (ph7_int64) sizeof(zBuf));
if( n < 1 ){
/* EOF or IO error */
break;
@@ -21418,8 +21426,9 @@
/* Perform the requested operation */
nRead = 0;
for(;;){
+ ph7_int64 zBufSz = (ph7_int64) sizeof(zBuf);
n = pStream->xRead(pHandle,zBuf,
- (nMaxlen > 0 && (nMaxlen < sizeof(zBuf))) ? nMaxlen : sizeof(zBuf));
+ (nMaxlen > 0 && (nMaxlen < zBufSz)) ? nMaxlen : zBufSz);
if( n < 1 ){
/* EOF or IO error,break immediately */
break;
Great, thanks for contribution. Will merge all of this upon validation.