diff options
author | Dieter Verfaillie <dieterv@optionexplicit.be> | 2013-10-17 17:43:48 +0200 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-10-17 15:04:50 -0400 |
commit | ebb80508d6959a0c94351e841c2cab6220602e62 (patch) | |
tree | da08996f1ce0f1904a6bd64eabb7d6665b0364bc /giscanner | |
parent | 65a0fa4c4e005047af7ec029c733bed4bd80292f (diff) | |
download | gobject-introspection-ebb80508d6959a0c94351e841c2cab6220602e62.tar.gz |
giscanner: remove g_realpath
giscannermodule expects file names to be canonicalized and
symlinks to be resolved (most likely to support users of
symlinked /usr/local). Instead of computing absolute and real
paths all over the place, we can do this once on entry
in SourceScanner().parse_files() and SourceScanner().parse_macros()
and clean the rest a bit...
https://bugzilla.gnome.org/show_bug.cgi?id=710320
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/giscannermodule.c | 5 | ||||
-rw-r--r-- | giscanner/grealpath.h | 64 | ||||
-rw-r--r-- | giscanner/scannerlexer.l | 11 | ||||
-rwxr-xr-x | giscanner/scannermain.py | 4 | ||||
-rw-r--r-- | giscanner/sourcescanner.py | 8 |
5 files changed, 10 insertions, 82 deletions
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c index 2f4c0e8a..2f413a02 100644 --- a/giscanner/giscannermodule.c +++ b/giscanner/giscannermodule.c @@ -28,7 +28,6 @@ #ifdef G_OS_WIN32 #define USE_WINDOWS #endif -#include "grealpath.h" #ifdef _WIN32 #include <fcntl.h> @@ -361,7 +360,7 @@ pygi_source_scanner_append_filename (PyGISourceScanner *self, if (!PyArg_ParseTuple (args, "s:SourceScanner.append_filename", &filename)) return NULL; - file = g_file_new_for_path (g_realpath (filename)); + file = g_file_new_for_path (filename); g_hash_table_add (self->scanner->files, file); Py_INCREF (Py_None); @@ -517,7 +516,7 @@ pygi_source_scanner_lex_filename (PyGISourceScanner *self, if (!PyArg_ParseTuple (args, "s:SourceScanner.lex_filename", &filename)) return NULL; - self->scanner->current_file = g_file_new_for_path ( g_realpath (filename)); + self->scanner->current_file = g_file_new_for_path (filename); if (!gi_source_scanner_lex_filename (self->scanner, filename)) { g_print ("Something went wrong during lexing.\n"); diff --git a/giscanner/grealpath.h b/giscanner/grealpath.h deleted file mode 100644 index 176f57ec..00000000 --- a/giscanner/grealpath.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef __G_REALPATH_H__ -#define __G_REALPATH_H__ - -#include <stdlib.h> -#ifdef USE_WINDOWS -#include <windows.h> -#endif - -/** - * g_realpath: - * - * this should be a) filled in for win32 and b) put in glib... - */ - -static inline gchar* -g_realpath (const char *path) -{ -#ifndef _WIN32 -#ifndef PATH_MAX -#define PATH_MAX 4096 -#endif - char buffer [PATH_MAX]; - if (realpath(path, buffer)) - return g_strdup(buffer); - else - return NULL; -#else - /* We don't want to include <windows.h> as it clashes horribly - * with token names from scannerparser.h. So just declare - * GetFullPathNameA() here unless we already defined it, like - * in giscanner.c. - */ -#ifndef USE_WINDOWS - extern __stdcall GetFullPathNameA(const char*, int, char*, char**); -#endif - char *buffer; - char dummy; - int rc, len; - - rc = GetFullPathNameA(path, 1, &dummy, NULL); - - if (rc == 0) - { - /* Weird failure, so just return the input path as such */ - return g_strdup(path); - } - - len = rc + 1; - buffer = g_malloc(len); - - rc = GetFullPathNameA(path, len, buffer, NULL); - - if (rc == 0 || rc > len) - { - /* Weird failure again */ - g_free(buffer); - return g_strdup(path); - } - - return buffer; -#endif -} - -#endif diff --git a/giscanner/scannerlexer.l b/giscanner/scannerlexer.l index 91f50cb9..f30191db 100644 --- a/giscanner/scannerlexer.l +++ b/giscanner/scannerlexer.l @@ -35,7 +35,6 @@ #include <glib.h> #include "sourcescanner.h" #include "scannerparser.h" -#include "grealpath.h" int lineno; char linebuf[2000]; @@ -316,17 +315,11 @@ process_linemarks (GISourceScanner *scanner) { char escaped_filename[1025]; char *filename; - char *real; sscanf(yytext, "# %d \"%1024[^\"]\"", &lineno, escaped_filename); filename = g_strcompress (escaped_filename); - real = g_realpath (filename); - if (real) { - g_object_unref (scanner->current_file); - scanner->current_file = g_file_new_for_path (real); - } else { - g_free (real); - } + g_object_unref (scanner->current_file); + scanner->current_file = g_file_new_for_path (filename); g_free (filename); } diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index ab8f5bbf..6ae2dede 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -267,7 +267,7 @@ def extract_filenames(args): _error('%s: no such a file or directory' % (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)) + filenames.append(arg) return filenames @@ -289,7 +289,7 @@ def extract_filelist(options): _error('%s: Invalid filelist entry-no such file or directory' % (line, )) # Make absolute, because we do comparisons inside scannerparser.c # against the absolute path that cpp will give us - filenames.append(os.path.abspath(filename)) + filenames.append(filename) return filenames diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py index d5c43926..3444445e 100644 --- a/giscanner/sourcescanner.py +++ b/giscanner/sourcescanner.py @@ -237,14 +237,14 @@ class SourceScanner(object): def parse_files(self, filenames): for filename in filenames: - filename = os.path.abspath(filename) + # self._scanner expects file names to be canonicalized and symlinks to be resolved + filename = os.path.realpath(filename) self._scanner.append_filename(filename) self._filenames.append(filename) headers = [] for filename in filenames: if os.path.splitext(filename)[1] in SOURCE_EXTS: - filename = os.path.abspath(filename) self._scanner.lex_filename(filename) else: headers.append(filename) @@ -253,7 +253,8 @@ class SourceScanner(object): def parse_macros(self, filenames): self._scanner.set_macro_scan(True) - self._scanner.parse_macros(filenames) + # self._scanner expects file names to be canonicalized and symlinks to be resolved + self._scanner.parse_macros([os.path.realpath(f) for f in filenames]) self._scanner.set_macro_scan(False) def get_symbols(self): @@ -298,7 +299,6 @@ class SourceScanner(object): for undef in undefs: proc.stdin.write('#undef %s\n' % (undef, )) for filename in filenames: - filename = os.path.abspath(filename) proc.stdin.write('#include <%s>\n' % (filename, )) proc.stdin.close() |