API freeze break request



Hi,
	The python GConf binding is missing a wrapping for GConfEngine, which
isn't used very often but I came across a need for it while writing a
little admin tool for GConf.

	See the patch below. The pygtk maintainers seem to be okay about
including it, so long as the release team approve.

	See:

  http://bugzilla.gnome.org/show_bug.cgi?id=164059

	for more details. Patch appended. Its pretty straightforward and
shouldn't impact any existing APIs.

Thanks,
Mark.
? t.tmp
? wrap-engine.patch
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-python/gnome-python/gconf/Makefile.am,v
retrieving revision 1.10
diff -u -p -r1.10 Makefile.am
--- Makefile.am	11 Aug 2004 15:42:40 -0000	1.10
+++ Makefile.am	14 Jan 2005 16:01:26 -0000
@@ -15,15 +15,24 @@ pkgpyexec_LTLIBRARIES = gconf.la
 gconf_la_CFLAGS = $(GCONF_CFLAGS)
 gconf_la_LDFLAGS = $(common_ldflags) -export-symbols-regex initgconf
 gconf_la_LIBADD = $(GCONF_LIBS)
-gconf_la_SOURCES = gconfmodule.c gconf-fixes.c gconf-fixes.h
+gconf_la_SOURCES = \
+	gconfmodule.c \
+	gconf-fixes.c \
+	gconf-fixes.h \
+	gconf-types.c \
+	gconf-types.h
 nodist_gconf_la_SOURCES = gconf.c
 CLEANFILES = gconf.c
 EXTRA_DIST = gconf.defs gconf.override  
-gconf.c: gconf.defs gconf.override
+gconf.c: gconf.defs gconf.override gconf-arg-types.py
+
+argtypesdir = $(datadir)/pygtk/2.0/argtypes
+argtypes_PYTHON = gconf-arg-types.py
 
 .defs.c:
 	(cd $(srcdir) \
 	 && $(PYGTK_CODEGEN) \
+	    --load-types gconf-arg-types.py \
 	    --override $*.override \
 	    --prefix py$* $*.defs) > gen-$*.c \
 	&& cp gen-$*.c $*.c \
Index: gconf-arg-types.py
===================================================================
RCS file: gconf-arg-types.py
diff -N gconf-arg-types.py
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gconf-arg-types.py	14 Jan 2005 16:01:26 -0000
@@ -0,0 +1,30 @@
+import argtypes
+
+class GConfEngineArg (argtypes.ArgType):
+    engine = ('    %(name)s = pygconf_engine_from_pyobject (py_%(name)s);\n'
+              '    if (PyErr_Occurred ())\n'
+              '        return NULL;\n')
+        
+    def write_param(self, ptype, pname, pdflt, pnull, info):
+        # pdflt and pnull not handled - we don't use "default" or "null-ok"
+        info.varlist.add ('GConfEngine*', pname)
+        info.varlist.add ('PyObject', '*py_' + pname + ' = NULL')
+        info.codebefore.append (self.engine % { 'name' : pname })
+        info.arglist.append (pname)
+        info.add_parselist ('O', ['&py_' + pname], [pname])
+        
+    def write_return (self, ptype, ownsreturn, info):
+        if ptype[-1] == '*':
+            ptype = ptype[:-1]
+        info.varlist.add (ptype, '*ret')
+        if ownsreturn:
+            info.varlist.add ('PyObject', '*py_ret')
+            info.codeafter.append ('    py_ret = pygconf_engine_new (ret);\n'
+                                   '    if (ret != NULL)\n'
+                                   '        gconf_engine_unref (ret);\n'
+                                   '    return py_ret;')
+        else:
+            info.codeafter.append ('    /* pygconf_engine_new() handles NULL checking */\n' +
+                                   '    return pygconf_engine_new (ret);')
+
+argtypes.matcher.register ("GConfEngine*", GConfEngineArg ())
Index: gconf-types.c
===================================================================
RCS file: gconf-types.c
diff -N gconf-types.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gconf-types.c	14 Jan 2005 16:01:26 -0000
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2005 Red Hat, Inc.
+ *
+ *   gconf-types.c: wrappers for some specialised GConf types.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include "gconf-types.h"
+
+#include <pygobject.h>
+
+typedef struct {
+  PyObject_HEAD
+  GConfEngine *engine;
+} PyGConfEngine;
+staticforward PyTypeObject PyGConfEngine_Type;
+
+static void
+pygconf_engine_dealloc (PyGConfEngine *self)
+{
+  pyg_begin_allow_threads;
+  gconf_engine_unref (self->engine);
+  pyg_end_allow_threads;
+  PyObject_DEL (self);
+}
+
+static PyTypeObject PyGConfEngine_Type = {
+  PyObject_HEAD_INIT (NULL)
+  0,
+  "gconf.GConfEngine",
+  sizeof (PyGConfEngine),
+  0,
+  (destructor) pygconf_engine_dealloc,
+  (printfunc) 0,
+  (getattrfunc) 0,
+  (setattrfunc) 0,
+  (cmpfunc) 0,
+  (reprfunc) 0,
+  0,
+  0,
+  0,
+  (hashfunc) 0,
+  (ternaryfunc) 0,
+  (reprfunc) 0,
+  (getattrofunc) 0,
+  (setattrofunc) 0,
+  0,
+  Py_TPFLAGS_DEFAULT
+};
+
+PyObject *
+pygconf_engine_new (GConfEngine *engine)
+{
+  PyGConfEngine *self;
+
+  if (engine == NULL)
+    {
+      Py_INCREF (Py_None);
+      return Py_None;
+    }
+
+  self = (PyGConfEngine *) PyObject_NEW (PyGConfEngine,	&PyGConfEngine_Type);
+  if (self == NULL)
+    return NULL;
+
+  pyg_begin_allow_threads;
+  self->engine = engine;
+  gconf_engine_ref (engine);
+  pyg_end_allow_threads;
+
+  return (PyObject *) self;
+}
+
+GConfEngine *
+pygconf_engine_from_pyobject (PyObject *object)
+{
+  PyGConfEngine *self;
+
+  if (object == NULL)
+    return NULL;
+
+  if (!PyObject_TypeCheck (object, &PyGConfEngine_Type))
+    {
+      PyErr_SetString (PyExc_TypeError, "unable to convert argument to GConfEngine*");
+      return NULL;
+    }
+
+  self = (PyGConfEngine *) object;
+
+  return self->engine;
+}
+
+void
+pygconf_register_engine_type (PyObject *moddict)
+{
+  PyGConfEngine_Type.ob_type = &PyType_Type;
+
+  PyType_Ready(&PyGConfEngine_Type);
+}
Index: gconf-types.h
===================================================================
RCS file: gconf-types.h
diff -N gconf-types.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gconf-types.h	14 Jan 2005 16:01:26 -0000
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2005 Red Hat, Inc.
+ *
+ *   gconf-types.h: wrappers for some specialised GConf types.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ * Author:
+ *     Mark McLoughlin <mark skynet ie>
+ */
+
+#ifndef __GCONF_TYPES_H__
+#define __GCONF_TYPES_H__
+
+#include <Python.h>
+#include <gconf/gconf.h>
+
+void         pygconf_register_engine_type (PyObject    *moddict);
+PyObject    *pygconf_engine_new           (GConfEngine *engine);
+GConfEngine *pygconf_engine_from_pyobject (PyObject    *object);
+     
+#endif /* __GCONF_TYPES_H__ */
Index: gconf.defs
===================================================================
RCS file: /cvs/gnome/gnome-python/gnome-python/gconf/gconf.defs,v
retrieving revision 1.10
diff -u -p -r1.10 gconf.defs
--- gconf.defs	12 Dec 2004 15:31:17 -0000	1.10
+++ gconf.defs	14 Jan 2005 16:01:27 -0000
@@ -848,24 +848,6 @@
   (return-type "none")
 )
 
