Repository: qpid-proton
Updated Branches:
  refs/heads/go1 9e788b2d4 -> dfb5b06d5


NO-JIRAL: Remove some unnecessary global constants from the program data segment


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/37be7760
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/37be7760
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/37be7760

Branch: refs/heads/go1
Commit: 37be7760324e92045135c244d4722bb7624ecd4b
Parents: 1cfa056
Author: Andrew Stitcher <[email protected]>
Authored: Mon Nov 23 18:11:07 2015 -0500
Committer: Andrew Stitcher <[email protected]>
Committed: Tue Nov 24 10:23:58 2015 -0500

----------------------------------------------------------------------
 proton-c/include/proton/object.h |  8 +++++---
 proton-c/src/codec/codec.c       |  7 +++++--
 proton-c/src/object/map.c        | 12 +++++++-----
 proton-c/src/object/object.c     |  9 +++------
 proton-c/src/protocol.h.py       | 27 ++++++++++++++-------------
 5 files changed, 34 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/37be7760/proton-c/include/proton/object.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/object.h b/proton-c/include/proton/object.h
index 064b082..8595eae 100644
--- a/proton-c/include/proton/object.h
+++ b/proton-c/include/proton/object.h
@@ -61,9 +61,11 @@ struct pn_class_t {
   int (*inspect)(void *, pn_string_t *);
 };
 
-PN_EXTERN extern const pn_class_t * const PN_OBJECT;
-PN_EXTERN extern const pn_class_t * const PN_VOID;
-PN_EXTERN extern const pn_class_t * const PN_WEAKREF;
+// Hack alert: Declare these as arrays so we can treat the name
+// of the single object as the address
+PN_EXTERN extern const pn_class_t PN_OBJECT[];
+PN_EXTERN extern const pn_class_t PN_VOID[];
+PN_EXTERN extern const pn_class_t PN_WEAKREF[];
 
 #define PN_CLASSDEF(PREFIX)                                               \
 static void PREFIX ## _initialize_cast(void *object) {                    \

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/37be7760/proton-c/src/codec/codec.c
----------------------------------------------------------------------
diff --git a/proton-c/src/codec/codec.c b/proton-c/src/codec/codec.c
index 1e58251..45026ee 100644
--- a/proton-c/src/codec/codec.c
+++ b/proton-c/src/codec/codec.c
@@ -68,6 +68,7 @@ const char *pn_type_name(pn_type_t type)
   case PN_ARRAY: return "PN_ARRAY";
   case PN_LIST: return "PN_LIST";
   case PN_MAP: return "PN_MAP";
+  default: break;
   }
 
   return "<UNKNOWN>";
@@ -267,7 +268,7 @@ int pni_inspect_enter(void *ctx, pn_data_t *data, 
pni_node_t *node)
       return 0;
     }
     const char *name = (index < grandfields->field_count)
-        ? FIELD_STRINGPOOL+FIELD_FIELDS[grandfields->first_field_index+index]
+        ? 
FIELD_STRINGPOOL.STRING0+FIELD_FIELDS[grandfields->first_field_index+index]
         : NULL;
     if (name) {
       err = pn_string_addf(str, "%s=", name);
@@ -287,7 +288,7 @@ int pni_inspect_enter(void *ctx, pn_data_t *data, 
pni_node_t *node)
     return pn_string_addf(str, "{");
   default:
     if (fields && index == 0) {
-      err = pn_string_addf(str, "%s", 
FIELD_STRINGPOOL+FIELD_NAME[fields->name_index]);
+      err = pn_string_addf(str, "%s", 
FIELD_STRINGPOOL.STRING0+FIELD_NAME[fields->name_index]);
       if (err) return err;
       err = pn_string_addf(str, "(");
       if (err) return err;
@@ -2130,6 +2131,8 @@ int pn_data_appendn(pn_data_t *data, pn_data_t *src, int 
limit)
       pn_data_enter(src);
       level++;
       break;
+    default:
+      break;
     }
 
     if (err) { pn_data_restore(src, point); return err; }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/37be7760/proton-c/src/object/map.c
----------------------------------------------------------------------
diff --git a/proton-c/src/object/map.c b/proton-c/src/object/map.c
index d0dc714..20bb4ea 100644
--- a/proton-c/src/object/map.c
+++ b/proton-c/src/object/map.c
@@ -392,10 +392,8 @@ static bool pni_identity_equals(void *a, void *b)
   return a == b;
 }
 
-extern const pn_class_t * const PN_UINTPTR;
-
 #define CID_pni_uintptr CID_pn_void
-static const pn_class_t *pni_uintptr_reify(void *object) { return PN_UINTPTR; }
+static const pn_class_t *pni_uintptr_reify(void *object);
 #define pni_uintptr_new NULL
 #define pni_uintptr_free NULL
 #define pni_uintptr_initialize NULL
@@ -407,8 +405,12 @@ static int pni_uintptr_refcount(void *object) { return -1; 
}
 #define pni_uintptr_compare NULL
 #define pni_uintptr_inspect NULL
 
