Use macro instead of const int to avoid warning.

Avoid -pedantic warnings under Clang regarding variable-length arrays by
using a macro rather than const integer type.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/1d57b5ce
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/1d57b5ce
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/1d57b5ce

Branch: refs/heads/master
Commit: 1d57b5ced639e9832cb8a77218040c95780a7a94
Parents: e9fcb61
Author: Marvin Humphrey <[email protected]>
Authored: Fri Feb 22 19:06:59 2013 -0800
Committer: Marvin Humphrey <[email protected]>
Committed: Fri Apr 5 14:05:54 2013 -0700

----------------------------------------------------------------------
 clownfish/compiler/src/CFCClass.c    |   14 ++++++++------
 clownfish/compiler/src/CFCDumpable.c |    4 ++--
 clownfish/compiler/src/CFCType.c     |   10 ++++++----
 3 files changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/1d57b5ce/clownfish/compiler/src/CFCClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCClass.c 
b/clownfish/compiler/src/CFCClass.c
index d3287dd..41f9e79 100644
--- a/clownfish/compiler/src/CFCClass.c
+++ b/clownfish/compiler/src/CFCClass.c
@@ -264,6 +264,8 @@ S_register(CFCClass *self) {
     registry_size++;
 }
 
+#define MAX_SINGLETON_LEN 256
+
 CFCClass*
 CFCClass_fetch_singleton(CFCParcel *parcel, const char *class_name) {
     CFCUTIL_NULL_CHECK(class_name);
@@ -276,11 +278,10 @@ CFCClass_fetch_singleton(CFCParcel *parcel, const char 
*class_name) {
     const char *prefix = parcel ? CFCParcel_get_prefix(parcel) : "";
     size_t prefix_len = strlen(prefix);
     size_t struct_sym_len = strlen(struct_sym);
-    const size_t MAX_LEN = 256;
-    if (prefix_len + struct_sym_len > MAX_LEN) {
+    if (prefix_len + struct_sym_len > MAX_SINGLETON_LEN) {
         CFCUtil_die("names too long: '%s', '%s'", prefix, struct_sym);
     }
-    char key[MAX_LEN + 1];
+    char key[MAX_SINGLETON_LEN + 1];
     sprintf(key, "%s%s", prefix, struct_sym);
     for (size_t i = 0; i < registry_size; i++) {
         if (strcmp(registry[i].key, key) == 0) {
@@ -407,16 +408,17 @@ CFCClass_has_attribute(CFCClass *self, const char *name) {
     return false;
 }
 
+#define MAX_FUNC_LEN 128
+
 static CFCFunction*
 S_find_func(CFCFunction **funcs, const char *sym) {
     if (!sym) {
         return NULL;
     }
 
-    const size_t MAX_LEN = 128;
-    char lcsym[MAX_LEN + 1];
+    char lcsym[MAX_FUNC_LEN + 1];
     size_t sym_len = strlen(sym);
-    if (sym_len > MAX_LEN) { CFCUtil_die("sym too long: '%s'", sym); }
+    if (sym_len > MAX_FUNC_LEN) { CFCUtil_die("sym too long: '%s'", sym); }
     for (size_t i = 0; i <= sym_len; i++) {
         lcsym[i] = tolower(sym[i]);
     }

http://git-wip-us.apache.org/repos/asf/lucy/blob/1d57b5ce/clownfish/compiler/src/CFCDumpable.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCDumpable.c 
b/clownfish/compiler/src/CFCDumpable.c
index 1853203..50d7bd4 100644
--- a/clownfish/compiler/src/CFCDumpable.c
+++ b/clownfish/compiler/src/CFCDumpable.c
@@ -153,6 +153,8 @@ S_make_method_obj(CFCClass *klass, const char *method_name) 
{
     return method;
 }
 
+#define BUF_SIZE 400
+
 static void
 S_add_dump_method(CFCClass *klass) {
     CFCMethod *method = S_make_method_obj(klass, "Dump");
@@ -162,7 +164,6 @@ S_add_dump_method(CFCClass *klass) {
     const char *full_struct   = CFCClass_full_struct_sym(klass);
     const char *vtable_var    = CFCClass_full_vtable_var(klass);
     CFCClass   *parent        = CFCClass_get_parent(klass);
-    const size_t BUF_SIZE = 400;
     char buf[BUF_SIZE];
 
     if (parent && CFCClass_has_attribute(parent, "dumpable")) {
@@ -218,7 +219,6 @@ S_add_load_method(CFCClass *klass) {
     const char *full_struct   = CFCClass_full_struct_sym(klass);
     const char *vtable_var    = CFCClass_full_vtable_var(klass);
     CFCClass   *parent        = CFCClass_get_parent(klass);
-    const size_t BUF_SIZE = 400;
     char buf[BUF_SIZE];
 
     if (parent && CFCClass_has_attribute(parent, "dumpable")) {

http://git-wip-us.apache.org/repos/asf/lucy/blob/1d57b5ce/clownfish/compiler/src/CFCType.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCType.c b/clownfish/compiler/src/CFCType.c
index 0e6e470..17f3b29 100644
--- a/clownfish/compiler/src/CFCType.c
+++ b/clownfish/compiler/src/CFCType.c
@@ -188,6 +188,8 @@ CFCType_new_float(int flags, const char *specifier) {
     return CFCType_new(flags, NULL, specifier, 0, c_string);
 }
 
+#define MAX_SPECIFIER_LEN 256
+
 CFCType*
 CFCType_new_object(int flags, CFCParcel *parcel, const char *specifier,
                    int indirection) {
@@ -214,7 +216,6 @@ CFCType_new_object(int flags, CFCParcel *parcel, const char 
*specifier,
         flags |= CFCTYPE_STRING_TYPE;
     }
 
-    const size_t MAX_SPECIFIER_LEN = 256;
     char full_specifier[MAX_SPECIFIER_LEN + 1];
     char small_specifier[MAX_SPECIFIER_LEN + 1];
     if (isupper(*specifier)) {
@@ -270,6 +271,8 @@ CFCType_new_object(int flags, CFCParcel *parcel, const char 
*specifier,
     return CFCType_new(flags, parcel, full_specifier, 1, c_string);
 }
 
+#define MAX_COMPOSITE_LEN 256
+
 CFCType*
 CFCType_new_composite(int flags, CFCType *child, int indirection,
                       const char *array) {
@@ -281,14 +284,13 @@ CFCType_new_composite(int flags, CFCType *child, int 
indirection,
 
     // Cache C representation.
     // NOTE: Array postfixes are NOT included.
-    const size_t  MAX_LEN        = 256;
     const char   *child_c_string = CFCType_to_c(child);
     size_t        child_c_len    = strlen(child_c_string);
     size_t        amount         = child_c_len + indirection;
-    if (amount > MAX_LEN) {
+    if (amount > MAX_COMPOSITE_LEN) {
         CFCUtil_die("C representation too long");
     }
-    char c_string[MAX_LEN + 1];
+    char c_string[MAX_COMPOSITE_LEN + 1];
     strcpy(c_string, child_c_string);
     for (int i = 0; i < indirection; i++) {
         strncat(c_string, "*", 1);

Reply via email to