[gjs: 3/15] mem: Split memory counters into private header



commit 8febd510e986021023e68ed9578045e69cfbf024
Author: Philip Chimento <philip chimento gmail com>
Date:   Wed Dec 5 22:57:09 2018 -0800

    mem: Split memory counters into private header
    
    Earlier in this cycle, we made gjs_memory_report() into public API, but
    the memory counters themselves should not be public. They are moved into
    a private header file.

 gi/boxed.cpp       |  2 +-
 gi/closure.cpp     |  2 +-
 gi/function.cpp    | 22 +++++++++---------
 gi/fundamental.cpp |  2 +-
 gi/gerror.cpp      |  2 +-
 gi/interface.cpp   | 12 +++++-----
 gi/ns.cpp          |  8 +++----
 gi/object.cpp      |  2 +-
 gi/param.cpp       | 14 ++++++------
 gi/repo.cpp        | 28 +++++++++++------------
 gi/union.cpp       |  2 +-
 gjs-srcs.mk        |  1 +
 gjs/importer.cpp   |  2 +-
 gjs/mem-private.h  | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gjs/mem.cpp        |  5 +++--
 gjs/mem.h          | 39 --------------------------------
 16 files changed, 119 insertions(+), 90 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index 425dedee..50c51008 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -33,7 +33,7 @@
 #include "function.h"
 #include "gi/gerror.h"
 #include "gjs/jsapi-class.h"
-#include "gjs/mem.h"
+#include "gjs/mem-private.h"
 #include "gtype.h"
 #include "object.h"
 #include "proxyutils.h"
diff --git a/gi/closure.cpp b/gi/closure.cpp
index afc3d3e3..4a6645c3 100644
--- a/gi/closure.cpp
+++ b/gi/closure.cpp
@@ -30,7 +30,7 @@
 #include "closure.h"
 #include "gjs/jsapi-util-root.h"
 #include "gjs/jsapi-wrapper.h"