-(define-function engine_get_local
-  (c-name "gconf_engine_get_local")
-  (return-type "GConfEngine*")
-  (parameters
-    '("const-char*" "address")
-    '("GError**" "err")
-  )
-)
-
-(define-function engine_get_local_for_addresses
-  (c-name "gconf_engine_get_local_for_addresses")
-  (return-type "GConfEngine*")
-  (parameters
-    '("GSList*" "addresses")
-    '("GError**" "err")
-  )
-)
-
 (define-method set_user_data
   (of-object "GConfEngine")
   (c-name "gconf_engine_set_user_data")
@@ -1980,24 +1962,6 @@
   (parameters
     '("gpointer" "app")
     '("gpointer" "mod_info")
-  )
-)
-
-(define-function clear_cache
-  (c-name "gconf_clear_cache")
-  (return-type "none")
-  (parameters
-    '("GConfEngine*" "conf")
-    '("GError**" "err")
-  )
-)
-
-(define-function synchronous_sync
-  (c-name "gconf_synchronous_sync")
-  (return-type "none")
-  (parameters
-    '("GConfEngine*" "conf")
-    '("GError**" "err")
   )
 )
 
Index: gconf.override
===================================================================
RCS file: /cvs/gnome/gnome-python/gnome-python/gconf/gconf.override,v
retrieving revision 1.17
diff -u -p -r1.17 gconf.override
--- gconf.override	12 Dec 2004 15:31:17 -0000	1.17
+++ gconf.override	14 Jan 2005 16:01:27 -0000
@@ -4,6 +4,7 @@ headers
 #include <Python.h>
 
 #include "gconf-fixes.h"
+#include "gconf-types.h"
 
 #define NO_IMPORT_PYGOBJECT
 #include "pygobject.h"
Index: gconfmodule.c
===================================================================
RCS file: /cvs/gnome/gnome-python/gnome-python/gconf/gconfmodule.c,v
retrieving revision 1.4
diff -u -p -r1.4 gconfmodule.c
--- gconfmodule.c	24 Aug 2003 14:02:52 -0000	1.4
+++ gconfmodule.c	14 Jan 2005 16:01:27 -0000
@@ -7,6 +7,8 @@
 /* include this first, before NO_IMPORT_PYGOBJECT is defined */
 #include <pygobject.h>
 
+#include "gconf-types.h"
+
 void pygconf_register_classes (PyObject *d);
 void pygconf_add_constants(PyObject *module, const gchar *strip_prefix);
 		
@@ -24,4 +26,5 @@ initgconf (void)
 
 	pygconf_register_classes (d);
 	pygconf_add_constants (m, "GCONF_");
+	pygconf_register_engine_type (m);
 }


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