File: class/Extras/Code/Swig/output.txt

[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ make -f makefile.hellolib-swig force
rm -f *.o *.so core hellolib_wrap.c hellolib_wrap.doc

[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ ls
Shadow  hellolib.i  makefile.hellolib-swig  myswig  output  setup-swig.csh


[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ make -f makefile.hellolib-swig
./myswig -python -I../HelloLib hellolib.i
Generating wrappers for Python
gcc hellolib_wrap.c -c -g -I../HelloLib -I/home/mark/python1.5.2-ddjcd/Python-1.5.2/Include -I/home/mark/python1.5.2-ddjcd/Python-1.5.2
ld -shared hellolib_wrap.o ../HelloLib/hellolib.o -o hellowrap.so


[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ ls
Shadow           hellolib_wrap.doc  makefile.hellolib-swig  setup-swig.csh
hellolib.i       hellolib_wrap.o    myswig
hellolib_wrap.c  hellowrap.so       output


[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ make -f makefile.hellolib-swig clean
rm -f *.o *.so core

[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ ls
Shadow      hellolib_wrap.c    makefile.hellolib-swig  output
hellolib.i  hellolib_wrap.doc  myswig                  setup-swig.csh



[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ make -f makefile.hellolib-swig
gcc hellolib_wrap.c -c -g -I../HelloLib -I/home/mark/python1.5.2-ddjcd/Python-1.5.2/Include -I/home/mark/python1.5.2-ddjcd/Python-1.5.2
ld -shared hellolib_wrap.o ../HelloLib/hellolib.o -o hellowrap.so

------------------------------------------------------------------------------

[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ python
Python 1.5.2 (#16, Oct 19 1999, 15:47:45)  [GCC egcs-2.91.66 19990314/Linux (egcs- on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>>
>>> import hellowrap
>>> hellowrap.__file__
'./hellowrap.so'
>>> hellowrap.message('swig world')
'Hello, swig world'
>>>
>>> hellowrap.message()
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: message requires exactly 1 argument; 0 given
>>>
>>> hellowrap
<module 'hellowrap' from './hellowrap.so'>
>>> dir(hellowrap)
['__doc__', '__file__', '__name__', 'message']
>>> hellowrap.__dict__
{'__file__': './hellowrap.so', '__doc__': None, 'message': <built-in function message>, '__name__': 'hellowrap'}



-------------------------------------------------------------------------------

[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ cp ../HelloLib/hellolib.* .
[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ ls
hellolib.c hellolib.h  makefile.hellolib-swig  output  setup-swig.csh


[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ source setup-swig.csh

[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ swig -module hellowrap -python hellolib.h
Generating wrappers for Python

[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ ls
hellolib.c  hellolib_wrap.c    makefile.hellolib-swig  setup-swig.csh
hellolib.h  hellolib_wrap.doc  output

[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ rm hellolib.c hellolib.h

-------------------------------------------------------------------------------

[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ swig -python hellolib.i
Generating wrappers for Python

[mark@toy ~/PP2ndEd/dev/examples/Part3/Extend/Swig]$ diff hellolib_wrap.c hellolib_wrap.c-save
555,556d554
<
< #include <hellolib.h>




/*
 * FILE : hellolib_wrap.c
 *
 * This file was automatically generated by :
 * Simplified Wrapper and Interface Generator (SWIG)
 * Version 1.1 (Patch 5)
 *

 . . .
 boiler-plate code for handling C global var access using Python
 types with attributes, and mapping C pointers to Python strings
 . . .

#include <hellolib.h>
extern char *message(char *);
static PyObject *_wrap_message(PyObject *self, PyObject *args) {
    PyObject * _resultobj;
    char * _result;
    char * _arg0;

    self = self;
    if(!PyArg_ParseTuple(args,"s:message",&_arg0))
        return NULL;
    _result = (char *)message(_arg0);
    _resultobj = Py_BuildValue("s", _result);
    return _resultobj;
}

static PyMethodDef hellowrapMethods[] = {
         { "message", _wrap_message, 1 },
         { NULL, NULL }
};
static PyObject *SWIG_globals;
#ifdef __cplusplus
extern "C"
#endif
SWIGEXPORT(void,inithellowrap)() {
         PyObject *m, *d;
         SWIG_globals = SWIG_newvarlink();
         m = Py_InitModule("hellowrap", hellowrapMethods);
 . . .

-------------------------------------------------------------------------------



[Home page] Books Code Blog Python Author Train Find ©M.Lutz