Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2009-02-24 04:04:35 (GMT)
committer Colin Walters <walters@verbum.org>2009-02-24 19:23:37 (GMT)
commitf3f8de20114405bae29a354d67c38a7bf0b096a2 (patch)
treeae6a6917db11c909f84771da264f7f5930154d09
parent7bd4bc6807dc829f6e8ea4db1b58a85e365b8b97 (diff)
Bug 572790 - Don't register #defines from .c files as constants
We keep track of the source filename for every symbol. This enables us to later filter symbols based on that name.
-rw-r--r--giscanner/giscannermodule.c16
-rw-r--r--giscanner/sourcescanner.c6
-rw-r--r--giscanner/sourcescanner.h1
-rw-r--r--giscanner/sourcescanner.py4
-rw-r--r--giscanner/transformer.py4
-rw-r--r--tests/scanner/foo-1.0-expected.gir3
-rw-r--r--tests/scanner/foo-1.0-expected.tgir3
-rw-r--r--tests/scanner/foo.c4
-rw-r--r--tests/scanner/foo.h4
-rwxr-xr-xtools/g-ir-scanner4
10 files changed, 45 insertions, 4 deletions
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c
index b7ac316..7d63784 100644
--- a/giscanner/giscannermodule.c
+++ b/giscanner/giscannermodule.c
@@ -151,6 +151,19 @@ symbol_get_const_string (PyGISourceSymbol *self,
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},
@@ -159,7 +172,8 @@ static const PyGetSetDef _PyGISourceSymbol_getsets[] = {
{ "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_string", (getter)symbol_get_const_string, NULL, NULL},
+ { "source_filename", (getter)symbol_get_source_filename, NULL, NULL},
{ 0 }
};
diff --git a/giscanner/sourcescanner.c b/giscanner/sourcescanner.c
index 1a2508d..79d89cd 100644
--- a/giscanner/sourcescanner.c
+++ b/giscanner/sourcescanner.c
@@ -60,6 +60,7 @@ gi_source_symbol_unref (GISourceSymbol * symbol)
if (symbol->base_type)
ctype_free (symbol->base_type);
g_free (symbol->const_string);
+ g_free (symbol->source_filename);
g_slice_free (GISourceSymbol, symbol);
}
}
@@ -245,6 +246,11 @@ gi_source_scanner_add_symbol (GISourceScanner *scanner,
if (found_filename || scanner->macro_scan)
scanner->symbols = g_slist_prepend (scanner->symbols,
gi_source_symbol_ref (symbol));
+ /* TODO: Refcounted string here or some other optimization */
+ if (found_filename && symbol->source_filename == NULL)
+ {
+ symbol->source_filename = g_strdup (scanner->current_filename);
+ }
switch (symbol->type)
{
diff --git a/giscanner/sourcescanner.h b/giscanner/sourcescanner.h
index 276b0cb..bbc4977 100644
--- a/giscanner/sourcescanner.h
+++ b/giscanner/sourcescanner.h
@@ -116,6 +116,7 @@ struct _GISourceSymbol
gboolean const_int_set;
int const_int;
char *const_string;
+ char *source_filename;
};
struct _GISourceType
diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py
index 56aac93..30e624b 100644
--- a/giscanner/sourcescanner.py
+++ b/giscanner/sourcescanner.py
@@ -179,6 +179,10 @@ class SourceSymbol(object):
if self._symbol.base_type is not None:
return SourceType(self._scanner, self._symbol.base_type)
+ @property
+ def source_filename(self):
+ return self._symbol.source_filename
+
class SourceScanner(object):
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 10a08a7..58c2fbc 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -460,6 +460,10 @@ class Transformer(object):
return return_
def _create_const(self, symbol):
+ # Don't create constants for non-public things
+ # http://bugzilla.gnome.org/show_bug.cgi?id=572790
+ if not symbol.source_filename.endswith('.h'):
+ return None
name = self.remove_prefix(symbol.ident)
if symbol.const_string is None:
type_name = 'int'
diff --git a/tests/scanner/foo-1.0-expected.gir b/tests/scanner/foo-1.0-expected.gir
index 6a1d8a4..2f82175 100644
--- a/tests/scanner/foo-1.0-expected.gir
+++ b/tests/scanner/foo-1.0-expected.gir
@@ -132,6 +132,9 @@ and/or use gtk-doc annotations. -->
</return-value>
</method>
</record>
+ <constant name="DEFINE_SHOULD_BE_EXPOSED" value="should be exposed">
+ <type name="utf8"/>
+ </constant>
<enumeration name="EnumFullname" c:type="FooEnumFullname">
<member name="one" value="1" c:identifier="FOO_ENUM_FULLNAME_ONE"/>
<member name="two" value="2" c:identifier="FOO_ENUM_FULLNAME_TWO"/>
diff --git a/tests/scanner/foo-1.0-expected.tgir b/tests/scanner/foo-1.0-expected.tgir
index 3401fe2..edf58ef 100644
--- a/tests/scanner/foo-1.0-expected.tgir
+++ b/tests/scanner/foo-1.0-expected.tgir
@@ -103,6 +103,9 @@
</return-value>
</method>
</record>
+ <constant name="DEFINE_SHOULD_BE_EXPOSED" value="should be exposed">
+ <type name="utf8"/>
+ </constant>
<enumeration name="EnumFullname">
<member name="one" value="1"/>
<member name="two" value="2"/>
diff --git a/tests/scanner/foo.c b/tests/scanner/foo.c
index 0e5beb6..0488260 100644
--- a/tests/scanner/foo.c
+++ b/tests/scanner/foo.c
@@ -1,5 +1,3 @@
-#define FOO_SUCCESS_INT 0x1138
-
#include "foo.h"
/* A hidden type not exposed publicly, similar to GUPNP's XML wrapper
@@ -524,3 +522,5 @@ void
foo_buffer_some_method (FooBuffer *buffer)
{
}
+
+#define FOO_DEFINE_SHOULD_NOT_BE_EXPOSED "should not be exposed"
diff --git a/tests/scanner/foo.h b/tests/scanner/foo.h
index dec9058..d3dd29f 100644
--- a/tests/scanner/foo.h
+++ b/tests/scanner/foo.h
@@ -4,6 +4,10 @@
#include <glib-object.h>
#include "utility.h"
+#define FOO_SUCCESS_INT 0x1138
+
+#define FOO_DEFINE_SHOULD_BE_EXPOSED "should be exposed"
+
#define FOO_TYPE_INTERFACE (foo_interface_get_type ())
#define FOO_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), FOO_TYPE_INTERFACE, FooInterface))
#define FOO_IS_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), FOO_TYPE_INTERFACE))
diff --git a/tools/g-ir-scanner b/tools/g-ir-scanner
index de20a7e..4b5b924 100755
--- a/tools/g-ir-scanner
+++ b/tools/g-ir-scanner
@@ -282,7 +282,9 @@ def main(args):
arg.endswith('.h')):
if not os.path.exists(arg):
_error('%s: no such a file or directory' % (arg, ))
- filenames.append(arg)
+ # Make absolute, because we do comparisons inside scannerparser.c
+ # against the absolute path that cpp will give us
+ filenames.append(os.path.abspath(arg))
cachestore = CacheStore()
transformer = Transformer(cachestore,