2013-02-11  Jin-woo Ye <jojelino@gmail.com>

	* Makefile-giscanner.am: Add explicit dependency to PYTHON_LIBS for {lib,_}giscanner_la
    * giscanner/annotationparser.py: Split lines correctly when the parser encountered \r preceeded by \n
    * giscanner/gdumpparser.py (_pair_boxed_type): Handle typedef'ed alias.
    * giscanner/girparser.py (_parse_boxed): Handle function node in Boxed type.
    * giscanner/giscannermodule.c (GISourceScanner): Increase # of method.
    (pygi_source_scanner_get_ignored_filenames): Define.
    (_PyGISourceScanner_methods): Insert method entry.
    * giscanner/scannerlexer.l: Recognize __{inline,restrict}__.
    * giscanner/sourcescanner.h (_GISourceScanner): Add ignored_filaname_table.
    * giscanner/sourcescanner.c (gi_source_scanner_new): Use it.
    (gi_source_scanner_free): Ditto.
    (gi_source_scanner_add_symbol): Insert the ignored filename to table.
    * giscanner/sourcescanner.py (SourceScanner.get_ignored_filenames): Define.
    * giscanner/transformer.py (_split_c_string_for_namespace_matches): Disallow zero-length name.
    * giscanner/utils.py (_libtool_pat): Accept dlname with relative path.
    (_extract_dlname_field): Raise exception when dlname not found.
    * m4/python.m4: Trim [\r\n].
diff --git a/Makefile-giscanner.am b/Makefile-giscanner.am
index c43b5bd..7878a5c 100644
--- a/Makefile-giscanner.am
+++ b/Makefile-giscanner.am
@@ -20,7 +20,7 @@ libgiscanner_la_SOURCES = \
 	giscanner/scannerparser.y				\
 	giscanner/grealpath.h
 libgiscanner_la_CPPFLAGS = -I$(top_srcdir)/girepository -I$(top_srcdir)/giscanner
-libgiscanner_la_LIBADD = $(GOBJECT_LIBS) $(GIO_LIBS)
+libgiscanner_la_LIBADD = $(GOBJECT_LIBS) $(GIO_LIBS) $(PYTHON_LIBS)
 libgiscanner_la_CFLAGS = $(GOBJECT_CFLAGS) $(GIO_CFLAGS)
 
 # Python module
@@ -77,7 +77,7 @@ _giscanner_la_CFLAGS = \
 	$(PYTHON_INCLUDES) \
 	$(GOBJECT_CFLAGS) \
 	-I$(top_srcdir)/giscanner
-_giscanner_la_LIBADD = libgiscanner.la $(GOBJECT_LIBS)
+_giscanner_la_LIBADD = libgiscanner.la $(GOBJECT_LIBS) $(PYTHON_LIBS)
 
 _giscanner_la_LDFLAGS = \
 	-module -avoid-version -export-symbols-regex init_giscanner
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index 9c0ce5a..f6582a9 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -28,7 +28,7 @@ import re
 from . import message
 from .odict import odict
 
-
+LINESEP=re.compile(r'(?:\n|\r\n)')
 # GTK-Doc comment block parts
 PART_IDENTIFIER = 'identifier'
 PART_PARAMETERS = 'parameters'
@@ -397,7 +397,7 @@ class DocBlock(object):
             lines.append(param.to_gtk_doc_param())
         if self.comment:
             lines.append('')
-            for l in self.comment.split('\n'):
+            for l in LINESEP.split(self.comment.split):
                 lines.append(l)
         if self.tags:
             lines.append('')
@@ -803,7 +803,7 @@ class AnnotationParser(object):
         # Assign line numbers to each line of the comment block,
         # which will later be used as the offset to calculate the
         # real line number in the source file
-        comment_lines = list(enumerate(comment.split('\n')))
+        comment_lines = list(enumerate(LINESEP.split(comment)))
 
         # Check for the start the comment block.
         if COMMENT_START_RE.match(comment_lines[0][1]):
diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
index c0b13f4..df8bfd8 100644
--- a/giscanner/gdumpparser.py
+++ b/giscanner/gdumpparser.py
@@ -512,6 +512,10 @@ different --identifier-prefix.""" % (xmlnode.attrib['name'], self._namespace.ide
         except TransformerException, e:
             message.fatal(e)
         pair_node = self._namespace.get(name)
+        while isinstance(pair_node, ast.Alias):
+            pair_node=pair_node.target
+            assert pair_node
+            pair_node=self._namespace.get(pair_node.unresolved_string)
         if not pair_node:
             # Keep the "bare" boxed instance
             self._namespace.append(boxed)
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index 479eb54..80a0440 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -500,6 +500,9 @@ class GIRParser(object):
         for callback in self._find_children(node, _corens('callback')):
             obj.fields.append(
                 self._parse_function_common(callback, ast.Callback, obj))
+        for func_node in self._find_children(node, _corens('function')):
+            func = self._parse_function_common(func_node, ast.Function, obj)
+            obj.static_methods.append(func)
         self._namespace.append(obj)
 
     def _parse_field(self, node, parent):
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c
index 0ece7f7..9b74a53 100644
--- a/giscanner/giscannermodule.c
+++ b/giscanner/giscannermodule.c
@@ -88,7 +88,7 @@ typedef struct {
 
 NEW_CLASS (PyGISourceSymbol, "SourceSymbol", GISourceSymbol, 10);
 NEW_CLASS (PyGISourceType, "SourceType", GISourceType, 9);
-NEW_CLASS (PyGISourceScanner, "SourceScanner", GISourceScanner, 8);
+NEW_CLASS (PyGISourceScanner, "SourceScanner", GISourceScanner, 9);
 
 
 /* Symbol */
@@ -564,6 +564,26 @@ pygi_source_scanner_get_symbols (PyGISourceScanner *self)
 }
 
 static PyObject *
+pygi_source_scanner_get_ignored_filenames (PyGISourceScanner *self)
+{
+  GList *l;
+  GList *symbols;
+  PyObject *list;
+  int i = 0;
+  symbols = g_hash_table_get_keys(self->scanner->ignored_filename_table);
+  list = PyList_New (g_list_length(symbols));
+
+  for (l = symbols; l; l = l->next)
+    {
+      PyObject *item = PyString_FromString(l->data);
+      PyList_SetItem (list, i++, item);
+    }
+
+  Py_INCREF (list);
+  return list;
+}
+
+static PyObject *
 pygi_source_scanner_get_comments (PyGISourceScanner *self)
 {
   GSList *l, *comments;
@@ -588,6 +608,7 @@ pygi_source_scanner_get_comments (PyGISourceScanner *self)
 
 static const PyMethodDef _PyGISourceScanner_methods[] = {
   { "get_comments", (PyCFunction) pygi_source_scanner_get_comments, METH_NOARGS },
+  { "get_ignored_filenames", (PyCFunction) pygi_source_scanner_get_ignored_filenames, METH_NOARGS },
   { "get_symbols", (PyCFunction) pygi_source_scanner_get_symbols, METH_NOARGS },
   { "append_filename", (PyCFunction) pygi_source_scanner_append_filename, METH_VARARGS },
   { "parse_file", (PyCFunction) pygi_source_scanner_parse_file, METH_VARARGS },
diff --git a/giscanner/scannerlexer.l b/giscanner/scannerlexer.l
index a783ec0..ccace2e 100644
--- a/giscanner/scannerlexer.l
+++ b/giscanner/scannerlexer.l
@@ -140,10 +140,10 @@ stringtext				([^\\\"])|(\\.)
 "__attribute" 		                { if (!parse_ignored_macro()) REJECT; }
 "__const"                               { return CONST; }
 "__extension__"                         { return EXTENSION; }
-"__inline"				{ return INLINE; }
+"__inline"(?:__)?				{ return INLINE; }
 "__nonnull" 			        { if (!parse_ignored_macro()) REJECT; }
 "__signed__"				{ return SIGNED; }
-"__restrict"				{ return RESTRICT; }
+"__restrict"(?:__)?				{ return RESTRICT; }
 "__typeof"				{ if (!parse_ignored_macro()) REJECT; }
 "_Bool"					{ return BOOL; }
 
diff --git a/giscanner/sourcescanner.c b/giscanner/sourcescanner.c
index 1b775b4..67ba542 100644
--- a/giscanner/sourcescanner.c
+++ b/giscanner/sourcescanner.c
@@ -189,6 +189,8 @@ gi_source_scanner_new (void)
   scanner = g_slice_new0 (GISourceScanner);
   scanner->typedef_table = g_hash_table_new_full (g_str_hash, g_str_equal,
 						  g_free, NULL);
+  scanner->ignored_filename_table = g_hash_table_new_full (g_str_hash, g_str_equal,
+                          g_free, NULL);
   scanner->struct_or_union_or_enum_table =
     g_hash_table_new_full (g_str_hash, g_str_equal,
 			   g_free, (GDestroyNotify)gi_source_symbol_unref);
@@ -208,7 +210,7 @@ void
 gi_source_scanner_free (GISourceScanner *scanner)
 {
   g_free (scanner->current_filename);
-
+  g_hash_table_destroy (scanner->ignored_filename_table);
   g_hash_table_destroy (scanner->typedef_table);
   g_hash_table_destroy (scanner->struct_or_union_or_enum_table);
 
@@ -260,7 +262,11 @@ gi_source_scanner_add_symbol (GISourceScanner  *scanner,
 	}
       g_object_unref (file);
     }
-
+  if (!found_filename && !g_hash_table_contains(scanner->ignored_filename_table,scanner->current_filename)){
+      g_hash_table_insert (scanner->ignored_filename_table,
+                     g_strdup (scanner->current_filename),
+                     GINT_TO_POINTER (TRUE));
+  }
   if (found_filename || scanner->macro_scan)
     scanner->symbols = g_slist_prepend (scanner->symbols,
 					gi_source_symbol_ref (symbol));
diff --git a/giscanner/sourcescanner.h b/giscanner/sourcescanner.h
index a2834ca..c9db918 100644
--- a/giscanner/sourcescanner.h
+++ b/giscanner/sourcescanner.h
@@ -114,6 +114,7 @@ struct _GISourceScanner
   GSList *comments; /* _GIComment */
   GHashTable *typedef_table;
   GHashTable *struct_or_union_or_enum_table;
+  GHashTable *ignored_filename_table;
 };
 
 struct _GISourceSymbol
diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py
index 9eb4ab4..bd4a283 100644
--- a/giscanner/sourcescanner.py
+++ b/giscanner/sourcescanner.py
@@ -260,7 +261,8 @@ class SourceScanner(object):
 
     def get_comments(self):
         return self._scanner.get_comments()
-
+    def get_ignored_filenames(self):
+        return self._scanner.get_ignored_filenames()
     def dump(self):
         print '-'*30
         for symbol in self._scanner.get_symbols():
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 6736799..7548525 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -246,7 +246,7 @@ currently-scanned namespace is first."""
                 for prefix in prefixes:
                     if (not is_identifier) and (not prefix.endswith('_')):
                         prefix = prefix + '_'
