gobject-introspection r274 - in trunk: . giscanner



Author: johan
Date: Sat May 24 14:44:32 2008
New Revision: 274
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=274&view=rev

Log:
2008-05-24  Johan Dahlin  <jdahlin async com br>

    * giscanner/ast.py:
    * giscanner/girwriter.py:
    * giscanner/giscannermodule.c
    (pygi_source_scanner_append_filename),
    (pygi_source_scanner_parse_file):
    * giscanner/glibtransformer.py:
    * giscanner/sourcescanner.py:
    Revert back to using temporary files to send in headers.
    Allow Functions to be passed in as callbacks, add a couple
    of try/excepts missing features.
    We can now scan pango



Modified:
   trunk/ChangeLog
   trunk/giscanner/ast.py
   trunk/giscanner/girwriter.py
   trunk/giscanner/giscannermodule.c
   trunk/giscanner/glibtransformer.py
   trunk/giscanner/sourcescanner.py

Modified: trunk/giscanner/ast.py
==============================================================================
--- trunk/giscanner/ast.py	(original)
+++ trunk/giscanner/ast.py	Sat May 24 14:44:32 2008
@@ -211,6 +211,7 @@
             self.name, self.type, self.value)
 
 
+# FIXME: Inherit from Function
 class Callback(Node):
     def __init__(self, name, retval, parameters):
         Node.__init__(self, name)

Modified: trunk/giscanner/girwriter.py
==============================================================================
--- trunk/giscanner/girwriter.py	(original)
+++ trunk/giscanner/girwriter.py	Sat May 24 14:44:32 2008
@@ -190,6 +190,7 @@
             self._write_type(prop.type)
 
     def _write_callback(self, callback):
+        # FIXME: reuse _write_function
         attrs = [('name', callback.name)]
         with self.tagcontext('callback', attrs):
             self._write_return_type(callback.retval)
@@ -206,7 +207,8 @@
             self.write_tag('record', attrs)
 
     def _write_field(self, field):
-        if isinstance(field, Callback):
+        # FIXME: Just function
+        if isinstance(field, (Callback, Function)):
             self._write_callback(field)
             return
 

Modified: trunk/giscanner/giscannermodule.c
==============================================================================
--- trunk/giscanner/giscannermodule.c	(original)
+++ trunk/giscanner/giscannermodule.c	Sat May 24 14:44:32 2008
@@ -361,27 +361,38 @@
 }
 
 static PyObject *
