Python Extension winth C++ Problematic :(

2006-08-03 Thread Chandrashekhar kaushik
HiI have been working getting my C++ code to be used in Python ( Basically Extending )This is the problem i am facing rite now.I have a function that returns a Pointer to a class in my C++ CodeIt looks like this 
SLSocket* SLSocket::accept( SLHostInfo& client ){    socklen_t    addrlen = sizeof( struct sockaddr_in );        int new_fd = ::accept( sock_fd , ( struct sockaddr* )client.address() , &addrlen );
    if( new_fd == -1 ){        sl_set_error(string("SLSocket::accept() : ") + string( sys_errlist[ errno ] ));        return NULL;     }else{        return new SLSocket( new_fd );         }
}I have used SWIG to get the Glue code.When i call this function ( in python ) and it eventually returns ( when it gets a connection in this case ) it crashes ! I get a SEG FAULT !Is it some thing that cannot be done ?
Are C++ functions those return pointers a pain in PythonHelp :D --shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

SWIG Python Extension winth C++ Problematic

2006-08-03 Thread Chandrashekhar kaushik
someone ??On 8/4/06, Chandrashekhar kaushik <[EMAIL PROTECTED]> wrote:
HiI have been working getting my C++ code to be used in Python ( Basically Extending )This is the problem i am facing rite now.I have a function that returns a Pointer to a class in my C++ Code
It looks like this 
SLSocket* SLSocket::accept( SLHostInfo& client ){    socklen_t    addrlen = sizeof( struct sockaddr_in );        int new_fd = ::accept( sock_fd , ( struct sockaddr* )client.address() , &addrlen );

    if( new_fd == -1 ){        sl_set_error(string("SLSocket::accept() : ") + string( sys_errlist[ errno ] ));        return NULL;     }else{        return new SLSocket( new_fd );         }
}I have used SWIG to get the Glue code.When i call this function ( in python ) and it eventually returns ( when it gets a connection in this case ) it crashes ! I get a SEG FAULT !Is it some thing that cannot be done ?
Are C++ functions those return pointers a pain in PythonHelp :D --shekhar

-- --shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: SWIG Python Extension winth C++ Problematic

2006-08-04 Thread Chandrashekhar kaushik
Hi skipthanks for replying I made a small test case that fails with a similar problem This is how it looks 1. Two simple classes A and B , each holds an integer.2. A has a function getB() that returns pointer to B.
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\#ifndef __AB_H__#define __AB_H__class B{   public: int b; B( int num = 0 ){b = num; } ~B(){}};
class A{   public: int a; A( int a = 0 ){this->a = a; } ~A(){} B* getB(){   B* temp = new B(a);   return  temp; }};#endif __AB_H__
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\The swig file is as follows%module testcase%{#include "AB.h"%}%include "AB.h"/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
Compilation commandsswig-1.3 -c++ -python -o swig.cc swig.ig++ -c -fPIC swig.cc -o swig.o -I /usr/local/include/python2.1/g++ -shared swig.o -o _testcase.so/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
Python Filefrom testcase import *a = A() # works fineb = B() # works finec = a.getB() # crashes ( Segmentation Fault )/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\See if you can makeout something out of that 
--shekharOn 8/4/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> I have been working getting my C++ code to be used in Python (>> Basically Extending ) This is the problem i am facing rite now.
>>>> I have a function that returns a Pointer to a class in my C++ Code>>>> It looks like this...>> I have used SWIG to get the Glue code.>>
>> When i call this function ( in python ) and it eventually returns (>> when it gets a connection in this case ) it crashes ! I get a SEG>> FAULT !>>>> Is it some thing that cannot be done ?
I'm certainly no SWIG expert, however:1. Is your SLSocket class wrapped with SWIG?  Do you maybe need a   typemap?  Can you explicitly create one from Python?  If so, does   that work?
2. What does your SWIG .i file look like?3. Finally, have you tried asking on the SWIG mailing list   ([EMAIL PROTECTED])?  There are probably many more SWIG
   experts there than here.Skip-- --shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

to py or not to py ?

2006-06-27 Thread Chandrashekhar kaushik
HI all I have the following prob.I am to write a parallel vis application .I wud have by default used C++ for the same but somehow thought if py cud help me ..It does as in many things that i would otherwise have written down
already exists ... ( like built in classes for sockets , threading etc )I would be doin the following type of tasks .. 1. sending data across the network     the data is going to be huge2. once data has been sent i will run some vis 
    algos parallely on them and get the resultsnow one thing that i wud req. is serializing my data structures so that they can be sent across the net.pyton does allow this using cPickle , but it bloats the data like anythin !!! 
for example a class containing 2 integers which i expect will be 8 bytes long ..cPickle.dumps returns a string thats 86 bytes wide  ( this is the binary version protocol 1 )anyway to improve serialization ??
also is it actually a good idea to write high perf applications in python ?thanks in advance-
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: to py or not to py ?

2006-06-28 Thread Chandrashekhar kaushik
okay so much for a few spelling errors and abbreviations used by me !!we are losing the main point !i had a look at mercurial . It deals with SCM . I am typically looking at an application thats to deal with geometry data ( tetras ) , 
process millions of them and may be process them repeatedly ( iterative ).It would basically involve client-server operations to first distribute dataover a computing network and then send requests to process the data
at the various nodes that contain the data. it is going to be multi-threaded. Carl , what are the problems that could arise with threading ??On 6/28/06, 
Steve Holden <[EMAIL PROTECTED]> wrote:
Serge Orlov wrote:> On 6/27/06, Chandrashekhar kaushik <[EMAIL PROTECTED]> wrote:[...]>>also is it actually a good idea to write high perf applications in python ?
>>> Take a look at Mercurial <http://www.selenic.com/mercurial/> sources.> It's a high performance python application. Or watch Bryan> O'Sullivan's Mercurial presentation
> <http://video.google.com/videoplay?docid=-7724296011317502612> he> talks briefly how they made it work fast.>> But writing high performance application in python requires
> self-discipline and attention to details, looking at the way you spell> I think it will be a challenge ;)This doesn't distinguish Python: are there any languages that you canwrite high-performance applications in *without* self-discipline and
attention to details?regards  Steve--Steve Holden   +44 150 684 7255  +1 800 494 3119Holden Web LLC/Ltd  http://www.holdenweb.comLove me, love my blog  
http://holdenweb.blogspot.comRecent Ramblings http://del.icio.us/steve.holden--
http://mail.python.org/mailman/listinfo/python-list-- --shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: to py or not to py ?

2006-06-28 Thread Chandrashekhar kaushik
> it is going to be multi-threaded.> >... because?one thread listens for incoming requests . as soon as a request arrives ( a connection is made ) the thread verifies the request and starts another thread where the request is processed ( typically  some algorithm is run on the data ).The first thread immediately goes back to listening for new connections. 
 On 6/28/06, Robert Kern <[EMAIL PROTECTED]> wrote:
Chandrashekhar kaushik wrote:> okay> so much for a few spelling errors and abbreviations used by me !!> we are losing the main point !> i had a look at mercurial . It deals with SCM . I am typically
> looking at an application thats to deal with geometry data ( tetras ) ,> process millions of them and may be process them repeatedly ( iterative ).> It would basically involve client-server operations to first distribute data
> over a computing network and then send requests to process the data> at the various nodes that contain the data.I do essentially the same thing (only with pickles of constructive solidgeometry definitions).
> it is going to be multi-threaded because?> Carl , what are the problems that could arise with threading ??An old, but still relevant overview is here:   
http://www.softpanorama.org/People/Ousterhout/Threads/index.shtmlA good event-driven framework for Python is Twisted. It's what I use for theprogram I mention above.   
http://twistedmatrix.com/trac/--Robert Kern"I have come to believe that the whole world is an enigma, a harmless enigma  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."   -- Umberto Eco--http://mail.python.org/mailman/listinfo/python-list
-- --shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

pickling and endianess

2006-08-24 Thread Chandrashekhar kaushik
Can an object pickled and saved on a little-endian machine be unpickledon a big-endian machine ? Does python handle this in some manner  , by say having a flag to indicatethe endianess of the machine on which the object was pickled ?  And then 
using this flag to decide how that data will be unpickled ?shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pickling and endianess

2006-08-24 Thread Chandrashekhar Kaushik
Thank you for the information.A request though.I am actually looking to implement serialization routines in C++.An am facing the problem of how to tackle endianess and sizeof issues.Could you give me a overview of how pickling is done in python ? Reading 
pickle.py is obviously the option , but its getting daunting as i am not that proficient in python :( .On 8/25/06, Tim Peters <
[EMAIL PROTECTED]> wrote:[Chandrashekhar kaushik]> Can an object pickled and saved on a little-endian machine be unpickled
> on a big-endian machine ?Yes.  The pickle format is platform-independent (native endiannessdoesn't matter, and neither do the native sizes of C's various integertypes).> Does python handle this in some manner  , by say having a flag to indicate
> the endianess of the machine on which the object was pickled ?  And then> using this flag to decide how that data will be unpickled ?Not a flag, no, the pickle format is the same on all platforms.  If
you need to know details, read pickle.py.--http://mail.python.org/mailman/listinfo/python-list-- 
--shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pickling and endianess

2006-08-24 Thread Chandrashekhar Kaushik
The pickletools.py seems to be giving cool info on the same ( the PM virual machine and all ). Will try to salvage something out of that. I dont think i really need that much . Just need to be able to send data across the network and then retrieve it properly independent of the architecture at the remote end :)
On 8/25/06, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
At Friday 25/8/2006 03:17, Chandrashekhar Kaushik wrote:>I am actually looking to implement serialization routines in C++.>An am facing the problem of how to tackle endianess and sizeof issues.>
>Could you give me a overview of how pickling is done in python ?>Reading pickle.py is obviously the option , but its getting daunting>as i am not that proficient in python :( .Uhm, I think this is a bit hard... The pickle format is actually code
for a stack-based machine, which gets interpreted when you load it.I think you should look for another example implementation; perhapsJava Serializable?Gabriel GenellinaSoftlab SRL
__Preguntá. Respondé. Descubrí.Todo lo que querías saber, y lo que ni imaginabas,está en Yahoo! Respuestas (Beta).¡Probalo ya!
http://www.yahoo.com.ar/respuestas-- --shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pickling and endianess

2006-08-24 Thread Chandrashekhar Kaushik
 >> What about old ASCII?    
The data is large .it also contains floats & double , so ascii will cause two problems -> loss of precision and the data will bloat  --shekhar
-- 
http://mail.python.org/mailman/listinfo/python-list