[gedit] Fix 668924 Make gedit_debug_message() introspectable
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Fix 668924 Make gedit_debug_message() introspectable
- Date: Thu, 9 Feb 2012 20:12:17 +0000 (UTC)
commit c3b38c92009e5148b5cb297c8f2252b83136570e
Author: Daniel Trebbien <dtrebbien gmail com>
Date: Thu Feb 9 10:19:03 2012 -0500
Fix 668924 Make gedit_debug_message() introspectable
Adds a new function to the gedit-debug public API:
gedit_debug_plugin_message(). gedit_debug_plugin_message() is intended to
be a non-variable argument (hence introspectable) version of
gedit_debug_message() that can be called by plugins.
An override of gedit_debug_plugin_message() is added for the PyGObject
Python language binding. The override makes it more convenient to use by
Python plugin writers.
https://bugzilla.gnome.org/show_bug.cgi?id=668924
docs/reference/gedit-sections.txt | 2 +-
gedit/Gedit.py | 35 ++++++++++++++++++++++++
gedit/gedit-debug.c | 53 ++++++++++++++++++++++++++++++++++---
gedit/gedit-debug.h | 6 +++-
4 files changed, 89 insertions(+), 7 deletions(-)
---
diff --git a/docs/reference/gedit-sections.txt b/docs/reference/gedit-sections.txt
index 1381194..72046ba 100644
--- a/docs/reference/gedit-sections.txt
+++ b/docs/reference/gedit-sections.txt
@@ -466,6 +466,7 @@ DEBUG_DBUS
gedit_debug_init
gedit_debug
gedit_debug_message
+gedit_debug_plugin_message
</SECTION>
<SECTION>
@@ -549,4 +550,3 @@ gedit_tab_state_get_type
GEDIT_TYPE_WINDOW_STATE
gedit_window_state_get_type
</SECTION>
-
diff --git a/gedit/Gedit.py b/gedit/Gedit.py
index db95657..4bf9e06 100644
--- a/gedit/Gedit.py
+++ b/gedit/Gedit.py
@@ -1,4 +1,6 @@
from gi.repository import GObject
+import inspect
+
from ..overrides import override
from ..importer import modules
@@ -42,4 +44,37 @@ class Message(Gedit.Message):
Message = override(Message)
__all__.append('Message')
+
+def get_trace_info(num_back_frames=0):
+ frame = inspect.currentframe().f_back
+ try:
+ for i in range(num_back_frames):
+ frame = frame.f_back
+
+ filename = frame.f_code.co_filename
+
+ # http://code.activestate.com/recipes/145297-grabbing-the-current-line-number-easily/
+ lineno = frame.f_lineno
+
+ func_name = frame.f_code.co_name
+ try:
+ # http://stackoverflow.com/questions/2203424/python-how-to-retrieve-class-information-from-a-frame-object
+ cls_name = frame.f_locals["self"].__class__.__name__
+ except:
+ pass
+ else:
+ func_name = "%s.%s" % (cls_name, func_name)
+
+ return (filename, lineno, func_name)
+ finally:
+ frame = None
+
+orig_debug_plugin_message_func = Gedit.debug_plugin_message
+
+ override(Gedit.debug_plugin_message)
+def debug_plugin_message(format, *format_args):
+ filename, lineno, func_name = get_trace_info(2)
+ orig_debug_plugin_message_func(filename, lineno, func_name, format % format_args)
+__all__.append(debug_plugin_message)
+
# vi:ex:ts=4:et
diff --git a/gedit/gedit-debug.c b/gedit/gedit-debug.c
index a6affeb..c6e1ca6 100644
--- a/gedit/gedit-debug.c
+++ b/gedit/gedit-debug.c
@@ -46,6 +46,8 @@ static gdouble last = 0.0;
static GeditDebugSection debug = GEDIT_NO_DEBUG;
+#define DEBUG_IS_ENABLED(section_rval) (debug & (section_rval))
+
/**
* gedit_debug_init:
*
@@ -130,7 +132,7 @@ void gedit_debug (GeditDebugSection section,
gint line,
const gchar *function)
{
- if (G_UNLIKELY (debug & section))
+ if (G_UNLIKELY (DEBUG_IS_ENABLED (section)))
{
#ifdef ENABLE_PROFILING
gdouble seconds;
@@ -144,6 +146,7 @@ void gedit_debug (GeditDebugSection section,
#else
g_print ("%s:%d (%s)\n", file, line, function);
#endif
+
fflush (stdout);
}
}
@@ -168,7 +171,7 @@ gedit_debug_message (GeditDebugSection section,
const gchar *function,
const gchar *format, ...)
{
- if (G_UNLIKELY (debug & section))
+ if (G_UNLIKELY (DEBUG_IS_ENABLED (section)))
{
va_list args;
gchar *msg;
@@ -177,6 +180,8 @@ gedit_debug_message (GeditDebugSection section,
gdouble seconds;
g_return_if_fail (timer != NULL);
+
+ seconds = g_timer_elapsed (timer, NULL);
#endif
g_return_if_fail (format != NULL);
@@ -186,9 +191,8 @@ gedit_debug_message (GeditDebugSection section,
va_end (args);
#ifdef ENABLE_PROFILING
- seconds = g_timer_elapsed (timer, NULL);
g_print ("[%f (%f)] %s:%d (%s) %s\n",
- seconds, seconds - last, file, line, function, msg);
+ seconds, seconds - last, file, line, function, msg);
last = seconds;
#else
g_print ("%s:%d (%s) %s\n", file, line, function, msg);
@@ -200,4 +204,45 @@ gedit_debug_message (GeditDebugSection section,
}
}
+/**
+ * gedit_debug_plugin_message:
+ * @file: Name of the source file containing the call to gedit_debug_plugin_message().
+ * @line: Line number within the file named by @file of the call to gedit_debug_plugin_message().
+ * @function: Name of the function that is calling gedit_debug_plugin_message().
+ * @message: An informational message.
+ *
+ * If output for debug section %GEDIT_DEBUG_PLUGINS is enabled, then logs the trace
+ * information @file, @line, and @function along with the informational message
+ * @message.
+ *
+ * This function may be overridden by GObject Introspection language bindings
+ * to be more language-specific.
+ *
+ * <emphasis>Python</emphasis>
+ *
+ * A PyGObject override is provided that has the following signature:
+ * <informalexample>
+ * <programlisting>
+ * def debug_plugin_message(format_str, *format_args):
+ * #...
+ * </programlisting>
+ * </informalexample>
+ *
+ * It automatically supplies parameters @file, @line, and @function, and it
+ * formats <code>format_str</code> with the given format arguments. The syntax
+ * of the format string is the usual Python string formatting syntax described
+ * by <ulink url="http://docs.python.org/library/stdtypes.html#string-formatting">5.6.2. String Formatting Operations</ulink>.
+ *
+ * Since: 3.4
+ */
+void
+gedit_debug_plugin_message (const gchar *file,
+ gint line,
+ const gchar *function,
+ const gchar *message)
+{
+ gedit_debug_message (GEDIT_DEBUG_PLUGINS, file, line, function, "%s",
+ message);
+}
+
/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-debug.h b/gedit/gedit-debug.h
index 618e2d3..8b8b4fb 100644
--- a/gedit/gedit-debug.h
+++ b/gedit/gedit-debug.h
@@ -67,8 +67,6 @@ typedef enum {
GEDIT_DEBUG_DBUS = 1 << 16
} GeditDebugSection;
-
-/* FIXME this is an issue for introspection */
#define DEBUG_VIEW GEDIT_DEBUG_VIEW, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_SEARCH GEDIT_DEBUG_SEARCH, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_PRINT GEDIT_DEBUG_PRINT, __FILE__, __LINE__, G_STRFUNC
@@ -100,6 +98,10 @@ void gedit_debug_message (GeditDebugSection section,
const gchar *function,
const gchar *format, ...) G_GNUC_PRINTF(5, 6);
+void gedit_debug_plugin_message (const gchar *file,
+ gint line,
+ const gchar *function,
+ const gchar *message);
#endif /* __GEDIT_DEBUG_H__ */
/* ex:set ts=8 noet: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]