diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:46:30 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:46:33 +0900 |
commit | dca4e6423c560689ee831785473ad3ab48e7548a (patch) | |
tree | 048ddb6edb0826be8ff180c027d45acb6dac67db /gi/pygpointer.c | |
parent | 392945d666d2cfb31a844826a72b1eb65a52546f (diff) | |
download | pygobject2-dca4e6423c560689ee831785473ad3ab48e7548a.tar.gz pygobject2-dca4e6423c560689ee831785473ad3ab48e7548a.tar.bz2 pygobject2-dca4e6423c560689ee831785473ad3ab48e7548a.zip |
Imported Upstream version 3.3.1
Change-Id: I7e59d7cf82217b545ec40115122a83ebf79763cb
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'gi/pygpointer.c')
-rw-r--r-- | gi/pygpointer.c | 198 |
1 files changed, 0 insertions, 198 deletions
diff --git a/gi/pygpointer.c b/gi/pygpointer.c deleted file mode 100644 index dccd303..0000000 --- a/gi/pygpointer.c +++ /dev/null @@ -1,198 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- - * pygtk- Python bindings for the GTK toolkit. - * Copyright (C) 1998-2003 James Henstridge - * - * pygpointer.c: wrapper for GPointer - * - * 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, see <http://www.gnu.org/licenses/>. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <pyglib.h> -#include <glib-object.h> -#include "pygpointer.h" -#include "pygtype.h" - -#include "pygi-type.h" - - -GQuark pygpointer_class_key; - -PYGLIB_DEFINE_TYPE("gobject.GPointer", PyGPointer_Type, PyGPointer); - -static void -pyg_pointer_dealloc(PyGPointer *self) -{ - Py_TYPE(self)->tp_free((PyObject *)self); -} - -static PyObject* -pyg_pointer_richcompare(PyObject *self, PyObject *other, int op) -{ - if (Py_TYPE(self) == Py_TYPE(other)) - return _pyglib_generic_ptr_richcompare (pyg_pointer_get_ptr (self), - pyg_pointer_get_ptr (other), - op); - else { - Py_INCREF(Py_NotImplemented); - return Py_NotImplemented; - } -} - -static PYGLIB_Py_hash_t -pyg_pointer_hash(PyGPointer *self) -{ - return PYGLIB_Py_hash_t_FromVoidPtr (pyg_pointer_get_ptr (self)); -} - -static PyObject * -pyg_pointer_repr(PyGPointer *self) -{ - gchar buf[128]; - - g_snprintf(buf, sizeof(buf), "<%s at 0x%" G_GUINTPTR_FORMAT ">", - g_type_name(self->gtype), - (guintptr)pyg_pointer_get_ptr (self)); - return PYGLIB_PyUnicode_FromString(buf); -} - -static int -pyg_pointer_init(PyGPointer *self, PyObject *args, PyObject *kwargs) -{ - gchar buf[512]; - - if (!PyArg_ParseTuple(args, ":GPointer.__init__")) - return -1; - - pyg_pointer_set_ptr (self, NULL); - self->gtype = 0; - - g_snprintf(buf, sizeof(buf), "%s can not be constructed", - Py_TYPE(self)->tp_name); - PyErr_SetString(PyExc_NotImplementedError, buf); - return -1; -} - -static void -pyg_pointer_free(PyObject *op) -{ - PyObject_FREE(op); -} - -/** - * pyg_register_pointer: - * @dict: the module dictionary to store the wrapper class. - * @class_name: the Python name for the wrapper class. - * @pointer_type: the GType of the pointer type being wrapped. - * @type: the wrapper class. - * - * Registers a wrapper for a pointer type. The wrapper class will be - * a subclass of gobject.GPointer, and a reference to the wrapper - * class will be stored in the provided module dictionary. - */ -void -pyg_register_pointer(PyObject *dict, const gchar *class_name, - GType pointer_type, PyTypeObject *type) -{ - PyObject *o; - - g_return_if_fail(dict != NULL); - g_return_if_fail(class_name != NULL); - g_return_if_fail(pointer_type != 0); - - if (!type->tp_dealloc) type->tp_dealloc = (destructor)pyg_pointer_dealloc; - - Py_TYPE(type) = &PyType_Type; - type->tp_base = &PyGPointer_Type; - - if (PyType_Ready(type) < 0) { - g_warning("could not get type `%s' ready", type->tp_name); - return; - } - - PyDict_SetItemString(type->tp_dict, "__gtype__", - o=pyg_type_wrapper_new(pointer_type)); - Py_DECREF(o); - - g_type_set_qdata(pointer_type, pygpointer_class_key, type); - - PyDict_SetItemString(dict, (char *)class_name, (PyObject *)type); -} - -/** - * pyg_pointer_new: - * @pointer_type: the GType of the pointer value. - * @pointer: the pointer value. - * - * Creates a wrapper for a pointer value. Since G_TYPE_POINTER types - * don't register any information about how to copy/free them, there - * is no guarantee that the pointer will remain valid, and there is - * nothing registered to release the pointer when the pointer goes out - * of scope. This is why we don't recommend people use these types. - * - * Returns: the boxed wrapper. - */ -PyObject * -pyg_pointer_new(GType pointer_type, gpointer pointer) -{ - PyGILState_STATE state; - PyGPointer *self; - PyTypeObject *tp; - g_return_val_if_fail(pointer_type != 0, NULL); - - state = PyGILState_Ensure(); - - if (!pointer) { - Py_INCREF(Py_None); - PyGILState_Release(state); - return Py_None; - } - - tp = g_type_get_qdata(pointer_type, pygpointer_class_key); - - if (!tp) - tp = (PyTypeObject *)pygi_type_import_by_g_type(pointer_type); - - if (!tp) - tp = (PyTypeObject *)&PyGPointer_Type; /* fallback */ - self = PyObject_NEW(PyGPointer, tp); - - PyGILState_Release(state); - - if (self == NULL) - return NULL; - - pyg_pointer_set_ptr (self, pointer); - self->gtype = pointer_type; - - return (PyObject *)self; -} - -void -pygobject_pointer_register_types(PyObject *d) -{ - pygpointer_class_key = g_quark_from_static_string("PyGPointer::class"); - - PyGPointer_Type.tp_dealloc = (destructor)pyg_pointer_dealloc; - PyGPointer_Type.tp_richcompare = pyg_pointer_richcompare; - PyGPointer_Type.tp_repr = (reprfunc)pyg_pointer_repr; - PyGPointer_Type.tp_hash = (hashfunc)pyg_pointer_hash; - PyGPointer_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; - PyGPointer_Type.tp_init = (initproc)pyg_pointer_init; - PyGPointer_Type.tp_free = (freefunc)pyg_pointer_free; - PYGOBJECT_REGISTER_GTYPE(d, PyGPointer_Type, "GPointer", G_TYPE_POINTER); -} |