summaryrefslogtreecommitdiff
path: root/gi/gimodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'gi/gimodule.c')
-rw-r--r--gi/gimodule.c125
1 files changed, 73 insertions, 52 deletions
diff --git a/gi/gimodule.c b/gi/gimodule.c
index cf3c5ea2..630135c4 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -52,7 +52,6 @@
#include "pygi-property.h"
#include "pygi-util.h"
#include "gimodule.h"
-#include "pygi-python-compat.h"
#include "pygi-basictype.h"
PyObject *PyGIWarning;
@@ -442,7 +441,7 @@ pyg_param_spec_from_object (PyObject *tuple)
}
item = PyTuple_GetItem(tuple, val_length-1);
- if (!PYGLIB_PyLong_Check(item)) {
+ if (!PyLong_Check (item)) {
PyErr_SetString(PyExc_TypeError,
"last element in tuple must be an int");
return NULL;
@@ -565,13 +564,13 @@ add_properties (GObjectClass *klass, PyObject *properties)
/* values are of format (type,nick,blurb, type_specific_args, flags) */
- if (!PYGLIB_PyUnicode_Check(key)) {
+ if (!PyUnicode_Check(key)) {
PyErr_SetString(PyExc_TypeError,
"__gproperties__ keys must be strings");
ret = FALSE;
break;
}
- prop_name = PYGLIB_PyUnicode_AsString (key);
+ prop_name = PyUnicode_AsUTF8 (key);
if (!PyTuple_Check(value)) {
PyErr_SetString(PyExc_TypeError,
@@ -604,7 +603,7 @@ add_properties (GObjectClass *klass, PyObject *properties)
break;
}
item = PyTuple_GetItem(value, val_length-1);
- if (!PYGLIB_PyLong_Check(item)) {
+ if (!PyLong_Check (item)) {
PyErr_SetString(PyExc_TypeError,
"last element in __gproperties__ value tuple must be an int");
ret = FALSE;
@@ -627,14 +626,14 @@ add_properties (GObjectClass *klass, PyObject *properties)
PyObject *type, *pvalue, *traceback;
ret = FALSE;
PyErr_Fetch(&type, &pvalue, &traceback);
- if (PYGLIB_PyUnicode_Check(pvalue)) {
+ if (PyUnicode_Check(pvalue)) {
char msg[256];
g_snprintf(msg, 256,
"%s (while registering property '%s' for GType '%s')",
- PYGLIB_PyUnicode_AsString(pvalue),
+ PyUnicode_AsUTF8 (pvalue),
prop_name, G_OBJECT_CLASS_NAME(klass));
Py_DECREF(pvalue);
- value = PYGLIB_PyUnicode_FromString(msg);
+ value = PyUnicode_FromString (msg);
}
PyErr_Restore(type, pvalue, traceback);
break;
@@ -682,7 +681,7 @@ _pyg_signal_accumulator(GSignalInvocationHint *ihint,
state = PyGILState_Ensure();
if (ihint->detail)
- py_detail = PYGLIB_PyUnicode_FromString(g_quark_to_string(ihint->detail));
+ py_detail = PyUnicode_FromString (g_quark_to_string(ihint->detail));
else {
Py_INCREF(Py_None);
py_detail = Py_None;
@@ -826,17 +825,17 @@ add_signals (GObjectClass *klass, PyObject *signals)
const gchar *signal_name;
gchar *signal_name_canon, *c;
- if (!PYGLIB_PyUnicode_Check(key)) {
+ if (!PyUnicode_Check(key)) {
PyErr_SetString(PyExc_TypeError,
"__gsignals__ keys must be strings");
ret = FALSE;
break;
}
- signal_name = PYGLIB_PyUnicode_AsString (key);
+ signal_name = PyUnicode_AsUTF8 (key);
if (value == Py_None ||
- (PYGLIB_PyUnicode_Check(value) &&
- !strcmp(PYGLIB_PyUnicode_AsString(value), "override")))
+ (PyUnicode_Check(value) &&
+ !strcmp(PyUnicode_AsUTF8 (value), "override")))
{
/* canonicalize signal name, replacing '-' with '_' */
signal_name_canon = g_strdup(signal_name);
@@ -1215,8 +1214,8 @@ get_type_name_for_class(PyTypeObject *class)
g_free(type_name);
g_snprintf(name_serial_str, 16, "-v%i", name_serial);
module = PyObject_GetAttrString((PyObject *)class, "__module__");
- if (module && PYGLIB_PyUnicode_Check(module)) {
- type_name = g_strconcat(PYGLIB_PyUnicode_AsString(module), ".",
+ if (module && PyUnicode_Check (module)) {
+ type_name = g_strconcat(PyUnicode_AsUTF8 (module), ".",
class->tp_name,
name_serial > 1 ? name_serial_str : NULL,
NULL);
@@ -1934,7 +1933,7 @@ pyg_channel_read(PyObject* self, PyObject *args, PyObject *kwargs)
}
if (max_count == 0)
- return PYGLIB_PyBytes_FromString("");
+ return PyBytes_FromString ("");
iochannel = pyg_boxed_get (py_iochannel, GIOChannel);
@@ -1953,16 +1952,16 @@ pyg_channel_read(PyObject* self, PyObject *args, PyObject *kwargs)
}
if ( ret_obj == NULL ) {
- ret_obj = PYGLIB_PyBytes_FromStringAndSize((char *)NULL, buf_size);
+ ret_obj = PyBytes_FromStringAndSize ((char *)NULL, buf_size);
if (ret_obj == NULL)
goto failure;
}
- else if (buf_size + total_read > (gsize)PYGLIB_PyBytes_Size(ret_obj)) {
- if (PYGLIB_PyBytes_Resize(&ret_obj, buf_size + total_read) == -1)
+ else if (buf_size + total_read > (gsize)PyBytes_Size (ret_obj)) {
+ if (_PyBytes_Resize (&ret_obj, buf_size + total_read) == -1)
goto failure;
}
- buf = PYGLIB_PyBytes_AsString(ret_obj) + total_read;
+ buf = PyBytes_AsString (ret_obj) + total_read;
Py_BEGIN_ALLOW_THREADS;
status = g_io_channel_read_chars (iochannel, buf, buf_size, &single_read, &error);
@@ -1974,8 +1973,8 @@ pyg_channel_read(PyObject* self, PyObject *args, PyObject *kwargs)
total_read += single_read;
}
- if ( total_read != (gsize)PYGLIB_PyBytes_Size(ret_obj) ) {
- if (PYGLIB_PyBytes_Resize(&ret_obj, total_read) == -1)
+ if ( total_read != (gsize)PyBytes_Size (ret_obj) ) {
+ if (_PyBytes_Resize (&ret_obj, total_read) == -1)
goto failure;
}
@@ -2089,7 +2088,7 @@ pyg_add_emission_hook(PyGObject *self, PyObject *args)
if (!g_signal_parse_name(name, gtype, &sigid, &detail, TRUE)) {
repr = PyObject_Repr((PyObject*)self);
PyErr_Format(PyExc_TypeError, "%s: unknown signal name: %s",
- PYGLIB_PyUnicode_AsString(repr),
+ PyUnicode_AsUTF8 (repr),
name);
Py_DECREF(repr);
return NULL;
@@ -2492,9 +2491,30 @@ pygi_register_version_tuples(PyObject *d)
return 0;
}
-PYGLIB_MODULE_START(_gi, "_gi")
-{
+static struct PyModuleDef __gimodule = {
+ PyModuleDef_HEAD_INIT,
+ "_gi",
+ NULL,
+ -1,
+ _gi_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+#ifdef __GNUC__
+#define PYGI_MODINIT_FUNC __attribute__((visibility("default"))) PyMODINIT_FUNC
+#else
+#define PYGI_MODINIT_FUNC PyMODINIT_FUNC
+#endif
+
+PYGI_MODINIT_FUNC PyInit__gi(void);
+
+PYGI_MODINIT_FUNC PyInit__gi(void) {
+ PyObject *module;
PyObject *api;
+ module = PyModule_Create(&__gimodule);
PyObject *module_dict = PyModule_GetDict (module);
/* Always enable Python threads since we cannot predict which GI repositories
@@ -2507,57 +2527,57 @@ PYGLIB_MODULE_START(_gi, "_gi")
PyModule_AddStringConstant(module, "__package__", "gi._gi");
if (pygi_foreign_init () < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_error_register_types (module) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_repository_register_types (module) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_info_register_types (module) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_type_register_types (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_pointer_register_types (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_struct_register_types (module) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_gboxed_register_types (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_boxed_register_types (module) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_ccallback_register_types (module) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_resulttuple_register_types (module) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_spawn_register_types (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_option_context_register_types (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_option_group_register_types (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_register_api (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_register_constants (module) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_register_version_tuples (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_register_warnings (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pyi_object_register_types (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_interface_register_types (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_paramspec_register_types (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_enum_register_types (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
if (pygi_flags_register_types (module_dict) < 0)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
PyGIWarning = PyErr_NewException ("gi.PyGIWarning", PyExc_Warning, NULL);
if (PyGIWarning == NULL)
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
PyGIDeprecationWarning = PyErr_NewException("gi.PyGIDeprecationWarning",
PyExc_DeprecationWarning, NULL);
@@ -2575,8 +2595,9 @@ PYGLIB_MODULE_START(_gi, "_gi")
api = PyCapsule_New ( (void *) &CAPI, "gi._API", NULL);
if (api == NULL) {
- return PYGLIB_MODULE_ERROR_RETURN;
+ return NULL;
}
PyModule_AddObject (module, "_API", api);
-}
-PYGLIB_MODULE_END
+
+ return module;
+} \ No newline at end of file