Commit 18d82747 authored by Simon Feltman's avatar Simon Feltman
Browse files

cache refactoring: Move GError arg setup and marshaling to new file

Move GError argument caching and marshaling fragments into
isolated file: pygi-error.c.

https://bugzilla.gnome.org/show_bug.cgi?id=709700
parent c45cafd0
......@@ -109,6 +109,8 @@ _gi_la_SOURCES = \
pygi-list.h \
pygi-array.c \
pygi-array.h \
pygi-error.c \
pygi-error.h \
pygi-hashtable.c \
pygi-hashtable.h
_gi_la_CFLAGS = \
......
......@@ -31,6 +31,7 @@
#include "pygi-basictype.h"
#include "pygi-list.h"
#include "pygi-array.h"
#include "pygi-error.h"
PyGIArgCache * _arg_cache_new_for_interface (GIInterfaceInfo *iface_info,
......@@ -275,20 +276,6 @@ _arg_cache_alloc (void)
return g_slice_new0 (PyGIArgCache);
}
static void
_arg_cache_from_py_gerror_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_gerror;
arg_cache->meta_type = PYGI_META_ARG_TYPE_CHILD;
}
static void
_arg_cache_to_py_gerror_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_gerror;
arg_cache->meta_type = PYGI_META_ARG_TYPE_CHILD;
}
static void
_arg_cache_from_py_interface_union_setup (PyGIArgCache *arg_cache,
GITransfer transfer)
......@@ -553,14 +540,11 @@ _arg_cache_new (GITypeInfo *type_info,
case GI_TYPE_TAG_GTYPE:
case GI_TYPE_TAG_UTF8:
case GI_TYPE_TAG_FILENAME:
arg_cache = pygi_arg_basic_type_new_from_info (type_info, arg_info, transfer, direction);
if (arg_cache) {
arg_cache->py_arg_index = py_arg_index;
arg_cache->c_arg_index = c_arg_index;
return arg_cache;
} else {
return NULL;
}
arg_cache = pygi_arg_basic_type_new_from_info (type_info,
arg_info,
transfer,
direction);
break;
case GI_TYPE_TAG_ARRAY:
{
......@@ -577,42 +561,29 @@ _arg_cache_new (GITypeInfo *type_info,
direction,
c_arg_index,
&py_arg_index);
arg_cache->py_arg_index = py_arg_index;
arg_cache->c_arg_index = c_arg_index;
return arg_cache;
}
break;
case GI_TYPE_TAG_GLIST:
{
arg_cache = pygi_arg_glist_new_from_info (type_info,
arg_info,
transfer,
direction);
if (arg_cache == NULL)
return NULL;
break;
arg_cache->py_arg_index = py_arg_index;
arg_cache->c_arg_index = c_arg_index;
return arg_cache;
}
case GI_TYPE_TAG_GSLIST:
{
arg_cache = pygi_arg_gslist_new_from_info (type_info,
arg_info,
transfer,
direction);
if (arg_cache == NULL)
return NULL;
break;
arg_cache->py_arg_index = py_arg_index;
arg_cache->c_arg_index = c_arg_index;
return arg_cache;
}
case GI_TYPE_TAG_GHASH:
arg_cache = pygi_arg_hash_table_new_from_info (type_info, arg_info, transfer, direction);
arg_cache->py_arg_index = py_arg_index;
arg_cache->c_arg_index = c_arg_index;
return arg_cache;
arg_cache = pygi_arg_hash_table_new_from_info (type_info,
arg_info,
transfer,
direction);
break;
case GI_TYPE_TAG_INTERFACE:
{
......@@ -625,26 +596,18 @@ _arg_cache_new (GITypeInfo *type_info,
callable_cache);
g_base_info_unref ( (GIBaseInfo *)interface_info);
arg_cache->py_arg_index = py_arg_index;
arg_cache->c_arg_index = c_arg_index;
return arg_cache;
}
case GI_TYPE_TAG_ERROR:
arg_cache = _arg_cache_alloc ();
if (arg_cache == NULL)
break;
if (direction & PYGI_DIRECTION_FROM_PYTHON)
_arg_cache_from_py_gerror_setup (arg_cache);
if (direction & PYGI_DIRECTION_TO_PYTHON)
_arg_cache_to_py_gerror_setup (arg_cache);
case GI_TYPE_TAG_ERROR:
arg_cache = pygi_arg_gerror_new_from_info (type_info,
arg_info,
transfer,
direction);
break;
}
if (arg_cache != NULL) {
pygi_arg_base_setup (arg_cache, type_info, arg_info, transfer, direction);
arg_cache->py_arg_index = py_arg_index;
arg_cache->c_arg_index = c_arg_index;
}
......
/* -*- Mode: C; c-basic-offset: 4 -*-
* vim: tabstop=4 shiftwidth=4 expandtab
*
* Copyright (C) 2011 John (J5) Palmieri <johnp@redhat.com>
* Copyright (C) 2014 Simon Feltman <sfeltman@gnome.org>
*
* 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/>.
*/
#include "pyglib.h"
#include "pygi-private.h"
#include "pygi-error.h"
static gboolean
_pygi_marshal_from_py_gerror (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
PyObject *py_arg,
GIArgument *arg,
gpointer *cleanup_data)
{
PyErr_Format (PyExc_NotImplementedError,
"Marshalling for GErrors is not implemented");
return FALSE;
}
static PyObject *
_pygi_marshal_to_py_gerror (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
GError *error = arg->v_pointer;
PyObject *py_obj = NULL;
py_obj = pyglib_error_marshal(&error);
if (arg_cache->transfer == GI_TRANSFER_EVERYTHING && error != NULL) {
g_error_free (error);
}
if (py_obj != NULL) {
return py_obj;
} else {
Py_RETURN_NONE;
}
}
static gboolean
pygi_arg_gerror_setup_from_info (PyGIArgCache *arg_cache,
GITypeInfo *type_info,
GIArgInfo *arg_info,
GITransfer transfer,
PyGIDirection direction)
{
if (!pygi_arg_base_setup (arg_cache, type_info, arg_info, transfer, direction)) {
return FALSE;
}
if (direction & PYGI_DIRECTION_FROM_PYTHON) {
arg_cache->from_py_marshaller = _pygi_marshal_from_py_gerror;
arg_cache->meta_type = PYGI_META_ARG_TYPE_CHILD;
}
if (direction & PYGI_DIRECTION_TO_PYTHON) {
arg_cache->to_py_marshaller = _pygi_marshal_to_py_gerror;
arg_cache->meta_type = PYGI_META_ARG_TYPE_CHILD;
}
return TRUE;
}
PyGIArgCache *
pygi_arg_gerror_new_from_info (GITypeInfo *type_info,
GIArgInfo *arg_info,
GITransfer transfer,
PyGIDirection direction)
{
gboolean res = FALSE;
PyGIArgCache *arg_cache = NULL;
arg_cache = _arg_cache_alloc ();
if (arg_cache == NULL)
return NULL;
res = pygi_arg_gerror_setup_from_info (arg_cache,
type_info,
arg_info,
transfer,
direction);
if (res) {
return arg_cache;
} else {
_pygi_arg_cache_free (arg_cache);
return NULL;
}
}
/* -*- Mode: C; c-basic-offset: 4 -*-
* vim: tabstop=4 shiftwidth=4 expandtab
*
* Copyright (C) 2014 Simon Feltman <sfeltman@gnome.org>
*
* 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/>.
*/
#ifndef __PYGI_ERROR_H__
#define __PYGI_ERROR_H__
#include <girepository.h>
#include "pygi-cache.h"
G_BEGIN_DECLS
PyGIArgCache *pygi_arg_gerror_new_from_info (GITypeInfo *type_info,
GIArgInfo *arg_info, /* may be null */
GITransfer transfer,
PyGIDirection direction);
G_END_DECLS
#endif /*__PYGI_ERROR_H__*/
......@@ -140,19 +140,6 @@ _is_union_member (GIInterfaceInfo *interface_info, PyObject *py_arg) {
return is_member;
}
gboolean
_pygi_marshal_from_py_gerror (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
PyObject *py_arg,
GIArgument *arg,
gpointer *cleanup_data)
{
PyErr_Format (PyExc_NotImplementedError,
"Marshalling for GErrors is not implemented");
return FALSE;
}
/* _pygi_destroy_notify_dummy:
*
* Dummy method used in the occasion when a method has a GDestroyNotify
......
......@@ -33,12 +33,6 @@ G_BEGIN_DECLS
gboolean _pygi_marshal_from_py_ssize_t (PyGIArgCache *arg_cache,
Py_ssize_t size,
GIArgument *arg);
gboolean _pygi_marshal_from_py_gerror (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
PyObject *py_arg,
GIArgument *arg,
gpointer *cleanup_data);
gboolean _pygi_marshal_from_py_interface_callback (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
......
......@@ -74,28 +74,6 @@ gi_argument_to_c_long (GIArgument *arg_in,
}
}
PyObject *
_pygi_marshal_to_py_gerror (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
GError *error = arg->v_pointer;
PyObject *py_obj = NULL;
py_obj = pyglib_error_marshal(&error);
if (arg_cache->transfer == GI_TRANSFER_EVERYTHING && error != NULL) {
g_error_free (error);
}
if (py_obj != NULL) {
return py_obj;
} else {
Py_RETURN_NONE;
}
}
PyObject *
_pygi_marshal_to_py_interface_callback (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
......
......@@ -22,10 +22,6 @@
#ifndef __PYGI_MARSHAL_TO_PY_H__
#define __PYGI_MARSHAL_TO_PY_H__
PyObject *_pygi_marshal_to_py_gerror (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
PyObject *_pygi_marshal_to_py_interface_callback(PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment