You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/10/16 02:16:54 UTC
[lucy-commits] svn commit: r1183772 -
/incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCType.c
Author: marvin
Date: Sun Oct 16 00:16:54 2011
New Revision: 1183772
URL: http://svn.apache.org/viewvc?rev=1183772&view=rev
Log:
Add checks for invalid flags to CFCType constructors.
Modified:
incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCType.c
Modified: incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCType.c
URL: http://svn.apache.org/viewvc/incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCType.c?rev=1183772&r1=1183771&r2=1183772&view=diff
==============================================================================
--- incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCType.c (original)
+++ incubator/lucy/branches/clownfish_lemon/clownfish/src/CFCType.c Sun Oct 16 00:16:54 2011
@@ -55,6 +55,30 @@ CFCType_new(int flags, struct CFCParcel
c_string);
}
+static void
+S_check_flags(int supplied, int acceptable, const char *type_name) {
+ int bad = (supplied & ~acceptable);
+ if (bad) {
+ char bad_flag[20];
+ if ((bad & CFCTYPE_CONST)) { strcpy(bad_flag, "CONST"); }
+ else if ((bad & CFCTYPE_NULLABLE)) { strcpy(bad_flag, "NULLABLE"); }
+ else if ((bad & CFCTYPE_INCREMENTED)) { strcpy(bad_flag, "INCREMENTED"); }
+ else if ((bad & CFCTYPE_DECREMENTED)) { strcpy(bad_flag, "DECREMENTED"); }
+ else if ((bad & CFCTYPE_OBJECT)) { strcpy(bad_flag, "OBJECT"); }
+ else if ((bad & CFCTYPE_PRIMITIVE)) { strcpy(bad_flag, "PRIMITIVE"); }
+ else if ((bad & CFCTYPE_INTEGER)) { strcpy(bad_flag, "INTEGER"); }
+ else if ((bad & CFCTYPE_FLOATING)) { strcpy(bad_flag, "FLOATING"); }
+ else if ((bad & CFCTYPE_STRING_TYPE)) { strcpy(bad_flag, "STRING_TYPE"); }
+ else if ((bad & CFCTYPE_VA_LIST)) { strcpy(bad_flag, "VA_LIST"); }
+ else if ((bad & CFCTYPE_ARBITRARY)) { strcpy(bad_flag, "ARBITRARY"); }
+ else if ((bad & CFCTYPE_COMPOSITE)) { strcpy(bad_flag, "COMPOSITE"); }
+ else {
+ CFCUtil_die("Unknown flags: %d", bad);
+ }
+ CFCUtil_die("Bad flag for type %s: %s", type_name, bad_flag);
+ }
+}
+
CFCType*
CFCType_init(CFCType *self, int flags, struct CFCParcel *parcel,
const char *specifier, int indirection, const char *c_string) {
@@ -129,6 +153,8 @@ CFCType_new_integer(int flags, const cha
// Add flags.
flags |= CFCTYPE_PRIMITIVE;
flags |= CFCTYPE_INTEGER;
+ S_check_flags(flags, CFCTYPE_CONST | CFCTYPE_PRIMITIVE | CFCTYPE_INTEGER,
+ "Integer");
CFCType *self = CFCType_new(flags, NULL, full_specifier, 0, c_string);
self->width = width;
@@ -165,6 +191,8 @@ CFCType_new_float(int flags, const char
flags |= CFCTYPE_PRIMITIVE;
flags |= CFCTYPE_FLOATING;
+ S_check_flags(flags, CFCTYPE_CONST | CFCTYPE_PRIMITIVE | CFCTYPE_FLOATING,
+ "Floating");
return CFCType_new(flags, NULL, specifier, 0, c_string);
}
@@ -223,6 +251,14 @@ CFCType_new_object(int flags, CFCParcel
sprintf(c_string, "%s*", full_specifier);
}
+ int acceptable_flags = CFCTYPE_OBJECT
+ | CFCTYPE_STRING_TYPE
+ | CFCTYPE_CONST
+ | CFCTYPE_NULLABLE
+ | CFCTYPE_INCREMENTED
+ | CFCTYPE_DECREMENTED;
+ S_check_flags(flags, acceptable_flags, "Object");
+
return CFCType_new(flags, parcel, full_specifier, 1, c_string);
}
@@ -233,6 +269,7 @@ CFCType_new_composite(int flags, CFCType
croak("Missing required param 'child'");
}
flags |= CFCTYPE_COMPOSITE;
+ S_check_flags(flags, CFCTYPE_COMPOSITE | CFCTYPE_NULLABLE, "Composite");
// Cache C representation.
// NOTE: Array postfixes are NOT included.