Navigation



Ignore:
Timestamp:
Dec 9, 2010, 5:14:24 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Finally got the proxy aka shadow class to work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/dbg_interactive/dbg_interactive.c

    r621 r624  
    3838
    3939/* wrapper generated by SWIG */
    40 extern void init_diwrap(void);
     40#if PY_VERSION_HEX >= 0x03000000
     41        extern void PyInit__fDpy(void);
     42        #define WRAPPER_INIT    PyInit__fDpy()
     43#else /* PY_VERSION_HEX */
     44        extern void init_fDpy(void);
     45        #define WRAPPER_INIT    init_fDpy()
     46#endif /* PY_VERSION_HEX */
     47       
     48/* The string created in the shadow proxy C string file */
     49extern unsigned char fDpy_py[];
     50extern unsigned int fDpy_py_len;
    4151
    4252/* Run an interactive interpreter in a separate thread */
     
    6373static int di_main(char * conffile)
    6474{
     75        char * shadow_hlp = NULL;
     76        int mustfree = 0;
    6577        TRACE_ENTRY("%p", conffile);
    6678       
    6779        Py_Initialize();
    6880       
    69 #if PY_VERSION_HEX >= 0x03000000
    70         PyInit__diwrap();
    71 #else /* PY_VERSION_HEX */
    72         init_diwrap();
    73 #endif /* PY_VERSION_HEX */
     81        WRAPPER_INIT;
    7482       
    75         /* In future version, it might be better to use the diwrap.py file generated by SWIG here to get the proxy classes definitions */
    76         PyRun_SimpleString("from _diwrap import *\n");
     83        /* Small hack to avoid duplicating the string, we replace the last char by a \0.
     84          It works if the python file is terminated with several \n */
     85        if (   (fDpy_py[fDpy_py_len - 2] == '\n')
     86            && (fDpy_py[fDpy_py_len - 1] == '\n')) {
     87                fDpy_py[fDpy_py_len - 1] = '\0';
     88                shadow_hlp = (char *)&fDpy_py[0];
     89        } else {
     90                CHECK_MALLOC(shadow_hlp = malloc(fDpy_py_len + 1));
     91                memcpy(shadow_hlp, fDpy_py, fDpy_py_len);
     92                shadow_hlp[fDpy_py_len] = '\0';
     93                mustfree=1;
     94        }
     95       
     96        PyRun_SimpleString("__file__ = \"\"\n");
     97        PyRun_SimpleString(shadow_hlp);
     98       
     99        if (mustfree)
     100                free(shadow_hlp);
     101               
     102       
    77103        if (TRACE_BOOL(INFO)) {
    78104                PyRun_SimpleString("print \"[dbg_interactive] \",FD_PROJECT_NAME,FD_PROJECT_VERSION_MAJOR,FD_PROJECT_VERSION_MINOR,FD_PROJECT_VERSION_REV\n");
Note: See TracChangeset for help on using the changeset viewer.