ref: ea47856f32ee8063d5fe7eb3b1fe5b6094320db2
parent: 783f049aa71a90b0ea02918e04b30a6b45b6a75e
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Mon Nov 11 14:23:47 EST 2024
fixed some of the strings not marked with const
--- a/3rd/mp/strtomp.c
+++ b/3rd/mp/strtomp.c
@@ -1,9 +1,9 @@
#include "platform.h"
-static char*
-frompow2(char *a, mpint *b, int s)
+static const char*
+frompow2(const char *a, mpint *b, int s)
{
- char *p, *next;
+ const char *p, *next;
mpdigit x;
uint32_t i;
@@ -27,10 +27,10 @@
return next;
}
-static char*
-from8(char *a, mpint *b)
+static const char*
+from8(const char *a, mpint *b)
{
- char *p, *next;
+ const char *p, *next;
mpdigit x, y;
int i;
@@ -64,8 +64,8 @@
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
};
-static char*
-from10(char *a, mpint *b)
+static const char*
+from10(const char *a, mpint *b)
{
uint32_t x, y;
mpint *pow, *r;
@@ -103,10 +103,10 @@
}
mpint*
-strtomp(char *a, char **pp, int base, mpint *b)
+strtomp(const char *a, char **pp, int base, mpint *b)
{
int sign;
- char *e;
+ const char *e;
if(b == nil){
b = mpnew(0);
@@ -163,7 +163,7 @@
}
if(pp != nil)
- *pp = e;
+ *pp = (char*)e;
// if no characters parsed, there wasn't a number to convert
if(e == a)
--- a/flisp.c
+++ b/flisp.c
@@ -162,13 +162,13 @@
// symbol table ---------------------------------------------------------------
int
-fl_is_keyword_name(char *str, size_t len)
+fl_is_keyword_name(const char *str, size_t len)
{
return (str[0] == ':' || str[len-1] == ':') && str[1] != '\0';
}
static symbol_t *
-mk_symbol(char *str)
+mk_symbol(const char *str)
{
symbol_t *sym;
size_t len = strlen(str);
@@ -189,7 +189,7 @@
}
static symbol_t **
-symtab_lookup(symbol_t **ptree, char *str)
+symtab_lookup(symbol_t **ptree, const char *str)
{
int x;
while(*ptree != nil && (x = strcmp(str, (*ptree)->name)) != 0)
@@ -198,7 +198,7 @@
}
value_t
-symbol(char *str)
+symbol(const char *str)
{
symbol_t **pnode;
@@ -253,7 +253,7 @@
return &dest[i+1];
}
-char *
+const char *
symbol_name(value_t v)
{
if(ismanaged(v)){
--- a/flisp.h
+++ b/flisp.h
@@ -176,8 +176,8 @@
/* symbol table */
value_t gensym(void);
-value_t symbol(char *str);
-char *symbol_name(value_t v);
+value_t symbol(const char *str);
+const char *symbol_name(value_t v);
/* read, eval, print main entry points */
value_t fl_toplevel_eval(value_t expr);
@@ -189,7 +189,7 @@
value_t fl_list2(value_t a, value_t b);
value_t fl_listn(size_t n, ...);
int fl_isnumber(value_t v);
-int fl_is_keyword_name(char *str, size_t len);
+int fl_is_keyword_name(const char *str, size_t len);
value_t alloc_vector(size_t n, int init);
/* safe casts */
--- a/posix/mp.h
+++ b/posix/mp.h
@@ -97,7 +97,7 @@
mpint* mpnrand(mpint *n, void (*gen)(uchar*, int), mpint *b);
/* conversion */
-mpint* strtomp(char*, char**, int, mpint*); /* ascii */
+mpint* strtomp(const char*, char**, int, mpint*); /* ascii */
char* mptoa(mpint*, int, char*, int);
mpint* letomp(uchar*, uint, mpint*); /* byte array, little-endian */
int mptole(mpint*, uchar*, uint, uchar**);
--- a/print.c
+++ b/print.c
@@ -18,7 +18,7 @@
}
static void
-outs(char *s, ios_t *f)
+outs(const char *s, ios_t *f)
{
ios_puts(s, f);
FL(hpos) += u8_strwidth(s);
@@ -25,7 +25,7 @@
}
static void
-outsn(char *s, ios_t *f, size_t n)
+outsn(const char *s, ios_t *f, size_t n)
{
ios_write(f, s, n);
FL(hpos) += u8_strwidth(s);
@@ -59,7 +59,7 @@
}
void
-fl_print_str(char *s, ios_t *f)
+fl_print_str(const char *s, ios_t *f)
{
outs(s, f);
}
@@ -113,7 +113,7 @@
}
static void
-print_symbol_name(ios_t *f, char *name)
+print_symbol_name(ios_t *f, const char *name)
{
int i, escape = 0, charescape = 0;
@@ -390,7 +390,7 @@
void
fl_print_child(ios_t *f, value_t v)
{
- char *name;
+ const char *name;
if(FL(print_level) >= 0 && FL(p_level) >= FL(print_level) && (iscons(v) || isvector(v) || isclosure(v))){
outc('#', f);
return;
@@ -502,7 +502,7 @@
}
static void
-print_string(ios_t *f, char *str, size_t sz)
+print_string(ios_t *f, const char *str, size_t sz)
{
char buf[512];
size_t i = 0;
--- a/print.h
+++ b/print.h
@@ -3,5 +3,5 @@
void fl_print(ios_t *f, value_t v);
void print_traverse(value_t v);
void fl_print_chr(char c, ios_t *f);
-void fl_print_str(char *s, ios_t *f);
+void fl_print_str(const char *s, ios_t *f);
void fl_print_child(ios_t *f, value_t v);
--- a/read.c
+++ b/read.c
@@ -27,7 +27,7 @@
#endif
static int64_t
-strtoll_mp(char *nptr, char **rptr, int base, mpint **mp)
+strtoll_mp(const char *nptr, char **rptr, int base, mpint **mp)
{
int64_t x;
mpint *m;
@@ -63,7 +63,7 @@
}
static uint64_t
-strtoull_mp(char *nptr, char **rptr, int base, mpint **mp)
+strtoull_mp(const char *nptr, char **rptr, int base, mpint **mp)
{
uint64_t x;
mpint *m;
@@ -93,7 +93,7 @@
#define RS value2c(ios_t*, FL(readstate)->source)
int
-isnumtok_base(char *tok, value_t *pval, int base)
+isnumtok_base(const char *tok, value_t *pval, int base)
{
char *end;
int64_t i64;
@@ -153,13 +153,13 @@
}
int
-isnumtok(char *tok, value_t *pval)
+isnumtok(const char *tok, value_t *pval)
{
return isnumtok_base(tok, pval, 0);
}
static int
-read_numtok(char *tok, value_t *pval, int base)
+read_numtok(const char *tok, value_t *pval, int base)
{
return isnumtok_base(tok, pval, base);
}
--- a/read.h
+++ b/read.h
@@ -1,8 +1,8 @@
#pragma once
value_t fl_read_sexpr(value_t f);
-int isnumtok_base(char *tok, value_t *pval, int base);
-int isnumtok(char *tok, value_t *pval);
+int isnumtok_base(const char *tok, value_t *pval, int base);
+int isnumtok(const char *tok, value_t *pval);
// defines which characters are ordinary symbol characters.
// exceptions are '.', which is an ordinary symbol character