+pygi_source_scanner_append_filename (PyGISourceScanner *self,
+				     PyObject          *args)
+{
+  char *filename;
+
+  if (!PyArg_ParseTuple (args, "s:SourceScanner.append_filename", &filename))
+    return NULL;
+
+  self->scanner->filenames = g_list_append (self->scanner->filenames,
+					    g_strdup (filename));
+  
+  Py_INCREF (Py_None);
+  return Py_None;
+}
+
+static PyObject *
 pygi_source_scanner_parse_file (PyGISourceScanner *self,
 				PyObject          *args)
 {
   int fd;
-  char *filename;
   FILE *fp;
   
-  if (!PyArg_ParseTuple (args, "is:SourceScanner.parse_file", &fd, &filename))
+  if (!PyArg_ParseTuple (args, "i:SourceScanner.parse_file", &fd))
     return NULL;
 
   fp = fdopen (fd, "r");
   if (!fp)
     {
-      PyErr_SetFromErrnoWithFilename (PyExc_OSError, filename);
+      PyErr_SetFromErrno (PyExc_OSError);
       return NULL;
     }
 
-  self->scanner->filenames =
-    g_list_append (self->scanner->filenames, g_strdup (filename));
-  self->scanner->current_filename = g_strdup (filename);
-
   if (!gi_source_scanner_parse_file (self->scanner, fp))
     {
       g_print ("Something went wrong during parsing.\n");
@@ -479,6 +490,7 @@
 static const PyMethodDef _PyGISourceScanner_methods[] = {
   { "get_directives", (PyCFunction) pygi_source_scanner_get_directives, METH_VARARGS },
   { "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 },
   { "lex_filename", (PyCFunction) pygi_source_scanner_lex_filename, METH_VARARGS },
   { "set_macro_scan", (PyCFunction) pygi_source_scanner_set_macro_scan, METH_VARARGS },

Modified: trunk/giscanner/glibtransformer.py
==============================================================================
--- trunk/giscanner/glibtransformer.py	(original)
+++ trunk/giscanner/glibtransformer.py	Sat May 24 14:44:32 2008
@@ -161,7 +161,11 @@
         if func.parameters:
             return False
 
-        func = getattr(self._library, symbol)
+        try:
+            func = getattr(self._library, symbol)
+        except AttributeError:
+            print 'Warning: could not find symbol: %s' % symbol
+            return False
         func.restype = cgobject.GType
         func.argtypes = []
         type_id = func()
@@ -288,7 +292,11 @@
         self._introspect_properties(node, type_id)
         self._introspect_signals(node, type_id)
         self._add_attribute(node)
-        self._remove_attribute(type_name)
+        try:
+            self._remove_attribute(type_name)
+        except KeyError:
+            print 'Warning: could not remove %s' % type_name
+            pass
         self._register_internal_type(type_name, node)
 
     def _introspect_interface(self, type_id, symbol):

Modified: trunk/giscanner/sourcescanner.py
==============================================================================
--- trunk/giscanner/sourcescanner.py	(original)
+++ trunk/giscanner/sourcescanner.py	Sat May 24 14:44:32 2008
@@ -20,6 +20,7 @@
 
 import os
 import subprocess
+import tempfile
 
 from . import _giscanner
 
@@ -151,6 +152,10 @@
                     self._cpp_options.append(opt)
 
     def parse_files(self, filenames):
+        for filename in filenames:
+            filename = os.path.abspath(filename)
+            self._scanner.append_filename(filename)
+
         headers = []
         for filename in filenames:
             if filename.endswith('.c'):
@@ -159,14 +164,12 @@
             else:
                 headers.append(filename)
 
-        for filename in headers:
-            self._parse_one(filename)
-            self._filenames.append(filename)
+        self._parse(headers)
+        self._filenames.extend(headers)
 
     def parse_macros(self):
         self._scanner.set_macro_scan(True)
-        for filename in self._filenames:
-            self._parse_one(filename)
+        self._parse(self._filenames)
         self._scanner.set_macro_scan(False)
 
     def get_symbols(self):
@@ -180,16 +183,10 @@
 
     # Private
 
-    def _parse_one(self, filename):
-        filename = os.path.abspath(filename)
-        proc = self._preprocess(filename)
-        fd = proc.stdout.fileno()
-        if proc is None:
+    def _parse(self, filenames):
+        if not filenames:
             return
-
-        self._scanner.parse_file(fd, filename)
-
-    def _preprocess(self, filename):
+        
         cpp_args = [
             'cpp',
             '-C',
@@ -198,13 +195,25 @@
             '-I.',
             ]
         cpp_args += self._cpp_options
-        proc = subprocess.Popen(
-            cpp_args,
-            bufsize=4096,
-            stdin=subprocess.PIPE,
-            stdout=subprocess.PIPE,
-            stderr=subprocess.STDOUT,
-            )
-        proc.stdin.write('#include <%s>\n' % (filename,))
+        proc = subprocess.Popen(cpp_args,
+                                stdin=subprocess.PIPE,
+                                stdout=subprocess.PIPE)
+                                
+        for filename in filenames:
+            filename = os.path.abspath(filename)
+            proc.stdin.write('#include <%s>\n' % (filename,))
         proc.stdin.close()
-        return proc
+
+        tmp = tempfile.mktemp()
+        fp = open(tmp, 'w+')
+        while True:
+            data = proc.stdout.read(4096)
+            if data is None:
+                break
+            fp.write(data)
+            if len(data) < 4096:
+                break
+        fp.seek(0, 0)
+        assert proc, 'Proc was none'
+        self._scanner.parse_file(fp.fileno())
+        os.unlink(tmp)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]