-static const pn_class_t PNI_UINTPTR = PN_METACLASS(pni_uintptr);
-const pn_class_t * const PN_UINTPTR = &PNI_UINTPTR;
+static const pn_class_t PN_UINTPTR[] = {PN_METACLASS(pni_uintptr)};
+
+static const pn_class_t *pni_uintptr_reify(void *object)
+{
+  return PN_UINTPTR;
+}
 
 pn_hash_t *pn_hash(const pn_class_t *clazz, size_t capacity, float load_factor)
 {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/37be7760/proton-c/src/object/object.c
----------------------------------------------------------------------
diff --git a/proton-c/src/object/object.c b/proton-c/src/object/object.c
index 4137f07..b0c1b33 100644
--- a/proton-c/src/object/object.c
+++ b/proton-c/src/object/object.c
@@ -29,8 +29,7 @@
 uintptr_t pn_object_hashcode(void *object) { return (uintptr_t) object; }
 intptr_t pn_object_compare(void *a, void *b) { return (intptr_t) a - 
(intptr_t) b; }
 
-static const pn_class_t PNI_OBJECT = PN_CLASS(pn_object);
-const pn_class_t * const PN_OBJECT = &PNI_OBJECT;
+const pn_class_t PN_OBJECT[] = {PN_CLASS(pn_object)};
 
 #define pn_void_initialize NULL
 static void *pn_void_new(const pn_class_t *clazz, size_t size) { return 
malloc(size); }
@@ -44,8 +43,7 @@ uintptr_t pn_void_hashcode(void *object) { return (uintptr_t) 
object; }
 intptr_t pn_void_compare(void *a, void *b) { return (intptr_t) a - (intptr_t) 
b; }
 int pn_void_inspect(void *object, pn_string_t *dst) { return 
pn_string_addf(dst, "%p", object); }
 
-static const pn_class_t PNI_VOID = PN_METACLASS(pn_void);
-const pn_class_t * const PN_VOID = &PNI_VOID;
+const pn_class_t PN_VOID[] = {PN_METACLASS(pn_void)};
 
 const char *pn_class_name(const pn_class_t *clazz)
 {
@@ -311,5 +309,4 @@ static int pn_weakref_inspect(void *object, pn_string_t 
*dst) {
   return pn_inspect(object, dst);
 }
 
-static const pn_class_t PNI_WEAKREF = PN_METACLASS(pn_weakref);
-const pn_class_t * const PN_WEAKREF = &PNI_WEAKREF;
+const pn_class_t PN_WEAKREF[] = {PN_METACLASS(pn_weakref)};

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/37be7760/proton-c/src/protocol.h.py
----------------------------------------------------------------------
diff --git a/proton-c/src/protocol.h.py b/proton-c/src/protocol.h.py
index bbc0dfe..0f58906 100644
--- a/proton-c/src/protocol.h.py
+++ b/proton-c/src/protocol.h.py
@@ -57,17 +57,12 @@ typedef struct {
 } pn_fields_t;
 
 extern const pn_fields_t FIELDS[];
-extern const char * const FIELD_STRINGPOOL;
 extern const uint16_t FIELD_NAME[];
 extern const uint16_t FIELD_FIELDS[];
-extern const unsigned char FIELD_MIN;
-extern const unsigned char FIELD_MAX;
 """)
 
-print("#ifdef DEFINE_FIELDS")
-
 print('struct FIELD_STRINGS {')
-print('  const char FIELD_STRINGS_NULL[sizeof("")];')
+print('  const char STRING0[sizeof("")];')
 strings = set()
 for name, fnames in fields.values():
     strings.add(name)
@@ -77,16 +72,20 @@ for str in strings:
     print('  const char FIELD_STRINGS_%s[sizeof("%s")];' % (istr, str))
 print("};")
 print()
-print('const struct FIELD_STRINGS FIELD_STRINGS = {')
+
+print("extern const struct FIELD_STRINGS FIELD_STRINGPOOL;")
+print("#ifdef DEFINE_FIELDS")
+print()
+
+print('const struct FIELD_STRINGS FIELD_STRINGPOOL = {')
 print('  "",')
 for str in strings:
     print('  "%s",'% str)
 print("};")
-print('const char * const FIELD_STRINGPOOL = (const char * const) 
&FIELD_STRINGS;')
 print()
 print("/* This is an array of offsets into FIELD_STRINGPOOL */")
 print("const uint16_t FIELD_NAME[] = {")
-print("  offsetof(struct FIELD_STRINGS, FIELD_STRINGS_NULL),")
+print("  offsetof(struct FIELD_STRINGS, STRING0),")
 index = 1
 for i in range(256):
   if i in fields:
@@ -98,7 +97,7 @@ print("};")
 
 print("/* This is an array of offsets into FIELD_STRINGPOOL */")
 print("const uint16_t FIELD_FIELDS[] = {")
-print("  offsetof(struct FIELD_STRINGS, FIELD_STRINGS_NULL),")
+print("  offsetof(struct FIELD_STRINGS, STRING0),")
 index = 1
 for i in range(256):
   if i in fields:
@@ -137,9 +136,11 @@ for i in range(field_min, field_max+1):
 
 print("};")
 print()
-print('const unsigned char FIELD_MIN = %d;' % field_min)
-print('const unsigned char FIELD_MAX = %d;' % field_max)
-print()
 print("#endif")
 print()
+print('enum {')
+print('  FIELD_MIN = %d,' % field_min)
+print('  FIELD_MAX = %d' % field_max)
+print('};')
+print()
 print("#endif /* protocol.h */")


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to