loci: constify most global variables
The compiler will now put them in rodata, which may be more efficient.
diff --git a/c_gen/c_code_gen.py b/c_gen/c_code_gen.py
index d57f675..7042312 100644
--- a/c_gen/c_code_gen.py
+++ b/c_gen/c_code_gen.py
@@ -897,7 +897,7 @@
"init", \\
"unknown"
-extern const char *of_error_strings[];
+extern const char *const of_error_strings[];
#ifndef NDEBUG
/* #define ASSERT(val) assert(val) */
@@ -1234,7 +1234,7 @@
OF_OBJECT_COUNT = %d
} of_object_id_t;
-extern const char *of_object_id_str[];
+extern const char *const of_object_id_str[];
#define OF_MESSAGE_OBJECT_COUNT %d
""" % ((last + 1), msg_count))
@@ -1295,7 +1295,7 @@
""")
def gen_object_enum_str(out):
- out.write("\nconst char *of_object_id_str[] = {\n")
+ out.write("\nconst char *const of_object_id_str[] = {\n")
out.write(" \"of_object\",\n")
for cls in of_g.ordered_messages:
out.write(" \"%s\",\n" % cls)
@@ -1312,7 +1312,7 @@
# We'll do version strings while we're at it
out.write("""
- const char *of_version_str[] = {
+ const char *const of_version_str[] = {
"Unknown OpenFlow Version",
"OpenFlow-1.0",
"OpenFlow-1.1",
@@ -1348,7 +1348,7 @@
/** @var of_error_strings
* The error string map; use abs value to index
*/
-const char *of_error_strings[] = { OF_ERROR_STRINGS };
+const char *const of_error_strings[] = { OF_ERROR_STRINGS };
""")
################################################################
@@ -2997,7 +2997,7 @@
out.write("""
typedef void (*of_object_init_f)(of_object_t *obj, of_version_t version,
int bytes, int clean_wire);
-extern of_object_init_f of_object_init_map[];
+extern const of_object_init_f of_object_init_map[];
""")
out.write("""
@@ -3125,7 +3125,7 @@
/**
* Map from object ID to type coerce function
*/
-of_object_init_f of_object_init_map[] = {
+const of_object_init_f of_object_init_map[] = {
(of_object_init_f)NULL,
""")
count = 1
diff --git a/c_gen/c_dump_gen.py b/c_gen/c_dump_gen.py
index dbf1e7a..08abae0 100644
--- a/c_gen/c_dump_gen.py
+++ b/c_gen/c_dump_gen.py
@@ -228,7 +228,7 @@
# Generate big table indexed by version and object
for version in of_g.of_version_range:
out.write("""
-static loci_obj_dump_f dump_funs_v%(version)s[OF_OBJECT_COUNT] = {
+static const loci_obj_dump_f dump_funs_v%(version)s[OF_OBJECT_COUNT] = {
""" % dict(version=version))
out.write(" unknown_dump, /* of_object, not a valid specific type */\n")
for j, cls in enumerate(of_g.all_class_order):
@@ -245,7 +245,7 @@
out.write("};\n\n")
out.write("""
-static loci_obj_dump_f *dump_funs[5] = {
+static const loci_obj_dump_f *const dump_funs[5] = {
NULL,
dump_funs_v1,
dump_funs_v2,
diff --git a/c_gen/c_match.py b/c_gen/c_match.py
index 1b5be1e..8c27bb5 100644
--- a/c_gen/c_match.py
+++ b/c_gen/c_match.py
@@ -338,7 +338,7 @@
out.write(""")
/* Indexed by version number */
-extern uint64_t of_match_incompat[4];
+extern const uint64_t of_match_incompat[4];
""")
@@ -387,7 +387,7 @@
}
/* Indexed by version number */
-uint64_t of_match_incompat[4] = {
+const uint64_t of_match_incompat[4] = {
-1,
OF_MATCH_V1_INCOMPAT,
OF_MATCH_V2_INCOMPAT,
diff --git a/c_gen/c_show_gen.py b/c_gen/c_show_gen.py
index 5dab038..14709ab 100644
--- a/c_gen/c_show_gen.py
+++ b/c_gen/c_show_gen.py
@@ -226,7 +226,7 @@
# Generate big table indexed by version and object
for version in of_g.of_version_range:
out.write("""
-static loci_obj_show_f show_funs_v%(version)s[OF_OBJECT_COUNT] = {
+static const loci_obj_show_f show_funs_v%(version)s[OF_OBJECT_COUNT] = {
""" % dict(version=version))
out.write(" unknown_show, /* of_object, not a valid specific type */\n")
for j, cls in enumerate(of_g.all_class_order):
@@ -243,7 +243,7 @@
out.write("};\n\n")
out.write("""
-static loci_obj_show_f *show_funs[5] = {
+static const loci_obj_show_f *const show_funs[5] = {
NULL,
show_funs_v1,
show_funs_v2,
diff --git a/c_gen/c_type_maps.py b/c_gen/c_type_maps.py
index 924243a..d790c85 100644
--- a/c_gen/c_type_maps.py
+++ b/c_gen/c_type_maps.py
@@ -52,7 +52,7 @@
*/
""")
for version in of_g.of_version_range:
- out.write("static int\nof_object_to_type_map_v%d[OF_OBJECT_COUNT] = {\n"
+ out.write("static const int\nof_object_to_type_map_v%d[OF_OBJECT_COUNT] = {\n"
%version)
out.write(" -1, /* of_object, not a valid specific type */\n")
for j, cls in enumerate(of_g.all_class_order):
@@ -112,7 +112,7 @@
/**
* Unified map, indexed by wire version which is 1-based.
*/
-int *of_object_to_type_map[OF_VERSION_ARRAY_MAX] = {
+const int *const of_object_to_type_map[OF_VERSION_ARRAY_MAX] = {
NULL,
""")
for version in of_g.of_version_range:
@@ -130,7 +130,7 @@
""")
for version in of_g.of_version_range:
out.write("""
-static of_experimenter_data_t
+static const of_experimenter_data_t
of_object_to_extension_data_v%d[OF_OBJECT_COUNT] = {
""" % version)
out.write(" {0, 0, 0}, /* of_object, not a valid specific type */\n")
@@ -153,7 +153,7 @@
/**
* Unified map, indexed by wire version which is 1-based.
*/
-of_experimenter_data_t *of_object_to_extension_data[OF_VERSION_ARRAY_MAX] = {
+const of_experimenter_data_t *const of_object_to_extension_data[OF_VERSION_ARRAY_MAX] = {
NULL,
""")
for version in of_g.of_version_range:
@@ -182,7 +182,7 @@
for i, ar in enumerate(all_ars):
version = i + 1
- out.write("static of_object_id_t\nof_%s_v%d[%s] = {\n" %
+ out.write("static const of_object_id_t\nof_%s_v%d[%s] = {\n" %
(type_str, version, len_name))
for i in range(arr_len):
comma = ""
@@ -210,7 +210,7 @@
* Indexed by wire version which is 1-based.
*/
-of_object_id_t *of_%(name)s[OF_VERSION_ARRAY_MAX] = {
+const of_object_id_t *const of_%(name)s[OF_VERSION_ARRAY_MAX] = {
NULL,
""" % dict(name=type_str, c_name=prefix.lower()))
for version in of_g.of_version_range:
@@ -291,7 +291,7 @@
* Treat as private; use function accessor below
*/
-extern of_object_id_t *of_%(name)s_type_to_id[OF_VERSION_ARRAY_MAX];
+extern const of_object_id_t *const of_%(name)s_type_to_id[OF_VERSION_ARRAY_MAX];
#define OF_%(u_name)s_ITEM_COUNT %(ar_len)d\n
@@ -322,7 +322,7 @@
* Treat as private; use function accessor below
*/
-extern of_object_id_t *of_%(name)s_type_to_id[OF_VERSION_ARRAY_MAX];
+extern const of_object_id_t *const of_%(name)s_type_to_id[OF_VERSION_ARRAY_MAX];
#define OF_%(u_name)s_ITEM_COUNT %(ar_len)d\n
@@ -357,7 +357,7 @@
* Treat as private; use function accessor below
*/
-extern of_object_id_t *of_%(name)s_type_to_id[OF_VERSION_ARRAY_MAX];
+extern const of_object_id_t *const of_%(name)s_type_to_id[OF_VERSION_ARRAY_MAX];
#define OF_%(u_name)s_ITEM_COUNT %(ar_len)d\n
@@ -441,7 +441,7 @@
* Treat as private; use function accessor below
*/
-extern of_object_id_t *of_%(name)s_type_to_id[OF_VERSION_ARRAY_MAX];
+extern const of_object_id_t *const of_%(name)s_type_to_id[OF_VERSION_ARRAY_MAX];
#define OF_%(u_name)s_ITEM_COUNT %(ar_len)d\n
@@ -586,7 +586,7 @@
################################################################
out.write("""
-extern int *of_object_to_type_map[OF_VERSION_ARRAY_MAX];
+extern const int *const of_object_to_type_map[OF_VERSION_ARRAY_MAX];
/**
* Map an object ID to its primary wire type value
@@ -632,7 +632,7 @@
""")
out.write("""
-extern of_experimenter_data_t *of_object_to_extension_data[OF_VERSION_ARRAY_MAX];
+extern const of_experimenter_data_t *const of_object_to_extension_data[OF_VERSION_ARRAY_MAX];
/**
* Map from the object ID of an extension to the experimenter ID
@@ -792,7 +792,7 @@
gen_type_to_obj_map_functions(out)
gen_obj_to_type_map_functions(out)
- out.write("extern int *of_object_fixed_len[OF_VERSION_ARRAY_MAX];\n")
+ out.write("extern const int *const of_object_fixed_len[OF_VERSION_ARRAY_MAX];\n")
out.write("""
/**
@@ -1038,7 +1038,7 @@
for version in of_g.of_version_range:
out.write("""
-static int\nof_object_fixed_len_v%d[OF_OBJECT_COUNT] = {
+static const int\nof_object_fixed_len_v%d[OF_OBJECT_COUNT] = {
-1, /* of_object is not instantiable */
""" % version)
for i, cls in enumerate(of_g.all_class_order):
@@ -1055,7 +1055,7 @@
/**
* Unified map of fixed length part of each object
*/
-int *of_object_fixed_len[OF_VERSION_ARRAY_MAX] = {
+const int *const of_object_fixed_len[OF_VERSION_ARRAY_MAX] = {
NULL,
""")
for version in of_g.of_version_range:
@@ -1078,7 +1078,7 @@
*/
""")
for version in of_g.of_version_range:
- out.write("int *of_object_to_stats_type_map_v%d = {\n" % (i+1))
+ out.write("const int *of_object_to_stats_type_map_v%d = {\n" % (i+1))
out.write(" -1, /* of_object (invalid) */\n");
for cls in of_g.ordered_messages:
name = cls[3:]
@@ -1096,7 +1096,7 @@
/**
* Unified map, indexed by wire version which is 1-based.
*/
-int *of_object_to_stats_type_map[OF_VERSION_ARRAY_MAX] = {
+const int *of_object_to_stats_type_map[OF_VERSION_ARRAY_MAX] = {
NULL,
""")
for version in of_g.of_version_range: