| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- /*
- * Linux-specific dynamic library manipulation routines
- */
- #include "bisondynlib.h"
- #include <stdio.h>
- #include <dlfcn.h>
- void *bisondynlib_open(char *filename)
- {
- void *handle;
- dlerror();
- handle = dlopen(filename, (RTLD_NOW|RTLD_GLOBAL));
- return handle;
- }
- int bisondynlib_close(void *handle)
- {
- return dlclose(handle);
- }
- char *bisondynlib_err()
- {
- return dlerror();
- }
- char *bisondynlib_lookup_hash(void *handle)
- {
- char **hash;
- dlerror();
- hash = dlsym(handle, "rules_hash");
- /*
- printf("bisondynlib_lookup_hash: hash=%s\n", *hash);
- */
- return *hash;
- }
- PyObject *bisondynlib_run(void *handle, PyObject *parser, void *cb, void *in, int debug)
- {
- PyObject *(*pparser)(PyObject *, void *, void *, int);
- pparser = bisondynlib_lookup_parser(handle);
- if (!pparser) {
- PyErr_SetString(PyExc_RuntimeError,
- "bisondynlib_lookup_parser() returned NULL");
- return NULL;
- }
- (*pparser)(parser, cb, in, debug);
- // Do not ignore a raised exception, but pass the exception through.
- if (PyErr_Occurred())
- return NULL;
- Py_INCREF(Py_None);
- return Py_None;
- }
- /*
- * function(void *) returns a pointer to a function(PyObject *, char *) returning PyObject*
- */
- PyObject *(*bisondynlib_lookup_parser(void *handle))(PyObject *, void *, void *, int)
- {
- dlerror();
- return dlsym(handle, "do_parse");
- }
- /*
- * Runs the compiler commands which build the parser/lexer into a shared lib
- */
- /*
- int bisondynlib_build(char *libName, char *pyincdir)
- {
- char buf[1024];
- sprintf(buf, "gcc -fPIC -shared -I%s tmp.bison.c tmp.lex.c -o %s", pyincdir, libName);
- printf("Running linux build command: %s\n", buf);
- system(buf);
- return 0;
- }
- */
|