summaryrefslogtreecommitdiff
path: root/giscanner/giscannermodule.c
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2014-04-28 16:21:35 -0700
committerColin Walters <walters@verbum.org>2015-09-29 23:12:58 -0400
commitd59b3827d2bb62c1ed4db8030ed9e8e753b7f52d (patch)
tree2ed3614ba3b281e4fd253d9e56897f49c5a9b3bf /giscanner/giscannermodule.c
parent750060dc0211cfb5786ba39da7283e5885eac7ad (diff)
downloadgobject-introspection-d59b3827d2bb62c1ed4db8030ed9e8e753b7f52d.tar.gz
giscanner: Use unicode literals in all Python files
Add unicode_literals future import which turns any string literal into a unicode string. Return unicode strings from the Python C extension module. Force writing of annotations (g-ir-annotation-tool) to output utf8 encoded data to stdout. This is an initial pass at following the "unicode sandwich" model of programming (http://nedbatchelder.com/text/unipain.html) needed for supporting Python 3. https://bugzilla.gnome.org/show_bug.cgi?id=679438
Diffstat (limited to 'giscanner/giscannermodule.c')
-rw-r--r--giscanner/giscannermodule.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c
index b9512275..f6945da3 100644
--- a/giscanner/giscannermodule.c
+++ b/giscanner/giscannermodule.c
@@ -141,7 +141,7 @@ symbol_get_ident (PyGISourceSymbol *self,
return Py_None;
}
- return PyString_FromString (self->symbol->ident);
+ return PyUnicode_FromString (self->symbol->ident);
}
static PyObject *
@@ -189,7 +189,7 @@ symbol_get_const_string (PyGISourceSymbol *self,
return Py_None;
}
- return PyString_FromString (self->symbol->const_string);
+ return PyUnicode_FromString (self->symbol->const_string);
}
static PyObject *
@@ -215,7 +215,7 @@ symbol_get_source_filename (PyGISourceSymbol *self,
return Py_None;
}
- return PyString_FromString (self->symbol->source_filename);
+ return PyUnicode_FromString (self->symbol->source_filename);
}
static const PyGetSetDef _PyGISourceSymbol_getsets[] = {
@@ -296,7 +296,7 @@ type_get_name (PyGISourceType *self,
return Py_None;
}
- return PyString_FromString (self->type->name);
+ return PyUnicode_FromString (self->type->name);
}
static PyObject *
@@ -593,10 +593,35 @@ pygi_source_scanner_get_comments (PyGISourceScanner *self)
for (l = comments; l; l = l->next)
{
GISourceComment *comment = l->data;
- PyObject *item = Py_BuildValue ("(ssi)", comment->comment,
- comment->filename,
- comment->line);
+ PyObject *comment_obj;
+ PyObject *filename_obj;
+ PyObject *item;
+
+ if (comment->comment)
+ {
+ comment_obj = PyUnicode_FromString (comment->comment);
+ }
+ else
+ {
+ Py_INCREF (Py_None);
+ comment_obj = Py_None;
+ }
+
+ if (comment->filename)
+ {
+ filename_obj = PyUnicode_FromString (comment->filename);
+ }
+ else
+ {
+ Py_INCREF (Py_None);
+ filename_obj = Py_None;
+ }
+
+ item = Py_BuildValue ("(OOi)", comment_obj, filename_obj, comment->line);
PyList_SetItem (list, i++, item);
+
+ Py_DECREF (comment_obj);
+ Py_DECREF (filename_obj);
}
g_slist_free (comments);