[pygobject] Use accessors for getting and setting PyGParamSpec pointers
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Use accessors for getting and setting PyGParamSpec pointers
- Date: Fri, 16 May 2014 22:12:04 +0000 (UTC)
commit bbbfa967d06eb8fdef6d6ebe705cc8df2869ddf3
Author: Simon Feltman <sfeltman src gnome org>
Date: Fri May 16 15:08:35 2014 -0700
Use accessors for getting and setting PyGParamSpec pointers
Add pyg_param_spec_get and pyg_param_spec_set macros for getting and
setting the GParamSpec pointer field held by the Python wrapper. This
is preliminary cleanup work for supporting fundamental types.
https://bugzilla.gnome.org/show_bug.cgi?id=631901
gi/pygi-value.c | 2 +-
gi/pygobject.h | 9 +++++++--
gi/pygparamspec.c | 22 +++++++++++-----------
3 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/gi/pygi-value.c b/gi/pygi-value.c
index 8235116..f54f8e1 100644
--- a/gi/pygi-value.c
+++ b/gi/pygi-value.c
@@ -555,7 +555,7 @@ pyg_value_from_pyobject_with_error(GValue *value, PyObject *obj)
* GObject.ParamSpec */
if (G_IS_PARAM_SPEC (pygobject_get (obj)))
g_value_set_param(value, G_PARAM_SPEC (pygobject_get (obj)));
- else if (PyGParamSpec_Check(obj))
+ else if (pyg_param_spec_check (obj))
g_value_set_param(value, PYGLIB_CPointer_GetPointer(obj, NULL));
else {
PyErr_SetString(PyExc_TypeError, "Expected ParamSpec");
diff --git a/gi/pygobject.h b/gi/pygobject.h
index c51bfdd..85359a5 100644
--- a/gi/pygobject.h
+++ b/gi/pygobject.h
@@ -80,8 +80,13 @@ typedef struct {
GParamSpec *pspec;
} PyGParamSpec;
-#define PyGParamSpec_Get(v) (((PyGParamSpec *)v)->pspec)
-#define PyGParamSpec_Check(v) (PyObject_TypeCheck(v, &PyGParamSpec_Type))
+#define pyg_param_spec_get(v) (((PyGParamSpec *)v)->pspec)
+#define pyg_param_spec_set(v,p) (((PyGParamSpec *)v)->pspec = (GParamSpec*)p)
+#define pyg_param_spec_check(v) (PyObject_TypeCheck(v, &PyGParamSpec_Type))
+
+/* Deprecated in favor of lower case with underscore macros above. */
+#define PyGParamSpec_Get pyg_param_spec_get
+#define PyGParamSpec_Check pyg_param_spec_check
typedef int (*PyGClassInitFunc) (gpointer gclass, PyTypeObject *pyclass);
typedef PyTypeObject * (*PyGTypeRegistrationFunction) (const gchar *name,
diff --git a/gi/pygparamspec.c b/gi/pygparamspec.c
index 9e6c467..ff53243 100644
--- a/gi/pygparamspec.c
+++ b/gi/pygparamspec.c
@@ -34,9 +34,9 @@ static PyObject*
pyg_param_spec_richcompare(PyObject *self, PyObject *other, int op)
{
if (Py_TYPE(self) == Py_TYPE(other) && Py_TYPE(self) == &PyGParamSpec_Type)
- return _pyglib_generic_ptr_richcompare(((PyGParamSpec*)self)->pspec,
- ((PyGParamSpec*)other)->pspec,
- op);
+ return _pyglib_generic_ptr_richcompare (pyg_param_spec_get (self),
+ pyg_param_spec_get (other),
+ op);
else {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
@@ -46,7 +46,7 @@ pyg_param_spec_richcompare(PyObject *self, PyObject *other, int op)
static long
pyg_param_spec_hash(PyGParamSpec *self)
{
- return (long)self->pspec;
+ return (long)pyg_param_spec_get (self);
}
static PyObject *
@@ -55,15 +55,15 @@ pyg_param_spec_repr(PyGParamSpec *self)
char buf[80];
g_snprintf(buf, sizeof(buf), "<%s '%s'>",
- G_PARAM_SPEC_TYPE_NAME(self->pspec),
- g_param_spec_get_name(self->pspec));
+ G_PARAM_SPEC_TYPE_NAME (pyg_param_spec_get (self)),
+ g_param_spec_get_name (pyg_param_spec_get (self)));
return PYGLIB_PyUnicode_FromString(buf);
}
static void
pyg_param_spec_dealloc(PyGParamSpec *self)
{
- g_param_spec_unref(self->pspec);
+ g_param_spec_unref (pyg_param_spec_get (self));
PyObject_DEL(self);
}
@@ -112,8 +112,8 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
{
GParamSpec *pspec;
- pspec = self->pspec;
-
+ pspec = pyg_param_spec_get (self);
+
/* common attributes */
if (!strcmp(attr, "__gtype__")) {
return pyg_type_wrapper_new(G_PARAM_SPEC_TYPE(pspec));
@@ -281,7 +281,7 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
static PyObject *
pyg_param_spec_dir(PyGParamSpec *self, PyObject *dummy)
{
- GParamSpec *pspec = self->pspec;
+ GParamSpec *pspec = pyg_param_spec_get (self);
if (G_IS_PARAM_SPEC_CHAR(pspec)) {
return Py_BuildValue("[sssssssssss]", "__doc__", "__gtype__",
@@ -393,7 +393,7 @@ pyg_param_spec_new(GParamSpec *pspec)
if (self == NULL)
return NULL;
- self->pspec = g_param_spec_ref(pspec);
+ pyg_param_spec_set (self, g_param_spec_ref (pspec));
return (PyObject *)self;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]