aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/c-to-c.py2
-rw-r--r--examples/cdecl.py2
-rw-r--r--examples/explore_ast.py2
-rw-r--r--examples/func_calls.py2
-rw-r--r--examples/func_defs.py2
-rw-r--r--examples/using_cpp_libc.py2
-rw-r--r--pycparser/__init__.py21
7 files changed, 19 insertions, 14 deletions
diff --git a/examples/c-to-c.py b/examples/c-to-c.py
index acd2cd4..35e1c64 100644
--- a/examples/c-to-c.py
+++ b/examples/c-to-c.py
@@ -13,7 +13,7 @@ import sys
# This is not required if you've installed pycparser into
# your site-packages/ with setup.py
#
-sys.path.insert(0, '..')
+sys.path.extend(['.', '..'])
from pycparser import parse_file, c_parser, c_generator
diff --git a/examples/cdecl.py b/examples/cdecl.py
index 0e07272..8884591 100644
--- a/examples/cdecl.py
+++ b/examples/cdecl.py
@@ -25,7 +25,7 @@ import sys
# This is not required if you've installed pycparser into
# your site-packages/ with setup.py
#
-sys.path.insert(0, '..')
+sys.path.extend(['.', '..'])
from pycparser import c_parser, c_ast
diff --git a/examples/explore_ast.py b/examples/explore_ast.py
index 919f44e..24df79f 100644
--- a/examples/explore_ast.py
+++ b/examples/explore_ast.py
@@ -18,7 +18,7 @@ import sys
# This is not required if you've installed pycparser into
# your site-packages/ with setup.py
#
-sys.path.insert(0, '..')
+sys.path.extend(['.', '..'])
from pycparser import c_parser, c_ast
diff --git a/examples/func_calls.py b/examples/func_calls.py
index f79d47e..f8ff731 100644
--- a/examples/func_calls.py
+++ b/examples/func_calls.py
@@ -13,7 +13,7 @@ import sys
# This is not required if you've installed pycparser into
# your site-packages/ with setup.py
#
-sys.path.insert(0, '..')
+sys.path.extend(['.', '..'])
from pycparser import c_parser, c_ast, parse_file
diff --git a/examples/func_defs.py b/examples/func_defs.py
index 9522382..c42d5c0 100644
--- a/examples/func_defs.py
+++ b/examples/func_defs.py
@@ -16,7 +16,7 @@ import sys
# This is not required if you've installed pycparser into
# your site-packages/ with setup.py
#
-sys.path.insert(0, '..')
+sys.path.extend(['.', '..'])
from pycparser import c_parser, c_ast, parse_file
diff --git a/examples/using_cpp_libc.py b/examples/using_cpp_libc.py
index fa9e6a7..1c28c7a 100644
--- a/examples/using_cpp_libc.py
+++ b/examples/using_cpp_libc.py
@@ -13,7 +13,7 @@ import sys
# This is not required if you've installed pycparser into
# your site-packages/ with setup.py
#
-sys.path.insert(0, '..')
+sys.path.extend(['.', '..'])
# Portable cpp path for Windows and Linux/Unix
CPPPATH = '../utils/cpp.exe' if sys.platform == 'win32' else 'cpp'
diff --git a/pycparser/__init__.py b/pycparser/__init__.py
index 377048b..0a5c079 100644
--- a/pycparser/__init__.py
+++ b/pycparser/__init__.py
@@ -46,7 +46,7 @@ def parse_file( filename, use_cpp=False,
Errors from cpp will be printed out.
"""
- if use_cpp:
+ if use_cpp:
path_list = [cpp_path]
if isinstance(cpp_args, list):
path_list += cpp_args
@@ -54,13 +54,18 @@ def parse_file( filename, use_cpp=False,
path_list += [cpp_args]
path_list += [filename]
- # Note the use of universal_newlines to treat all newlines
- # as \n for Python's purpose
- #
- pipe = Popen( path_list,
- stdout=PIPE,
- universal_newlines=True)
- text = pipe.communicate()[0]
+ try:
+ # Note the use of universal_newlines to treat all newlines
+ # as \n for Python's purpose
+ #
+ pipe = Popen( path_list,
+ stdout=PIPE,
+ universal_newlines=True)
+ text = pipe.communicate()[0]
+ except OSError as e:
+ raise RuntimeError("Unable to invoke 'cpp'. " +
+ 'Make sure its path was passed correctly\n' +
+ ('Original error: %s' % e))
else:
text = open(filename, 'rU').read()