Commit a6a90551 authored by Tomeu Vizoso's avatar Tomeu Vizoso
parent 8b3a3baa
......@@ -22,6 +22,7 @@
*/
#include "pygi-private.h"
#include "pygi.h"
#include <pygobject.h>
......@@ -241,11 +242,10 @@ static PyMethodDef _pygi_functions[] = {
{ NULL, NULL, 0 }
};
struct PyGI_API PyGI_API = {
pygi_type_import_by_g_type
static struct PyGI_API CAPI = {
pygi_type_import_by_g_type_real,
};
PyMODINIT_FUNC
init_gi (void)
{
......@@ -275,7 +275,7 @@ init_gi (void)
_pygi_boxed_register_types (m);
_pygi_argument_init();
api = PyCObject_FromVoidPtr ( (void *) &PyGI_API, NULL);
api = PyCObject_FromVoidPtr ( (void *) &CAPI, NULL);
if (api == NULL) {
return;
}
......
......@@ -54,7 +54,7 @@ _pygi_type_import_by_gi_info (GIBaseInfo *info)
}
PyObject *
pygi_type_import_by_g_type (GType g_type)
pygi_type_import_by_g_type_real (GType g_type)
{
GIRepository *repository;
GIBaseInfo *info;
......@@ -86,7 +86,7 @@ _pygi_type_get_from_g_type (GType g_type)
py_type = PyObject_GetAttrString (py_g_type, "pytype");
if (py_type == Py_None) {
py_type = pygi_type_import_by_g_type (g_type);
py_type = pygi_type_import_by_g_type_real (g_type);
}
Py_DECREF (py_g_type);
......
......@@ -28,7 +28,7 @@ G_BEGIN_DECLS
/* Public */
PyObject *pygi_type_import_by_g_type (GType g_type);
PyObject *pygi_type_import_by_g_type_real (GType g_type);
/* Private */
......
......@@ -22,11 +22,12 @@
#ifndef __PYGI_H__
#define __PYGI_H__
#include <config.h>
#include <pygobject.h>
#include <girepository.h>
#if ENABLE_INTROSPECTION
G_BEGIN_DECLS
#include <girepository.h>
typedef struct {
PyObject_HEAD
......@@ -55,51 +56,40 @@ struct PyGI_API {
PyObject* (*type_import_by_g_type) (GType g_type);
};
#ifndef __PYGI_PRIVATE_H__
static struct PyGI_API *PyGI_API = NULL;
#define pygi_type_import_by_g_type (PyGI_API->type_import_by_g_type)
static int
pygi_import (void)
_pygi_import (void)
{
PyObject *module;
PyObject *api;
if (PyGI_API != NULL) {
return 1;
}
module = PyImport_ImportModule ("gi");
if (module == NULL) {
PyGI_API = (struct PyGI_API*) PyCObject_Import("gi", "_API");
if (PyGI_API == NULL) {
return -1;
}
api = PyObject_GetAttrString (module, "_API");
if (api == NULL) {
Py_DECREF (module);
return -1;
}
if (!PyCObject_Check (api)) {
Py_DECREF (module);
Py_DECREF (api);
PyErr_Format (PyExc_TypeError, "gi._API must be cobject, not %s",
api->ob_type->tp_name);
return -1;
}
return 0;
}
PyGI_API = (struct PyGI_API *) PyCObject_AsVoidPtr (api);
static inline PyObject *
pygi_type_import_by_g_type (GType g_type)
{
if (_pygi_import() < 0) {
return NULL;
}
return PyGI_API->type_import_by_g_type(g_type);
}
Py_DECREF (api);
#else /* ENABLE_INTROSPECTION */
return 0;
static inline PyObject *
pygi_type_import_by_g_type (GType g_type)
{
return NULL;
}
#endif /* __PYGI_PRIVATE_H__ */
G_END_DECLS
#endif /* ENABLE_INTROSPECTION */
#endif /* __PYGI_H__ */
......@@ -21,10 +21,16 @@ endif
_gobject_la_CFLAGS = \
-I$(top_srcdir)/glib \
-I$(top_srcdir)/gi \
$(PYTHON_INCLUDES) \
$(FFI_CFLAGS) \
$(GLIB_CFLAGS) \
-DPY_SSIZE_T_CLEAN
if ENABLE_INTROSPECTION
_gobject_la_CFLAGS += $(GI_CFLAGS)
endif
_gobject_la_LDFLAGS = $(common_ldflags) -export-symbols-regex "_gobject|PyInit__gobject"
_gobject_la_LIBADD = \
$(GLIB_LIBS) \
......
......@@ -28,7 +28,7 @@
#include "pygobject-private.h"
#include "pygboxed.h"
#include "pygi-external.h"
#include "pygi.h"
GQuark pygboxed_type_key;
GQuark pygboxed_marshal_key;
......
......@@ -28,7 +28,7 @@
#include <pyglib.h>
#include "pygobject-private.h"
#include "pygi-external.h"
#include "pygi.h"
GQuark pygenum_class_key;
......
......@@ -29,7 +29,7 @@
#include "pygobject-private.h"
#include "pygflags.h"
#include "pygi-external.h"
#include "pygi.h"
GQuark pygflags_class_key;
......
/* -*- Mode: C; c-basic-offset: 4 -*-
* vim: tabstop=4 shiftwidth=4 expandtab
*/
#ifndef _PYGI_EXTERNAL_H_
#define _PYGI_EXTERNAL_H_
#include <Python.h>
#include <glib.h>
struct PyGI_API {
PyObject* (*type_import_by_g_type) (GType g_type);
};
static struct PyGI_API *PyGI_API = NULL;
static int
_pygi_import (void)
{
#if ENABLE_INTROSPECTION
PyObject *module;
PyObject *api;
if (PyGI_API != NULL) {
return 1;
}
module = PyImport_ImportModule("gi");
if (module == NULL) {
PyErr_Clear();
return -1;
}
api = PyObject_GetAttrString(module, "_API");
if (api == NULL) {
PyErr_Clear();
Py_DECREF(module);
return -1;
}
if (!PyCObject_Check(api)) {
Py_DECREF(module);
Py_DECREF(api);
PyErr_Format(PyExc_TypeError, "gi._API must be cobject, not %s",
api->ob_type->tp_name);
return -1;
}
PyGI_API = (struct PyGI_API *)PyCObject_AsVoidPtr(api);
Py_DECREF(module);
return 0;
#else
return -1;
#endif /* ENABLE_INTROSPECTION */
}
static inline PyObject *
pygi_type_import_by_g_type (GType g_type)
{
if (_pygi_import() < 0) {
return NULL;
}
return PyGI_API->type_import_by_g_type(g_type);
}
#endif /* _PYGI_EXTERNAL_H_ */
......@@ -29,7 +29,7 @@
#include "pyginterface.h"
#include "pygparamspec.h"
#include "pygi-external.h"
#include "pygi.h"
static void pygobject_dealloc(PyGObject *self);
......
......@@ -28,7 +28,7 @@
#include "pygobject-private.h"
#include "pygpointer.h"
#include "pygi-external.h"
#include "pygi.h"
GQuark pygpointer_class_key;
......
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