trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpe...@apache.org
Subject [1/5] git commit: TS-2519: make using RECP_NULL a compilation error
Date Mon, 27 Jan 2014 19:49:21 GMT
Updated Branches:
  refs/heads/master 6215bf9e9 -> 77e2776ba


TS-2519: make using RECP_NULL a compilation error

RECP_NULL can still be useful to represent the case when a record
does not have a persistence type. It might be a configuration record,
for example. However, stats records shold never be registered as
RECP_NULL, because that's ambiguous as to whether it should be
persisted This change add some template helpers to ensure that any
attempt to register a RECP_NULL stat dies in a horrible shower of
compiler errors.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/7eeb5c78
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/7eeb5c78
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/7eeb5c78

Branch: refs/heads/master
Commit: 7eeb5c782b2f49a99d5e0ec62599f8c171fa7ea1
Parents: 7352493
Author: James Peach <jpeach@apache.org>
Authored: Wed Jan 22 21:47:07 2014 -0800
Committer: James Peach <jpeach@apache.org>
Committed: Mon Jan 27 09:30:14 2014 -0800

----------------------------------------------------------------------
 lib/records/I_RecCore.h    | 14 ++++++++++----
 lib/records/I_RecDefs.h    | 25 +++++++++++++++++++++++++
 lib/records/I_RecProcess.h |  4 +++-
 lib/records/P_RecCore.cc   |  8 ++++----
 lib/records/RecProcess.cc  |  2 +-
 5 files changed, 43 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7eeb5c78/lib/records/I_RecCore.h
----------------------------------------------------------------------
diff --git a/lib/records/I_RecCore.h b/lib/records/I_RecCore.h
index 424b1c2..e9b1a4f 100644
--- a/lib/records/I_RecCore.h
+++ b/lib/records/I_RecCore.h
@@ -73,11 +73,17 @@ const char * RecConfigOverrideFromEnvironment(const char * name, const
char * va
 //-------------------------------------------------------------------------
 // Stat Registration
 //-------------------------------------------------------------------------
-int RecRegisterStatInt(RecT rec_type, const char *name, RecInt data_default, RecPersistT
persist_type);
-int RecRegisterStatFloat(RecT rec_type, const char *name, RecFloat data_default, RecPersistT
persist_type);
-int RecRegisterStatString(RecT rec_type, const char *name, RecString data_default, RecPersistT
persist_type);
-int RecRegisterStatCounter(RecT rec_type, const char *name, RecCounter data_default, RecPersistT
persist_type);
+int _RecRegisterStatInt(RecT rec_type, const char *name, RecInt data_default, RecPersistT
persist_type);
+#define RecRegisterStatInt(rec_type, name, data_default, persist_type) _RecRegisterStatInt((rec_type),
(name), (data_default), REC_PERSISTENCE_TYPE(persist_type))
 
+int _RecRegisterStatFloat(RecT rec_type, const char *name, RecFloat data_default, RecPersistT
persist_type);
+#define RecRegisterStatFloat(rec_type, name, data_default, persist_type) _RecRegisterStatFloat((rec_type),
(name), (data_default), REC_PERSISTENCE_TYPE(persist_type))
+
+int _RecRegisterStatString(RecT rec_type, const char *name, RecString data_default, RecPersistT
persist_type);
+#define RecRegisterStatString(rec_type, name, data_default, persist_type) _RecRegisterStatString((rec_type),
(name), (data_default), REC_PERSISTENCE_TYPE(persist_type))
+
+int _RecRegisterStatCounter(RecT rec_type, const char *name, RecCounter data_default, RecPersistT
persist_type);
+#define RecRegisterStatCounter(rec_type, name, data_default, persist_type) _RecRegisterStatCounter((rec_type),
(name), (data_default), REC_PERSISTENCE_TYPE(persist_type))
 
 //-------------------------------------------------------------------------
 // Config Registration

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7eeb5c78/lib/records/I_RecDefs.h
----------------------------------------------------------------------
diff --git a/lib/records/I_RecDefs.h b/lib/records/I_RecDefs.h
index 5a9c121..ec3afbc 100644
--- a/lib/records/I_RecDefs.h
+++ b/lib/records/I_RecDefs.h
@@ -88,6 +88,31 @@ enum RecPersistT
   RECP_NON_PERSISTENT
 };
 
+// RECP_NULL should never be used by callers of RecRegisterStat*(). You have to decide
+// whether to persist stats or not. The template goop below make sure that passing RECP_NULL
+// is a very ugle compile-time error.
+
+namespace rec {
+namespace detail {
+template <RecPersistT>
+struct is_valid_persistence;
+
+template<>
+struct is_valid_persistence<RECP_PERSISTENT>
+{
+  static const RecPersistT value = RECP_PERSISTENT;
+};
+
+template<>
+struct is_valid_persistence<RECP_NON_PERSISTENT>
+{
+  static const RecPersistT value = RECP_NON_PERSISTENT;
+};
+
+}}
+
+#define REC_PERSISTENCE_TYPE(P) rec::detail::is_valid_persistence<P>::value
+
 enum RecUpdateT
 {
   RECU_NULL,                    // default: don't know the behavior

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7eeb5c78/lib/records/I_RecProcess.h
----------------------------------------------------------------------
diff --git a/lib/records/I_RecProcess.h b/lib/records/I_RecProcess.h
index 8faffe7..123041e 100644
--- a/lib/records/I_RecProcess.h
+++ b/lib/records/I_RecProcess.h
@@ -46,8 +46,10 @@ void RecProcess_set_remote_sync_interval_ms(int ms);
 // RawStat Registration
 //-------------------------------------------------------------------------
 RecRawStatBlock *RecAllocateRawStatBlock(int num_stats);
-int RecRegisterRawStat(RecRawStatBlock * rsb, RecT rec_type, const char *name, RecDataT data_type,
RecPersistT persist_type, int id, RecRawStatSyncCb sync_cb);
 
+int _RecRegisterRawStat(RecRawStatBlock * rsb, RecT rec_type, const char *name, RecDataT
data_type, RecPersistT persist_type, int id, RecRawStatSyncCb sync_cb);
+#define RecRegisterRawStat(rsb, rec_type, name, data_type, persist_type, id, sync_cb) \
+  _RecRegisterRawStat((rsb), (rec_type), (name), (data_type), REC_PERSISTENCE_TYPE(persist_type),
(id), (sync_cb))
 
 // RecRawStatRange* RecAllocateRawStatRange (int num_buckets);
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7eeb5c78/lib/records/P_RecCore.cc
----------------------------------------------------------------------
diff --git a/lib/records/P_RecCore.cc b/lib/records/P_RecCore.cc
index 2be8116..152bf05 100644
--- a/lib/records/P_RecCore.cc
+++ b/lib/records/P_RecCore.cc
@@ -291,25 +291,25 @@ recv_message_cb(RecMessage * msg, RecMessageT msg_type, void */* cookie
*/)
   }
 
 int
-RecRegisterStatInt(RecT rec_type, const char *name, RecInt data_default, RecPersistT persist_type)
+_RecRegisterStatInt(RecT rec_type, const char *name, RecInt data_default, RecPersistT persist_type)
 {
   REC_REGISTER_STAT_XXX(rec_int, RECD_INT);
 }
 
 int
-RecRegisterStatFloat(RecT rec_type, const char *name, RecFloat data_default, RecPersistT
persist_type)
+_RecRegisterStatFloat(RecT rec_type, const char *name, RecFloat data_default, RecPersistT
persist_type)
 {
   REC_REGISTER_STAT_XXX(rec_float, RECD_FLOAT);
 }
 
 int
-RecRegisterStatString(RecT rec_type, const char *name, RecString data_default, RecPersistT
persist_type)
+_RecRegisterStatString(RecT rec_type, const char *name, RecString data_default, RecPersistT
persist_type)
 {
   REC_REGISTER_STAT_XXX(rec_string, RECD_STRING);
 }
 
 int
-RecRegisterStatCounter(RecT rec_type, const char *name, RecCounter data_default, RecPersistT
persist_type)
+_RecRegisterStatCounter(RecT rec_type, const char *name, RecCounter data_default, RecPersistT
persist_type)
 {
   REC_REGISTER_STAT_XXX(rec_counter, RECD_COUNTER);
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7eeb5c78/lib/records/RecProcess.cc
----------------------------------------------------------------------
diff --git a/lib/records/RecProcess.cc b/lib/records/RecProcess.cc
index 5dc7392..8cab1de 100644
--- a/lib/records/RecProcess.cc
+++ b/lib/records/RecProcess.cc
@@ -532,7 +532,7 @@ RecAllocateRawStatBlock(int num_stats)
 // RecRegisterRawStat
 //-------------------------------------------------------------------------
 int
-RecRegisterRawStat(RecRawStatBlock *rsb, RecT rec_type, const char *name, RecDataT data_type,
RecPersistT persist_type, int id,
+_RecRegisterRawStat(RecRawStatBlock *rsb, RecT rec_type, const char *name, RecDataT data_type,
RecPersistT persist_type, int id,
                    RecRawStatSyncCb sync_cb)
 {
   Debug("stats", "RecRawStatSyncCb(%s): rsb pointer:%p id:%d\n", name, rsb, id);


Mime
View raw message