]> git.neil.brown.name Git - edlib.git/commitdiff
Mark various 'static' values as 'const'.
authorNeilBrown <neil@brown.name>
Mon, 12 Jun 2023 01:21:37 +0000 (11:21 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 07:51:40 +0000 (17:51 +1000)
Anything that can be const now it.

 git grep -nH 'static[^(]*[=;]' | grep -v const | grep -v 'struct map'

can help find things that should be const, or maybe should put moved to
the 'editor' pane.

Signed-off-by: NeilBrown <neil@brown.name>
core-misc.c
display-ncurses.c
display-x11-xcb.c
doc-email.c
edlib.c
lang-python.c
lib-autosave.c
lib-view.c
lib-wiggle.c
lib-x11selection-xcb.c
md5.h

index 4364e011a36ae90834b2283390a11476fc0cf1c4..c2f0656cc51c1eee6d41f87fabf416daf4e2a130 100644 (file)
@@ -81,7 +81,7 @@ static void dump_count_hash(void);
 static void stat_dump(void);
 static void dump_mem(void);
 
-static char *tnames[] = {
+static const char *tnames[] = {
        [TIME_KEY]     = "KEY",
        [TIME_WINDOW]  = "WINDOW",
        [TIME_READ]    = "READ",
index 49c5af4a965dee1877b303e0093893a490418604..e960d6f8a43ffaea765575fbc30682987fd0379a 100644 (file)
@@ -1109,7 +1109,7 @@ DEF_CMD(nc_draw_image)
                cy = y + ci->focus->cy;
        }
        for (i = 0; i < h; i+= 2) {
-               static wint_t hilo = 0x2580; /* L'▀' */
+               static const wint_t hilo = 0x2580; /* L'▀' */
                for (j = 0; j < w ; j+= 1) {
                        unsigned char *p1 = buf + i*w*4 + j*4;
                        unsigned char *p2 = buf + (i+1)*w*4 + j*4;
index 6d124a077ed91a21f3ca3597b287ccc6633ac118..850309748b6e1d5bff54637b18d3477d06792a7d 100644 (file)
@@ -156,7 +156,7 @@ enum my_atoms {
        a_UTF8_STRING,
        NR_ATOMS
 };
-static char *atom_names[NR_ATOMS] = {
+static const char *atom_names[NR_ATOMS] = {
        [a_NONE]                = "NONE",
        [a_WM_STATE]            = "_NET_WM_STATE",
        [a_STATE_FULLSCREEN]    = "_NET_WM_STATE_FULLSCREEN",
@@ -1786,7 +1786,7 @@ static struct pane *xcb_display_init(const char *d safe,
        xd->visual = xcb_depth_visuals(di.data);
 
        for (i = 0; i < NR_ATOMS; i++) {
-               char *n = atom_names[i];
+               const char *n = atom_names[i];
                if (!n)
                        continue;
                cookies[i] = xcb_intern_atom(conn, 0, strlen(n), n);
index 6204b8a87d889e36b9ea4e61fa69526f1d1f1357..b6742318bbdee225912d703e7e2568ec1741cf32 100644 (file)
@@ -353,7 +353,7 @@ static struct map *email_view_map safe;
 
 DEF_LOOKUP_CMD(email_view_handle, email_view_map);
 
-static char tspecials[] = "()<>@,;:\\\"/[]?=";
+static const char tspecials[] = "()<>@,;:\\\"/[]?=";
 
 static int lws(char c) {
        return c == ' '  || c == '\t' || c == '\r' || c == '\n';
diff --git a/edlib.c b/edlib.c
index b98aa01d8f3cb974140a92e113938c6504c9efac..6471c635a60db2564f03e44560039a227e2d0c64 100644 (file)
--- a/edlib.c
+++ b/edlib.c
@@ -17,7 +17,7 @@
 #include "core.h"
 #include "misc.h"
 
-static char WelcomeText[] =
+static const char WelcomeText[] =
        "\n"
        "Welcome to 'edlib' - a document editor that comes in well defined pieces.\n"
        "\n"
@@ -45,7 +45,7 @@ static char WelcomeText[] =
        "Mouse clicks move the cursor, and clicking on the scroll bar scrolls\n"
        ;
 
-static char shortopt[] = "gtx";
+static const char shortopt[] = "gtx";
 
 int main(int argc, char *argv[])
 {
index 5429e3abb070d3558c398f4739ff200d2cf32125..743bd1c5f83d91c6e8dcf393a601c97c1839dff4 100644 (file)
@@ -702,7 +702,7 @@ static int __Pane_init(Pane *self safe, PyObject *args, PyObject *kwds,
 {
        Pane *parent = NULL;
        int ret;
-       static char *keywords[] = {"parent", "z", NULL};
+       static const char *keywords[] = {"parent", "z", NULL};
 
        if (self->pane) {
                PyErr_SetString(PyExc_TypeError, "Pane already initialised");
@@ -715,7 +715,7 @@ static int __Pane_init(Pane *self safe, PyObject *args, PyObject *kwds,
                return 0;
 
        /* Pane(parent=None, z=0) */
-       ret = PyArg_ParseTupleAndKeywords(args, kwds, "|Oi", keywords,
+       ret = PyArg_ParseTupleAndKeywords(args, kwds, "|Oi", (char**)keywords,
                                          &parent, zp);
        if (ret <= 0)
                return -1;
@@ -1497,7 +1497,7 @@ static PyObject *Pane_vmark_at_or_before(Pane *self safe, PyObject *args)
        return Py_None;
 }
 
-static PyMethodDef pane_methods[] = {
+static const PyMethodDef pane_methods[] = {
        {"close", (PyCFunction)Pane_close, METH_NOARGS,
         "close the pane"},
        {"children", (PyCFunction)pane_children, METH_NOARGS,
@@ -1672,7 +1672,7 @@ static PyObject *pane_cmp(Pane *p1 safe, Pane *p2 safe, int op)
        Py_RETURN_RICHCOMPARE(p1->pane, p2->pane, op);
 }
 
-static PyGetSetDef pane_getseters[] = {
+static const PyGetSetDef pane_getseters[] = {
        {"x",
         (getter)pane_getnum, (setter)pane_setnum,
         "X offset in parent", "x" },
@@ -1758,7 +1758,7 @@ static int Pane_set_item(Pane *self safe, PyObject *key, PyObject *val)
        return 0;
 }
 
-static PyMappingMethods pane_mapping = {
+static const PyMappingMethods pane_mapping = {
        .mp_length = NULL,
        .mp_subscript = (binaryfunc)Pane_get_item,
        .mp_ass_subscript = (objobjargproc)Pane_set_item,
@@ -1771,13 +1771,13 @@ static PyTypeObject PaneType = {
        .tp_dealloc     = (destructor)pane_dealloc,
        .tp_richcompare = (richcmpfunc)pane_cmp,
        .tp_repr        = (reprfunc)pane_repr,
-       .tp_as_mapping  = &pane_mapping,
+       .tp_as_mapping  = (PyMappingMethods*)&pane_mapping,
        .tp_hash        = (hashfunc)pane_hash,
        .tp_call        = (ternaryfunc)pane_direct_call,
        .tp_flags       = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
        .tp_doc         = "edlib panes",
-       .tp_methods     = pane_methods,
-       .tp_getset      = pane_getseters,
+       .tp_methods     = (PyMethodDef*)pane_methods,
+       .tp_getset      = (PyGetSetDef*)pane_getseters,
        .tp_init        = (initproc)Pane_init,
        .tp_new         = (newfunc)pane_new,
 };
@@ -1829,7 +1829,7 @@ static PyObject *to_end(Doc *self safe, PyObject *args)
        return Py_None;
 }
 
-static PyMethodDef doc_methods[] = {
+static const PyMethodDef doc_methods[] = {
        {"first_mark", (PyCFunction)first_mark, METH_NOARGS,
         "first mark of document"},
        {"to_end", (PyCFunction)to_end, METH_VARARGS,
@@ -1845,7 +1845,7 @@ static PyTypeObject DocType = {
        .tp_repr        = (reprfunc)doc_repr,
        .tp_flags       = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
        .tp_doc         = "edlib document",
-       .tp_methods     = doc_methods,
+       .tp_methods     = (PyMethodDef*)doc_methods,
        .tp_base        = &PaneType,
        .tp_init        = (initproc)Doc_init,
        .tp_new         = (newfunc)Doc_new,
@@ -2003,7 +2003,7 @@ static PyObject *mark_compare(Mark *a safe, Mark *b safe, int op)
        }
 }
 
-static PyGetSetDef mark_getseters[] = {
+static const PyGetSetDef mark_getseters[] = {
        {"pos",
         (getter)mark_getpos, (setter)mark_setpos,
         "Position ref", NULL},
@@ -2036,7 +2036,7 @@ static int Mark_init(Mark *self safe, PyObject *args safe, PyObject *kwds)
        Pane *owner = NULL;
        int view = MARK_UNGROUPED;
        Mark *orig = NULL;
-       static char *keywords[] = {"pane","view","orig", "owner", NULL};
+       static const char *keywords[] = {"pane","view","orig", "owner", NULL};
        int ret;
 
        if (!PyTuple_Check(args) ||
@@ -2044,7 +2044,7 @@ static int Mark_init(Mark *self safe, PyObject *args safe, PyObject *kwds)
                /* Internal Mark_Frommark call */
                return 1;
 
-       ret = PyArg_ParseTupleAndKeywords(args, kwds, "|O!iO!O!", keywords,
+       ret = PyArg_ParseTupleAndKeywords(args, kwds, "|O!iO!O!", (char**)keywords,
                                          &PaneType, &doc,
                                          &view,
                                          &MarkType, &orig,
@@ -2297,7 +2297,7 @@ static PyObject *Mark_watch(Mark *self safe, PyObject *args)
        return Py_None;
 }
 
-static PyMethodDef mark_methods[] = {
+static const PyMethodDef mark_methods[] = {
        {"to_mark", (PyCFunction)Mark_to_mark, METH_VARARGS,
         "Move one mark to another"},
        {"to_mark_noref", (PyCFunction)Mark_to_mark_noref, METH_VARARGS,
@@ -2396,7 +2396,7 @@ static PyObject *mark_repr(Mark *self safe)
        return ret;
 }
 
-static PyMappingMethods mark_mapping = {
+static const PyMappingMethods mark_mapping = {
        .mp_length = NULL,
        .mp_subscript = (binaryfunc)mark_get_item,
        .mp_ass_subscript = (objobjargproc)mark_set_item,
@@ -2407,7 +2407,7 @@ static int mark_bool(Mark *self safe)
        return mark_valid(self->mark);
 }
 
-static PyNumberMethods mark_as_num = {
+static const PyNumberMethods mark_as_num = {
        .nb_bool        = (inquiry) mark_bool,
 };
 
@@ -2416,16 +2416,16 @@ static PyTypeObject MarkType = {
        .tp_name        = "edlib.Mark",
        .tp_basicsize   = sizeof(Mark),
        .tp_dealloc     = (destructor)mark_dealloc,
-       .tp_as_mapping  = &mark_mapping,
+       .tp_as_mapping  = (PyMappingMethods*)&mark_mapping,
        .tp_flags       = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
        .tp_doc         = "edlib marks",
        .tp_richcompare = (richcmpfunc)mark_compare,
-       .tp_methods     = mark_methods,
-       .tp_getset      = mark_getseters,
+       .tp_methods     = (PyMethodDef*)mark_methods,
+       .tp_getset      = (PyGetSetDef*)mark_getseters,
        .tp_init        = (initproc)Mark_init,
        .tp_new         = (newfunc)mark_new,
        .tp_repr        = (reprfunc)mark_repr,
-       .tp_as_number   = &mark_as_num,
+       .tp_as_number   = (PyNumberMethods*)&mark_as_num,
 };
 
 static void comm_dealloc(Comm *self safe)
@@ -2887,7 +2887,7 @@ static PyObject *py_LOG_BT(PyObject *self, PyObject *args)
        return Py_None;
 }
 
-static PyMethodDef edlib_methods[] = {
+static const PyMethodDef edlib_methods[] = {
        {"time_start", py_time_start, METH_VARARGS,
         "Record start time"},
        {"time_stop", py_time_stop, METH_VARARGS,
@@ -2943,7 +2943,7 @@ void edlib_init(struct pane *ed safe)
 
        PyModule_SetDocString(m , "edlib - one more editor is never enough");
 
-       PyModule_AddFunctions(m, edlib_methods);
+       PyModule_AddFunctions(m, (PyMethodDef*)edlib_methods);
        PyModule_AddObject(m, "editor", Pane_Frompane(ed));
        PyModule_AddObject(m, "Pane", (PyObject *)&PaneType);
        PyModule_AddObject(m, "PaneIter", (PyObject *)&PaneIterType);
index 3218620bfd7fa4dce1e5780c99f229608149ce06..176ea699c4ce747b916c24df5bd94463f9fcf700 100644 (file)
@@ -23,7 +23,7 @@
  * 'n' or 'q' discard the diff.
  */
 
-static char mesg[] =
+static const char mesg[] =
        "\nAutosave file has these differences, type:\n"
        "'y' to restore,\n"
        "'n' to ignore,\n"
index 321263e5060ce43e721f20d26057a0b973310a0d..ef172301d50db48b92b3b5232e8e628f1a002299 100644 (file)
@@ -44,12 +44,12 @@ DEF_LOOKUP_CMD(view_handle, view_map);
 static struct pane *do_view_attach(struct pane *par, int border);
 static int calc_border(struct pane *p safe);
 
-static char default_status[] =
+static const char default_status[] =
        "{!CountLinesAsync}M:{doc-modified?,*,-}{doc-readonly?,%%,  } D:{doc-file-changed?,CHANGED:,}{doc-name%-15} L{^line}/{lines} {display-context}{render-default}/{view-default} {doc-status}";
-static char default_title[] =
+static const char default_title[] =
        "{doc-name}";
 
-static char *format_status(char *status safe,
+static char *format_status(const char *status safe,
                           struct pane *focus safe,
                           struct mark *pm)
 {
@@ -152,7 +152,7 @@ static char *format_status(char *status safe,
        return buf_final(&b);
 }
 
-static void one_char(struct pane *p safe, char *s, char *attr, int x, int y)
+static void one_char(struct pane *p safe, const char *s, char *attr, int x, int y)
 {
        call("Draw:text", p, -1, NULL, s, 0, NULL, attr, x, y);
 }
@@ -163,8 +163,8 @@ DEF_CMD(view_refresh)
        struct view_data *vd = p->data;
        int i;
        struct mark *pm;
-       char *status;
-       char *title;
+       const char *status;
+       const char *title;
 
        if (vd->border <= 0)
                return 1;
@@ -252,9 +252,6 @@ DEF_CMD(view_refresh)
        if (!(~vd->border & (BORDER_RIGHT|BORDER_BOT)))
                one_char(p, "┛", "inverse", p->w-vd->border_width, p->h-vd->border_height+vd->ascent);
 
-       free(status);
-       free(title);
-
        return 1;
 }
 
index c1724c46e7a6a96079da826fba7b15233564ef07..fabc085e4685e292e5777cdea654d07bdd7334a2 100644 (file)
@@ -368,7 +368,7 @@ DEF_CMD(wiggle_set_common)
        return ret;
 }
 
-static char *typenames[] = {
+static const char *typenames[] = {
        [End] = "End",
        [Unmatched] = "Unmatched",
        [Unchanged] = "Unchanged",
index 0d72c38c8ad3025c1aaa8de18048b0137e4ce921..398768a79b9d32ef80a87ab4e9f9e8f79abfa349 100644 (file)
@@ -117,7 +117,7 @@ enum my_atoms {
        NR_ATOMS,
        NR_TARGETS = a_NULL,
 };
-static char *atom_names[NR_ATOMS] = {
+static const char *atom_names[NR_ATOMS] = {
        [a_TIMESTAMP]           = "TIMESTAMP",
        [a_TARGETS]             = "TARGETS",
        [a_MULTIPLE]            = "MULTIPLE",
@@ -1007,7 +1007,7 @@ static struct command *xcb_register(struct pane *p safe, char *display safe)
        xci->screen = safe_cast iter.data;
 
        for (i = 0; i < NR_ATOMS; i++) {
-               char *n = atom_names[i];
+               const char *n = atom_names[i];
                if (!n)
                        continue;
                cookies[i] = xcb_intern_atom(conn, 0, strlen(n), n);
diff --git a/md5.h b/md5.h
index 6b6e1863e76fb17635e03c0a064eb0ad4c25d467..734d6fc8a4da24ea1b1580b67e46bbb5c99f8ecd 100644 (file)
--- a/md5.h
+++ b/md5.h
@@ -198,7 +198,7 @@ static void md5_final(struct md5_state *mctx safe, uint8_t out[MD5_DIGEST_SIZE])
        memset(mctx, 0, sizeof(*mctx));
 }
 
-static char _md5_hex[] = "0123456789ABCDEF";
+static const char _md5_hex[] = "0123456789ABCDEF";
 static void md5_final_txt(struct md5_state *mctx safe, char out[MD5_DIGEST_SIZE*2+1])
 {
        uint8_t outb[MD5_DIGEST_SIZE];