-                    if name.startswith(prefix):
+                    if name.startswith(prefix) and not (len(prefix)>=len(name)):
                         matches.append((ns, name[len(prefix):], len(prefix)))
                         break
             else:
diff --git a/giscanner/utils.py b/giscanner/utils.py
index 9adf6d9..03d9612 100644
--- a/giscanner/utils.py
+++ b/giscanner/utils.py
@@ -69,8 +69,8 @@ def to_underscores_noprefix(name):
     name = _upperstr_pat2.sub(r'\1_\2', name)
     return name
 
-_libtool_pat = re.compile("dlname='([A-z0-9\.\-\+]+)'\n")
-
+_libtool_pat = re.compile("dlname\s*=\s*'(?:[^']+/)?([^']+)'\n")
+
 def _extract_dlname_field(la_file):
     f = open(la_file)
     data = f.read()
@@ -79,6 +80,7 @@ def _extract_dlname_field(la_file):
     if m:
         return m.groups()[0]
     else:
+        raise Exception("could not found dlname from %s"%(la_file))
         return None
 
 # Returns the name that we would pass to dlopen() the library
diff --git a/m4/python.m4 b/m4/python.m4
index cdd586c..3a5e0e3 100644
--- a/m4/python.m4
+++ b/m4/python.m4
@@ -43,7 +43,7 @@ AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
 [AC_REQUIRE([AM_PATH_PYTHON])
 AC_MSG_CHECKING(for headers required to compile python extensions)
 dnl deduce PYTHON_INCLUDES
-PYTHON_INCLUDES=`$PYTHON-config --includes`
+PYTHON_INCLUDES=`$PYTHON-config --includes|tr -d "\r\n"`
 AC_SUBST(PYTHON_INCLUDES)
 dnl check if the headers exist:
 save_CPPFLAGS="$CPPFLAGS"
@@ -64,7 +64,7 @@ AC_DEFUN([AM_CHECK_PYTHON_LIBS],
 AC_MSG_CHECKING(for libraries required to link against libpython)
 dnl deduce PYTHON_LIBS
 if test "x$PYTHON_LIBS" == x; then
-	PYTHON_LIBS=`$PYTHON-config --ldflags --libs`
+	PYTHON_LIBS=`$PYTHON-config --ldflags --libs|tr -d "\r\n"`
 fi
 AC_SUBST(PYTHON_LIBS)
 dnl check if libpython exist:
