#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#include "sourcescanner.h"
#include <Python.h>
+#include "sourcescanner.h"
+#include "grealpath.h"
#ifdef _WIN32
#include <fcntl.h>
return PyInt_FromLong (self->symbol->type);
}
+static PyObject *
+symbol_get_line (PyGISourceSymbol *self,
+ void *context)
+{
+ return PyInt_FromLong (self->symbol->line);
+}
+
static PyObject *
symbol_get_ident (PyGISourceSymbol *self,
void *context)
symbol_get_const_int (PyGISourceSymbol *self,
void *context)
{
+ if (!self->symbol->const_int_set)
+ {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
return PyInt_FromLong (self->symbol->const_int);
}
+static PyObject *
+symbol_get_const_double (PyGISourceSymbol *self,
+ void *context)
+{
+ if (!self->symbol->const_double_set)
+ {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return PyFloat_FromDouble (self->symbol->const_double);
+}
+
static PyObject *
symbol_get_const_string (PyGISourceSymbol *self,
void *context)
return PyString_FromString (self->symbol->const_string);
}
+static PyObject *
+symbol_get_source_filename (PyGISourceSymbol *self,
+ void *context)
+{
+ if (!self->symbol->source_filename)
+ {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+ return PyString_FromString (self->symbol->source_filename);
+}
+
static const PyGetSetDef _PyGISourceSymbol_getsets[] = {
/* int ref_count; */
{ "type", (getter)symbol_get_type, NULL, NULL},
{ "ident", (getter)symbol_get_ident, NULL, NULL},
{ "base_type", (getter)symbol_get_base_type, NULL, NULL},
/* gboolean const_int_set; */
- { "const_int", (getter)symbol_get_const_int, NULL, NULL},
- { "const_string", (getter)symbol_get_const_string, NULL, NULL},
+ { "const_int", (getter)symbol_get_const_int, NULL, NULL},
+ /* gboolean const_double_set; */
+ { "const_double", (getter)symbol_get_const_double, NULL, NULL},
+ { "const_string", (getter)symbol_get_const_string, NULL, NULL},
+ { "source_filename", (getter)symbol_get_source_filename, NULL, NULL},
+ { "line", (getter)symbol_get_line, NULL, NULL},
{ 0 }
};
return list;
}
+static PyObject *
+type_get_is_bitfield (PyGISourceType *self,
+ void *context)
+{
+ return PyInt_FromLong (self->type->is_bitfield);
+}
+
static const PyGetSetDef _PyGISourceType_getsets[] = {
{ "type", (getter)type_get_type, NULL, NULL},
{ "storage_class_specifier", (getter)type_get_storage_class_specifier, NULL, NULL},
{ "name", (getter)type_get_name, NULL, NULL},
{ "base_type", (getter)type_get_base_type, NULL, NULL},
{ "child_list", (getter)type_get_child_list, NULL, NULL},
+ { "is_bitfield", (getter)type_get_is_bitfield, NULL, NULL},
{ 0 }
};
return NULL;
self->scanner->filenames = g_list_append (self->scanner->filenames,
- g_strdup (filename));
+ g_realpath (filename));
Py_INCREF (Py_None);
return Py_None;
return attr_length + indent + self_indent;
}
+/* Hall of shame, wasted time debugging the code below
+ * 20min - Johan 2009-02-19
+ */
static PyObject *
pygi_collect_attributes (PyObject *self,
PyObject *args)
GString *attr_value;
int len;
- if (!PyArg_ParseTuple(args, "sOisi",
- &tag_name, &attributes,
+ if (!PyArg_ParseTuple(args, "sO!isi",
+ &tag_name, &PyList_Type, &attributes,
&self_indent, &indent_char,
&indent))
return NULL;
first = TRUE;
attr_value = g_string_new ("");
-
+
for (i = 0; i < PyList_Size (attributes); ++i)
{
PyObject *tuple;
char *attr, *value, *escaped;
tuple = PyList_GetItem (attributes, i);
- g_assert(tuple != NULL);
- g_assert(PyTuple_Size(tuple) == 2);
+
+ if (!PyTuple_Check (tuple))
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "attribute item must be a tuple");
+ return NULL;
+ }
+
+ if (!PyTuple_Size (tuple) == 2)
+ {
+ PyErr_SetString(PyExc_IndexError,
+ "attribute item must be a tuple of length 2");
+ return NULL;
+ }
+
if (PyTuple_GetItem(tuple, 1) == Py_None)
continue;