瀏覽代碼

Added CFLAGS option and exception on dlsym crash.

Sander Mathijs van Veen 14 年之前
父節點
當前提交
016568a0bd
共有 3 個文件被更改,包括 16 次插入2 次删除
  1. 6 0
      src/c/bisondynlib-linux.c
  2. 7 2
      src/pyrex/bison_.pyx
  3. 3 0
      src/python/bison.py

+ 6 - 0
src/c/bisondynlib-linux.c

@@ -47,6 +47,12 @@ PyObject *bisondynlib_run(void *handle, PyObject *parser, void *cb, void *in, in
     //printf("bisondynlib_run: looking up parser\n");
     pparser = bisondynlib_lookup_parser(handle);
     //printf("bisondynlib_run: calling parser, py_input=0x%lx\n", in);
+    if (!pparser) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "bisondynlib_lookup_parser() returned NULL");
+        return NULL;
+    }
+
     (*pparser)(parser, cb, in, debug);
     //printf("bisondynlib_run: back from parser\n");
     //return result;

+ 7 - 2
src/pyrex/bison_.pyx

@@ -528,7 +528,9 @@ cdef class ParserEngine:
         #           extra_preargs=['/DWIN32', '/G4', '/Gs', '/Oit', '/MT', '/nologo', '/W3', '/WX', '/Id:\python23\include'])
     
         # link 'em into a shared lib
-        objs = ccompiler.compile([parser.bisonCFile1, parser.flexCFile1])
+        objs = ccompiler.compile([parser.bisonCFile1, parser.flexCFile1],
+                                 extra_preargs=parser.cflags_pre,
+                                 extra_postargs=parser.cflags_post)
         libFileName = parser.bisonEngineLibName+imp.get_suffixes()[0][0]
         if os.path.isfile(libFileName+".bak"):
             try:
@@ -551,7 +553,10 @@ cdef class ParserEngine:
                          'bisonCFile1', 'bisonHFile1', 'flexFile',
                          'flexCFile', 'flexCFile1',
                          ] + objs:
-                fname = getattr(parser, name, None)
+                if hasattr(parser, name):
+                    fname = getattr(parser, name)
+                else:
+                    fname = None
                 #print "want to delete %s" % fname
                 if fname and os.path.isfile(fname):
                     hitlist.append(fname)

+ 3 - 0
src/python/bison.py

@@ -241,6 +241,9 @@ class BisonParser(object):
     flexCFile = "lex.yy.c"
     
     flexCFile1 = "tmp.lex.c" # c output file from lex gets renamed to this
+
+    cflags_pre = ['-fPIC']  # = CFLAGS added before all arguments.
+    cflags_post = ['-O3','-g']  # = CFLAGS added after all arguments.
     
     verbose = 0