-#include "gjs/mem.h"
+#include "gjs/mem-private.h"
 
 struct Closure {
     JSContext *context;
diff --git a/gi/function.cpp b/gi/function.cpp
index 4491aa4b..220aa198 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -23,20 +23,20 @@
 
 #include <config.h>
 
-#include "function.h"
-#include "arg.h"
-#include "object.h"
-#include "fundamental.h"
-#include "boxed.h"
-#include "union.h"
-#include "gerror.h"
-#include "closure.h"
-#include "gtype.h"
-#include "param.h"
+#include "gi/arg.h"
+#include "gi/boxed.h"
+#include "gi/closure.h"
+#include "gi/function.h"
+#include "gi/fundamental.h"
+#include "gi/gerror.h"
+#include "gi/gtype.h"
+#include "gi/object.h"
+#include "gi/param.h"
+#include "gi/union.h"
 #include "gjs/context-private.h"
 #include "gjs/jsapi-class.h"
 #include "gjs/jsapi-wrapper.h"
-#include "gjs/mem.h"
+#include "gjs/mem-private.h"
 
 #include <util/log.h>
 
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index 661ff545..cf1071fa 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -35,7 +35,7 @@
 #include "repo.h"
 #include "gjs/jsapi-class.h"
 #include "gjs/jsapi-wrapper.h"
-#include "gjs/mem.h"
+#include "gjs/mem-private.h"
 
 #include <gjs/context.h>
 #include <util/log.h>
diff --git a/gi/gerror.cpp b/gi/gerror.cpp
index 7cee0ec8..485af08e 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -31,7 +31,7 @@
 #include "gjs/context-private.h"
 #include "gjs/jsapi-class.h"
 #include "gjs/jsapi-wrapper.h"
-#include "gjs/mem.h"
+#include "gjs/mem-private.h"
 #include "repo.h"
 #include "util/error.h"
 
diff --git a/gi/interface.cpp b/gi/interface.cpp
index 5378a439..a53d11d3 100644
--- a/gi/interface.cpp
+++ b/gi/interface.cpp
@@ -24,14 +24,14 @@
 
 #include <config.h>
 
-#include "function.h"
-#include "gtype.h"
-#include "interface.h"
-#include "object.h"
-#include "repo.h"
+#include "gi/function.h"
+#include "gi/gtype.h"
+#include "gi/interface.h"
+#include "gi/object.h"
+#include "gi/repo.h"
 #include "gjs/jsapi-class.h"
 #include "gjs/jsapi-wrapper.h"
-#include "gjs/mem.h"
+#include "gjs/mem-private.h"
 
 #include <util/log.h>
 
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 5fc0012d..cc1fceb9 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -23,12 +23,12 @@
 
 #include <config.h>
 
-#include "ns.h"
-#include "repo.h"
-#include "param.h"
+#include "gi/ns.h"
+#include "gi/param.h"
+#include "gi/repo.h"
 #include "gjs/jsapi-class.h"
 #include "gjs/jsapi-wrapper.h"
-#include "gjs/mem.h"
+#include "gjs/mem-private.h"
 
 #include <util/log.h>
 #include <girepository.h>
diff --git a/gi/object.cpp b/gi/object.cpp
index 94ee8c07..a8e3af21 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -47,7 +47,7 @@
 #include "gjs/jsapi-util-root.h"
 #include "gjs/jsapi-wrapper.h"
 #include "gjs/context-private.h"
-#include "gjs/mem.h"
+#include "gjs/mem-private.h"
 
 #include <util/log.h>
 #include <girepository.h>
diff --git a/gi/param.cpp b/gi/param.cpp
index 0d5c3277..e4268774 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -25,15 +25,15 @@
 
 #include <string.h>
 
-#include "param.h"
-#include "arg.h"
-#include "object.h"
-#include "repo.h"
-#include "gtype.h"
-#include "function.h"
+#include "gi/arg.h"
+#include "gi/function.h"
+#include "gi/gtype.h"
+#include "gi/object.h"
+#include "gi/param.h"
+#include "gi/repo.h"
 #include "gjs/jsapi-class.h"
 #include "gjs/jsapi-wrapper.h"
-#include "gjs/mem.h"
+#include "gjs/mem-private.h"
 
 #include <util/log.h>
 
diff --git a/gi/repo.cpp b/gi/repo.cpp
index e4e0ca3f..40a45c87 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -23,22 +23,22 @@
 
 #include <config.h>
 
-#include "repo.h"
-#include "ns.h"
-#include "function.h"
-#include "object.h"
-#include "param.h"
-#include "boxed.h"
-#include "union.h"
-#include "enumeration.h"
-#include "arg.h"
-#include "foreign.h"
-#include "fundamental.h"
-#include "interface.h"
-#include "gerror.h"
+#include "gi/arg.h"
+#include "gi/boxed.h"
+#include "gi/enumeration.h"
+#include "gi/foreign.h"
+#include "gi/function.h"
+#include "gi/fundamental.h"
+#include "gi/gerror.h"
+#include "gi/interface.h"
+#include "gi/ns.h"
+#include "gi/object.h"
+#include "gi/param.h"
+#include "gi/repo.h"
+#include "gi/union.h"
 #include "gjs/jsapi-class.h"
 #include "gjs/jsapi-wrapper.h"
-#include "gjs/mem.h"
+#include "gjs/mem-private.h"
 
 #include <util/misc.h>
 
diff --git a/gi/union.cpp b/gi/union.cpp
index 89c35a02..52256418 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -33,7 +33,7 @@
 #include "object.h"
 #include "gjs/jsapi-class.h"
 #include "gjs/jsapi-wrapper.h"
-#include "gjs/mem.h"
+#include "gjs/mem-private.h"
 #include "repo.h"
 #include "proxyutils.h"
 #include "function.h"
diff --git a/gjs-srcs.mk b/gjs-srcs.mk
index 47fdf949..4a285590 100644
--- a/gjs-srcs.mk
+++ b/gjs-srcs.mk
@@ -80,6 +80,7 @@ gjs_srcs =                            \
        gjs/jsapi-util-string.cpp       \
        gjs/jsapi-wrapper.h             \
        gjs/mem.cpp                     \
+       gjs/mem-private.h               \
        gjs/module.h                    \
        gjs/module.cpp                  \
        gjs/native.cpp                  \
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 7a9a60e9..b43b8cf8 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -28,10 +28,10 @@
 #include <vector>
 
 #include "gjs/context-private.h"
+#include "gjs/mem-private.h"
 #include "importer.h"
 #include "jsapi-class.h"
 #include "jsapi-wrapper.h"
-#include "mem.h"
 #include "module.h"
 #include "native.h"
 #include "util/glib.h"
diff --git a/gjs/mem-private.h b/gjs/mem-private.h
new file mode 100644
index 00000000..df223af0
--- /dev/null
+++ b/gjs/mem-private.h
@@ -0,0 +1,66 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (c) 2008  litl, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef GJS_MEM_PRIVATE_H_
+#define GJS_MEM_PRIVATE_H_
+
+#include <glib.h>
+
+typedef struct {
+    volatile int value;
+    const char* name;
+} GjsMemCounter;
+
+#define GJS_DECLARE_COUNTER(name) extern GjsMemCounter gjs_counter_##name;
+
+GJS_DECLARE_COUNTER(everything)
+
+GJS_DECLARE_COUNTER(boxed)
+GJS_DECLARE_COUNTER(closure)
+GJS_DECLARE_COUNTER(function)
+GJS_DECLARE_COUNTER(fundamental)
+GJS_DECLARE_COUNTER(gerror)
+GJS_DECLARE_COUNTER(importer)
+GJS_DECLARE_COUNTER(interface)
+GJS_DECLARE_COUNTER(ns)
+GJS_DECLARE_COUNTER(object_instance)
+GJS_DECLARE_COUNTER(object_prototype)
+GJS_DECLARE_COUNTER(param)
+GJS_DECLARE_COUNTER(repo)
+GJS_DECLARE_COUNTER(union)
+
+#define GJS_INC_COUNTER(name)                               \
+    do {                                                    \
+        g_atomic_int_add(&gjs_counter_everything.value, 1); \
+        g_atomic_int_add(&gjs_counter_##name.value, 1);     \
+    } while (0)
+
+#define GJS_DEC_COUNTER(name)                                \
+    do {                                                     \
+        g_atomic_int_add(&gjs_counter_everything.value, -1); \
+        g_atomic_int_add(&gjs_counter_##name.value, -1);     \
+    } while (0)
+
+#define GJS_GET_COUNTER(name) g_atomic_int_get(&gjs_counter_##name.value)
+
+#endif  // GJS_MEM_PRIVATE_H_
diff --git a/gjs/mem.cpp b/gjs/mem.cpp
index 1dc07a5b..4539a3db 100644
--- a/gjs/mem.cpp
+++ b/gjs/mem.cpp
@@ -23,8 +23,9 @@
 
 #include <config.h>
 
-#include "mem.h"
-#include <util/log.h>
+#include "gjs/mem-private.h"
+#include "gjs/mem.h"
+#include "util/log.h"
 
 #define GJS_DEFINE_COUNTER(name)             \
     GjsMemCounter gjs_counter_ ## name = { \
diff --git a/gjs/mem.h b/gjs/mem.h
index 0bbd9ba3..769d1caf 100644
--- a/gjs/mem.h
+++ b/gjs/mem.h
@@ -31,45 +31,6 @@
 
 G_BEGIN_DECLS
 
-typedef struct {
-    volatile int value;
-    const char *name;
-} GjsMemCounter;
-
-#define GJS_DECLARE_COUNTER(name) \
-    extern GjsMemCounter gjs_counter_ ## name ;
-
-GJS_DECLARE_COUNTER(everything)
-
-GJS_DECLARE_COUNTER(boxed)
-GJS_DECLARE_COUNTER(closure)
-GJS_DECLARE_COUNTER(function)
-GJS_DECLARE_COUNTER(fundamental)
-GJS_DECLARE_COUNTER(gerror)
-GJS_DECLARE_COUNTER(importer)
-GJS_DECLARE_COUNTER(interface)
-GJS_DECLARE_COUNTER(ns)
-GJS_DECLARE_COUNTER(object_instance)
-GJS_DECLARE_COUNTER(object_prototype)
-GJS_DECLARE_COUNTER(param)
-GJS_DECLARE_COUNTER(repo)
-GJS_DECLARE_COUNTER(union)
-
-#define GJS_INC_COUNTER(name)                \
-    do {                                        \
-        g_atomic_int_add(&gjs_counter_everything.value, 1); \
-        g_atomic_int_add(&gjs_counter_ ## name .value, 1); \
-    } while (0)
-
-#define GJS_DEC_COUNTER(name)                \
-    do {                                        \
-        g_atomic_int_add(&gjs_counter_everything.value, -1); \
-        g_atomic_int_add(&gjs_counter_ ## name .value, -1); \
-    } while (0)
-
-#define GJS_GET_COUNTER(name) \
-    g_atomic_int_get(&gjs_counter_ ## name .value)
-
 GJS_EXPORT
 void gjs_memory_report(const char *where,
                        bool        die_if_leaks);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]