[gjs: 8/21] maint: Remove GLib custom types from some files



commit 39786302d2503ae2acbb6007c86d3c1b8e854450
Author: Philip Chimento <philip chimento gmail com>
Date:   Fri May 31 22:34:03 2019 -0700

    maint: Remove GLib custom types from some files
    
    In files where the IWYU tool would recommend including <glib.h> only for
    the custom types such as gint or gconstpointer, we instead remove usage
    of those types in favour of the plain old C types.

 gi/arg.cpp             | 51 +++++++++++++++++---------------------------------
 gi/arg.h               | 23 ++++++++---------------
 gi/function.h          |  2 +-
 gjs/profiler-private.h |  4 +++-
 test/gjs-test-utils.h  |  6 ++----
 5 files changed, 31 insertions(+), 55 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index db5c0350..5c5c2001 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -41,11 +41,7 @@
 #include "gjs/jsapi-wrapper.h"
 #include <util/log.h>
 
-bool
-_gjs_flags_value_is_valid(JSContext   *context,
-                          GType        gtype,
-                          gint64       value)
-{
+bool _gjs_flags_value_is_valid(JSContext* context, GType gtype, int64_t value) {
     GFlagsValue *v;
     guint32 tmpval;
 
@@ -80,11 +76,8 @@ _gjs_flags_value_is_valid(JSContext   *context,
 }
 
 GJS_JSAPI_RETURN_CONVENTION
-static bool
-_gjs_enum_value_is_valid(JSContext  *context,
-                         GIEnumInfo *enum_info,
-                         gint64      value)
-{
+static bool _gjs_enum_value_is_valid(JSContext* context, GIEnumInfo* enum_info,
+                                     int64_t value) {
     bool found;
     int n_values;
     int i;
@@ -94,10 +87,9 @@ _gjs_enum_value_is_valid(JSContext  *context,
 
     for (i = 0; i < n_values; ++i) {
         GIValueInfo *value_info;
-        gint64 enum_value;
 
         value_info = g_enum_info_get_value(enum_info, i);
-        enum_value = g_value_info_get_value(value_info);
+        int64_t enum_value = g_value_info_get_value(value_info);
         g_base_info_unref((GIBaseInfo *)value_info);
 
         if (enum_value == value) {
@@ -134,14 +126,11 @@ _gjs_enum_uses_signed_type (GIEnumInfo *enum_info)
  */
 
 GJS_USE
-gint64
-_gjs_enum_from_int (GIEnumInfo *enum_info,
-                    int         int_value)
-{
+int64_t _gjs_enum_from_int(GIEnumInfo* enum_info, int int_value) {
     if (_gjs_enum_uses_signed_type (enum_info))
-        return (gint64)int_value;
+        return int64_t(int_value);
     else
-        return (gint64)(guint32)int_value;
+        return int64_t(uint32_t(int_value));
 }
 
 /* Here for symmetry, but result is the same for the two cases */
@@ -2790,7 +2779,8 @@ gjs_value_from_g_argument (JSContext             *context,
 
             /* Enum/Flags are aren't pointer types, unlike the other interface subtypes */
             if (interface_type == GI_INFO_TYPE_ENUM) {
-                gint64 value_int64 = _gjs_enum_from_int ((GIEnumInfo *)interface_info, arg->v_int);
+                int64_t value_int64 =
+                    _gjs_enum_from_int(interface_info, arg->v_int);
 
                 if (_gjs_enum_value_is_valid(context, (GIEnumInfo *)interface_info, value_int64)) {
                     value = JS::NumberValue(value_int64);
@@ -2798,7 +2788,8 @@ gjs_value_from_g_argument (JSContext             *context,
 
                 goto out;
             } else if (interface_type == GI_INFO_TYPE_FLAGS) {
-                gint64 value_int64 = _gjs_enum_from_int ((GIEnumInfo *)interface_info, arg->v_int);
+                int64_t value_int64 =
+                    _gjs_enum_from_int(interface_info, arg->v_int);
 
                 gtype = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*)interface_info);
                 if (_gjs_flags_value_is_valid(context, gtype, value_int64)) {
@@ -3590,13 +3581,9 @@ gjs_g_argument_release_in_arg(JSContext  *context,
     return true;
 }
 
-bool
-gjs_g_argument_release_in_array (JSContext  *context,
-                                 GITransfer  transfer,
-                                 GITypeInfo *type_info,
-                                 guint       length,
-                                 GArgument  *arg)
-{
+bool gjs_g_argument_release_in_array(JSContext* context, GITransfer transfer,
+                                     GITypeInfo* type_info, unsigned length,
+                                     GIArgument* arg) {
     GITypeInfo *param_type;
     gpointer *array;
     GArgument elem;
@@ -3639,13 +3626,9 @@ gjs_g_argument_release_in_array (JSContext  *context,
     return ret;
 }
 
-bool
-gjs_g_argument_release_out_array (JSContext  *context,
-                                  GITransfer  transfer,
-                                  GITypeInfo *type_info,
-                                  guint       length,
-                                  GArgument  *arg)
-{
+bool gjs_g_argument_release_out_array(JSContext* context, GITransfer transfer,
+                                      GITypeInfo* type_info, unsigned length,
+                                      GIArgument* arg) {
     GITypeInfo *param_type;
     gpointer *array;
     GArgument elem;
diff --git a/gi/arg.h b/gi/arg.h
index 8cbdae2f..751a2330 100644
--- a/gi/arg.h
+++ b/gi/arg.h
@@ -93,17 +93,13 @@ bool gjs_g_argument_release    (JSContext  *context,
                                 GITypeInfo *type_info,
                                 GArgument  *arg);
 GJS_JSAPI_RETURN_CONVENTION
-bool gjs_g_argument_release_out_array (JSContext  *context,
-                                       GITransfer  transfer,
-                                       GITypeInfo *type_info,
-                                       guint       length,
-                                       GArgument  *arg);
+bool gjs_g_argument_release_out_array(JSContext* cx, GITransfer transfer,
+                                      GITypeInfo* type_info, unsigned length,
+                                      GIArgument* arg);
 GJS_JSAPI_RETURN_CONVENTION
-bool gjs_g_argument_release_in_array (JSContext  *context,
-                                      GITransfer  transfer,
-                                      GITypeInfo *type_info,
-                                      guint       length,
-                                      GArgument  *arg);
+bool gjs_g_argument_release_in_array(JSContext* cx, GITransfer transfer,
+                                     GITypeInfo* type_info, unsigned length,
+                                     GIArgument* arg);
 GJS_JSAPI_RETURN_CONVENTION
 bool gjs_g_argument_release_in_arg (JSContext  *context,
                                     GITransfer  transfer,
@@ -111,13 +107,10 @@ bool gjs_g_argument_release_in_arg (JSContext  *context,
                                     GArgument  *arg);
 
 GJS_JSAPI_RETURN_CONVENTION
-bool _gjs_flags_value_is_valid (JSContext   *context,
-                                GType        gtype,
-                                gint64       value);
+bool _gjs_flags_value_is_valid(JSContext* cx, GType gtype, int64_t value);
 
 GJS_USE
-gint64 _gjs_enum_from_int (GIEnumInfo *enum_info,
-                           int         int_value);
+int64_t _gjs_enum_from_int(GIEnumInfo* enum_info, int int_value);
 
 GJS_JSAPI_RETURN_CONVENTION
 bool gjs_array_from_strv(JSContext             *context,
diff --git a/gi/function.h b/gi/function.h
index 93cd7379..16e0fa29 100644
--- a/gi/function.h
+++ b/gi/function.h
@@ -44,7 +44,7 @@ typedef enum {
 } GjsParamType;
 
 struct GjsCallbackTrampoline {
-    gint ref_count;
+    int ref_count;
     GICallableInfo *info;
 
     GClosure *js_function;
diff --git a/gjs/profiler-private.h b/gjs/profiler-private.h
index 0697be25..42af367e 100644
--- a/gjs/profiler-private.h
+++ b/gjs/profiler-private.h
@@ -24,6 +24,8 @@
 #ifndef GJS_PROFILER_PRIVATE_H
 #define GJS_PROFILER_PRIVATE_H
 
+#include <stdint.h>
+
 #include "context.h"
 #include "gjs/macros.h"
 #include "profiler.h"
@@ -33,7 +35,7 @@ G_BEGIN_DECLS
 GjsProfiler *_gjs_profiler_new(GjsContext *context);
 void _gjs_profiler_free(GjsProfiler *self);
 
-void _gjs_profiler_add_mark(GjsProfiler* self, gint64 time, gint64 duration,
+void _gjs_profiler_add_mark(GjsProfiler* self, int64_t time, int64_t duration,
                             const char* group, const char* name,
                             const char* message);
 
diff --git a/test/gjs-test-utils.h b/test/gjs-test-utils.h
index 977f4276..669bcd8a 100644
--- a/test/gjs-test-utils.h
+++ b/test/gjs-test-utils.h
@@ -36,13 +36,11 @@ struct _GjsUnitTestFixture {
     JSCompartment *compartment;
 };
 
-void gjs_unit_test_fixture_setup(GjsUnitTestFixture *fx,
-                                 gconstpointer       unused);
+void gjs_unit_test_fixture_setup(GjsUnitTestFixture* fx, const void* unused);
 
 void gjs_unit_test_destroy_context(GjsUnitTestFixture *fx);
 
-void gjs_unit_test_fixture_teardown(GjsUnitTestFixture *fx,
-                                    gconstpointer      unused);
+void gjs_unit_test_fixture_teardown(GjsUnitTestFixture* fx, const void* unused);
 
 void gjs_test_add_tests_for_coverage ();
 


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