SWIG and binary strings?
Markus Stenberg
mstenber at cc.Helsinki.FI
Wed Jun 23 00:23:13 EDT 1999
I've swig'ed OpenSSL library for my Python needs. That was a cakewalk,
until I ran at the 'char *, int'-defined strings with nulls embedded in
them used in, among other things, SSL_write().
Is there any elegant way to make SWIG generate s# automatically (as opposed
to s, and requiring unneccessary length parameter and much whining if
string has 0's?)
My (ugly) solution was following:
- Define each function in wrong fashion in the .i
(SSL_write as (SSL*, char *) while it should be SSL_write(SSL *, char *,
int), etc)
- Run SWIG
- Run patch after SWIG, to do following fixes:
@@ -1108,10 +1110,11 @@
int _result;
SSL * _arg0;
char * _arg1;
+ int _arg2;
char * _argc0 = 0;
self = self;
- if(!PyArg_ParseTuple(args,ßs:SSL_write",&_argc0,&_arg1))
+ if(!PyArg_ParseTuple(args,ßs#:SSL_write",&_argc0,&_arg1,&_arg2))
return NULL;
if (_argc0) {
if (SWIG_GetPtr(_argc0,(void **) &_arg0,"_SSL_p")) {
@@ -1119,7 +1122,7 @@
return NULL;
}
}
- _result = (int )SSL_write(_arg0,_arg1);
+ _result = (int )SSL_write(_arg0,_arg1,_arg2);
_resultobj = Py_BuildValue(ï",_result);
return _resultobj;
}
.. and obviously same for other functions as well.
I do not find this elegant, however, is there any other way? (Beyond
writing ugly wrappers in pure Python-C, and I am too lazy to maintain those
;->)
- Academically-curious-ly, Markus
--
Markus Stenberg
Finger fingon at mpoli.fi for PGP key -- PGP key id: 1024/5DAC7D21
More information about the Python-list
mailing list