You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by pf...@apache.org on 2012/10/17 06:28:20 UTC
svn commit: r1399089 - in /incubator/ooo/trunk/main/pyuno:
inc/pyuno/pyuno.hxx source/module/pyuno.cxx source/module/pyuno_adapter.cxx
source/module/pyuno_module.cxx source/module/pyuno_runtime.cxx
source/module/pyuno_type.cxx source/module/pyuno_util.cxx
Author: pfg
Date: Wed Oct 17 04:28:19 2012
New Revision: 1399089
URL: http://svn.apache.org/viewvc?rev=1399089&view=rev
Log:
pyuno: obsolete PyString_* in favor of PyBytes_*
Python3 removed the PyString functions and replaced them with PyBytes.
To aid portability Python version 2.6 and upper support PyBytes and
we are adding some compatibility defines for older versions so no
problems are expected from this change.
Reference: http://docs.python.org/c-api/string.html
Modified:
incubator/ooo/trunk/main/pyuno/inc/pyuno/pyuno.hxx
incubator/ooo/trunk/main/pyuno/source/module/pyuno.cxx
incubator/ooo/trunk/main/pyuno/source/module/pyuno_adapter.cxx
incubator/ooo/trunk/main/pyuno/source/module/pyuno_module.cxx
incubator/ooo/trunk/main/pyuno/source/module/pyuno_runtime.cxx
incubator/ooo/trunk/main/pyuno/source/module/pyuno_type.cxx
incubator/ooo/trunk/main/pyuno/source/module/pyuno_util.cxx
Modified: incubator/ooo/trunk/main/pyuno/inc/pyuno/pyuno.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/pyuno/inc/pyuno/pyuno.hxx?rev=1399089&r1=1399088&r2=1399089&view=diff
==============================================================================
--- incubator/ooo/trunk/main/pyuno/inc/pyuno/pyuno.hxx (original)
+++ incubator/ooo/trunk/main/pyuno/inc/pyuno/pyuno.hxx Wed Oct 17 04:28:19 2012
@@ -37,11 +37,20 @@
#pragma warning(pop)
#endif
#endif // #ifdef Py_PYTHON_H
+
// Compatibility for older system Python (2.6 and previous)
#ifndef PyVarObject_HEAD_INIT
#define PyVarObject_HEAD_INIT(type, size) \
PyObject_HEAD_INIT(type) size,
#endif
+// define PyBytes_* as the equivalent string type methods.
+#ifndef PyBytes_Check
+ #define PyBytes_Check PyString_Check
+ #define PyBytes_AsString PyString_AsString
+ #define PyBytes_FromString PyString_FromString
+ #define PyBytes_Size PyString_Size
+ #define PyBytes_FromStringAndSize PyString_FromStringAndSize
+#endif
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/script/CannotConvertException.hpp>
Modified: incubator/ooo/trunk/main/pyuno/source/module/pyuno.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/pyuno/source/module/pyuno.cxx?rev=1399089&r1=1399088&r2=1399089&view=diff
==============================================================================
--- incubator/ooo/trunk/main/pyuno/source/module/pyuno.cxx (original)
+++ incubator/ooo/trunk/main/pyuno/source/module/pyuno.cxx Wed Oct 17 04:28:19 2012
@@ -441,7 +441,7 @@ PyObject *PyUNO_str( PyObject * self )
buf.append( OUStringToOString(s,RTL_TEXTENCODING_ASCII_US) );
}
- return PyString_FromString( buf.getStr());
+ return PyBytes_FromString( buf.getStr());
}
PyObject* PyUNO_getattr (PyObject* self, char* name)
@@ -647,7 +647,7 @@ static PyTypeObject PyUNOType =
(printfunc) 0,
(getattrfunc) PyUNO_getattr,
(setattrfunc) PyUNO_setattr,
- (cmpfunc) PyUNO_cmp,
+ PyUNO_cmp,
(reprfunc) PyUNO_repr,
0,
0,
Modified: incubator/ooo/trunk/main/pyuno/source/module/pyuno_adapter.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/pyuno/source/module/pyuno_adapter.cxx?rev=1399089&r1=1399088&r2=1399089&view=diff
==============================================================================
--- incubator/ooo/trunk/main/pyuno/source/module/pyuno_adapter.cxx (original)
+++ incubator/ooo/trunk/main/pyuno/source/module/pyuno_adapter.cxx Wed Oct 17 04:28:19 2012
@@ -246,7 +246,7 @@ Any Adapter::invoke( const OUString &aFu
buf.appendAscii( "pyuno::Adapater: Method " ).append( aFunctionName );
buf.appendAscii( " is not implemented at object " );
PyRef str( PyObject_Repr( mWrappedObject.get() ), SAL_NO_ACQUIRE );
- buf.appendAscii( PyString_AsString( str.get() ));
+ buf.appendAscii( PyBytes_AsString( str.get() ));
throw IllegalArgumentException( buf.makeStringAndClear(), Reference< XInterface > (),0 );
}
Modified: incubator/ooo/trunk/main/pyuno/source/module/pyuno_module.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/pyuno/source/module/pyuno_module.cxx?rev=1399089&r1=1399088&r2=1399089&view=diff
==============================================================================
--- incubator/ooo/trunk/main/pyuno/source/module/pyuno_module.cxx (original)
+++ incubator/ooo/trunk/main/pyuno/source/module/pyuno_module.cxx Wed Oct 17 04:28:19 2012
@@ -225,7 +225,7 @@ PyObject * extractOneStringArg( PyObject
return NULL;
}
PyObject *obj = PyTuple_GetItem( args, 0 );
- if( !PyString_Check( obj ) && ! PyUnicode_Check(obj))
+ if( !PyBytes_Check( obj ) && ! PyUnicode_Check(obj))
{
OStringBuffer buf;
buf.append( funcName ).append( ": expecting one string argument" );
@@ -248,11 +248,11 @@ static PyObject *createUnoStructHelper(P
PyObject *structName = PyTuple_GetItem( args,0 );
PyObject *initializer = PyTuple_GetItem( args ,1 );
- if( PyString_Check( structName ) )
+ if( PyBytes_Check( structName ) )
{
if( PyTuple_Check( initializer ) )
{
- OUString typeName( OUString::createFromAscii(PyString_AsString(structName)));
+ OUString typeName( OUString::createFromAscii(PyBytes_AsString(structName)));
RuntimeCargo *c = runtime.getImpl()->cargo;
Reference<XIdlClass> idl_class ( c->xCoreReflection->forName (typeName),UNO_QUERY);
if (idl_class.is ())
@@ -287,7 +287,7 @@ static PyObject *createUnoStructHelper(P
{
OStringBuffer buf;
buf.append( "UNO struct " );
- buf.append( PyString_AsString(structName) );
+ buf.append( PyBytes_AsString(structName) );
buf.append( " is unkown" );
PyErr_SetString (PyExc_RuntimeError, buf.getStr());
}
@@ -463,7 +463,7 @@ static PyObject *getClass( PyObject *, P
{
Runtime runtime;
PyRef ret = getClass(
- OUString( PyString_AsString( obj), strlen(PyString_AsString(obj)),RTL_TEXTENCODING_ASCII_US),
+ OUString( PyBytes_AsString( obj), strlen(PyBytes_AsString(obj)),RTL_TEXTENCODING_ASCII_US),
runtime );
Py_XINCREF( ret.get() );
return ret.get();
@@ -603,9 +603,9 @@ static PyObject * invoke ( PyObject *, P
{
PyObject *object = PyTuple_GetItem( args, 0 );
- if( PyString_Check( PyTuple_GetItem( args, 1 ) ) )
+ if( PyBytes_Check( PyTuple_GetItem( args, 1 ) ) )
{
- const char *name = PyString_AsString( PyTuple_GetItem( args, 1 ) );
+ const char *name = PyBytes_AsString( PyTuple_GetItem( args, 1 ) );
if( PyTuple_Check( PyTuple_GetItem( args , 2 )))
{
ret = PyUNO_invoke( object, name , PyTuple_GetItem( args, 2 ) );
@@ -614,7 +614,7 @@ static PyObject * invoke ( PyObject *, P
{
OStringBuffer buf;
buf.append( "uno.invoke expects a tuple as 3rd argument, got " );
- buf.append( PyString_AsString( PyObject_Str( PyTuple_GetItem( args, 2) ) ) );
+ buf.append( PyBytes_AsString( PyObject_Str( PyTuple_GetItem( args, 2) ) ) );
PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
}
}
@@ -622,7 +622,7 @@ static PyObject * invoke ( PyObject *, P
{
OStringBuffer buf;
buf.append( "uno.invoke expected a string as 2nd argument, got " );
- buf.append( PyString_AsString( PyObject_Str( PyTuple_GetItem( args, 1) ) ) );
+ buf.append( PyBytes_AsString( PyObject_Str( PyTuple_GetItem( args, 1) ) ) );
PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
}
}
@@ -672,7 +672,7 @@ static PyObject *setCurrentContext( PyOb
{
OStringBuffer buf;
buf.append( "uno.setCurrentContext expects an XComponentContext implementation, got " );
- buf.append( PyString_AsString( PyObject_Str( PyTuple_GetItem( args, 0) ) ) );
+ buf.append( PyBytes_AsString( PyObject_Str( PyTuple_GetItem( args, 0) ) ) );
PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
}
}
@@ -717,6 +717,7 @@ struct PyMethodDef PyUNOModule_methods [
extern "C" PY_DLLEXPORT void initpyuno()
{
// noop when called already, otherwise needed to allow multiple threads
+ // This has to be reworked for Python 3.
PyEval_InitThreads();
Py_InitModule (const_cast< char * >("pyuno"), PyUNOModule_methods);
}
Modified: incubator/ooo/trunk/main/pyuno/source/module/pyuno_runtime.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/pyuno/source/module/pyuno_runtime.cxx?rev=1399089&r1=1399088&r2=1399089&view=diff
==============================================================================
--- incubator/ooo/trunk/main/pyuno/source/module/pyuno_runtime.cxx (original)
+++ incubator/ooo/trunk/main/pyuno/source/module/pyuno_runtime.cxx Wed Oct 17 04:28:19 2012
@@ -154,8 +154,8 @@ static PyRef importUnoModule( ) throw (
OUStringBuffer buf;
buf.appendAscii( "python object raised an unknown exception (" );
PyRef valueRep( PyObject_Repr( excValue.get() ), SAL_NO_ACQUIRE );
- buf.appendAscii( PyString_AsString( valueRep.get())).appendAscii( ", traceback follows\n" );
- buf.appendAscii( PyString_AsString( str.get() ) );
+ buf.appendAscii( PyBytes_AsString( valueRep.get())).appendAscii( ", traceback follows\n" );
+ buf.appendAscii( PyBytes_AsString( str.get() ) );
throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface > () );
}
PyRef dict( PyModule_GetDict( module.get() ) );
@@ -722,7 +722,7 @@ Any Runtime::pyObject2Any ( const PyRef
double d = PyFloat_AsDouble (o);
a <<= d;
}
- else if (PyString_Check (o))
+ else if (PyBytes_Check (o))
a <<= pyString2ustring(o);
else if( PyUnicode_Check( o ) )
a <<= pyString2ustring(o);
@@ -743,10 +743,10 @@ Any Runtime::pyObject2Any ( const PyRef
{
PyRef str(PyObject_GetAttrString( o , const_cast< char * >("value") ),SAL_NO_ACQUIRE);
Sequence< sal_Int8 > seq;
- if( PyString_Check( str.get() ) )
+ if( PyBytes_Check( str.get() ) )
{
seq = Sequence<sal_Int8 > (
- (sal_Int8*) PyString_AsString(str.get()), PyString_Size(str.get()));
+ (sal_Int8*) PyBytes_AsString(str.get()), PyBytes_Size(str.get()));
}
a <<= seq;
}
@@ -879,7 +879,7 @@ Any Runtime::pyObject2Any ( const PyRef
OUStringBuffer buf;
buf.appendAscii( "Couldn't convert " );
PyRef reprString( PyObject_Str( o ) , SAL_NO_ACQUIRE );
- buf.appendAscii( PyString_AsString( reprString.get() ) );
+ buf.appendAscii( PyBytes_AsString( reprString.get() ) );
buf.appendAscii( " to a UNO type" );
throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface > () );
}
@@ -909,14 +909,14 @@ Any Runtime::extractUnoException( const
else
{
str = PyRef(
- PyString_FromString( "Couldn't find uno._uno_extract_printable_stacktrace" ),
+ PyBytes_FromString( "Couldn't find uno._uno_extract_printable_stacktrace" ),
SAL_NO_ACQUIRE );
}
}
else
{
str = PyRef(
- PyString_FromString( "Couldn't find uno.py, no stacktrace available" ),
+ PyBytes_FromString( "Couldn't find uno.py, no stacktrace available" ),
SAL_NO_ACQUIRE );
}
@@ -924,7 +924,7 @@ Any Runtime::extractUnoException( const
else
{
// it may occur, that no traceback is given (e.g. only native code below)
- str = PyRef( PyString_FromString( "no traceback available" ), SAL_NO_ACQUIRE);
+ str = PyRef( PyBytes_FromString( "no traceback available" ), SAL_NO_ACQUIRE);
}
if( isInstanceOfStructOrException( excValue.get() ) )
@@ -937,7 +937,7 @@ Any Runtime::extractUnoException( const
PyRef typeName( PyObject_Str( excType.get() ), SAL_NO_ACQUIRE );
if( typeName.is() )
{
- buf.appendAscii( PyString_AsString( typeName.get() ) );
+ buf.appendAscii( PyBytes_AsString( typeName.get() ) );
}
else
{
@@ -947,7 +947,7 @@ Any Runtime::extractUnoException( const
PyRef valueRep( PyObject_Str( excValue.get() ), SAL_NO_ACQUIRE );
if( valueRep.is() )
{
- buf.appendAscii( PyString_AsString( valueRep.get()));
+ buf.appendAscii( PyBytes_AsString( valueRep.get()));
}
else
{
@@ -956,7 +956,7 @@ Any Runtime::extractUnoException( const
buf.appendAscii( ", traceback follows\n" );
if( str.is() )
{
- buf.appendAscii( PyString_AsString( str.get() ) );
+ buf.appendAscii( PyBytes_AsString( str.get() ) );
}
else
{
Modified: incubator/ooo/trunk/main/pyuno/source/module/pyuno_type.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/pyuno/source/module/pyuno_type.cxx?rev=1399089&r1=1399088&r2=1399089&view=diff
==============================================================================
--- incubator/ooo/trunk/main/pyuno/source/module/pyuno_type.cxx (original)
+++ incubator/ooo/trunk/main/pyuno/source/module/pyuno_type.cxx Wed Oct 17 04:28:19 2012
@@ -166,15 +166,15 @@ Any PyEnum2Enum( PyObject *obj ) throw (
Any ret;
PyRef typeName( PyObject_GetAttrString( obj,const_cast< char * >("typeName") ), SAL_NO_ACQUIRE);
PyRef value( PyObject_GetAttrString( obj, const_cast< char * >("value") ), SAL_NO_ACQUIRE);
- if( !PyString_Check( typeName.get() ) || ! PyString_Check( value.get() ) )
+ if( !PyBytes_Check( typeName.get() ) || ! PyBytes_Check( value.get() ) )
{
throw RuntimeException(
USTR_ASCII( "attributes typeName and/or value of uno.Enum are not strings" ),
Reference< XInterface > () );
}
- OUString strTypeName( OUString::createFromAscii( PyString_AsString( typeName.get() ) ) );
- char *stringValue = PyString_AsString( value.get() );
+ OUString strTypeName( OUString::createFromAscii( PyBytes_AsString( typeName.get() ) ) );
+ char *stringValue = PyBytes_AsString( value.get() );
TypeDescription desc( strTypeName );
if( desc.is() )
@@ -204,7 +204,7 @@ Any PyEnum2Enum( PyObject *obj ) throw (
{
OUStringBuffer buf;
buf.appendAscii( "value " ).appendAscii( stringValue ).appendAscii( "is unknown in enum " );
- buf.appendAscii( PyString_AsString( typeName.get() ) );
+ buf.appendAscii( PyBytes_AsString( typeName.get() ) );
throw RuntimeException( buf.makeStringAndClear(), Reference<XInterface> () );
}
ret = Any( &pEnumDesc->pEnumValues[i], desc.get()->pWeakRef );
@@ -212,7 +212,7 @@ Any PyEnum2Enum( PyObject *obj ) throw (
else
{
OUStringBuffer buf;
- buf.appendAscii( "enum " ).appendAscii( PyString_AsString(typeName.get()) ).appendAscii( " is unknown" );
+ buf.appendAscii( "enum " ).appendAscii( PyBytes_AsString(typeName.get()) ).appendAscii( " is unknown" );
throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface> () );
}
return ret;
@@ -222,7 +222,7 @@ Any PyEnum2Enum( PyObject *obj ) throw (
Type PyType2Type( PyObject * o ) throw(RuntimeException )
{
PyRef pyName( PyObject_GetAttrString( o, const_cast< char * >("typeName") ), SAL_NO_ACQUIRE);
- if( !PyString_Check( pyName.get() ) )
+ if( !PyBytes_Check( pyName.get() ) )
{
throw RuntimeException(
USTR_ASCII( "type object does not have typeName property" ),
@@ -232,7 +232,7 @@ Type PyType2Type( PyObject * o ) throw(R
PyRef pyTC( PyObject_GetAttrString( o, const_cast< char * >("typeClass") ), SAL_NO_ACQUIRE );
Any enumValue = PyEnum2Enum( pyTC.get() );
- OUString name( OUString::createFromAscii( PyString_AsString( pyName.get() ) ) );
+ OUString name( OUString::createFromAscii( PyBytes_AsString( pyName.get() ) ) );
TypeDescription desc( name );
if( ! desc.is() )
{
@@ -278,8 +278,8 @@ PyObject *importToGlobal(PyObject *str,
}
PyModule_AddObject(
typesModule.get(),
- PyString_AsString( target ),
- PyUNO_Type_new( PyString_AsString(str),tc,runtime ) );
+ PyBytes_AsString( target ),
+ PyUNO_Type_new( PyBytes_AsString(str),tc,runtime ) );
if( com::sun::star::uno::TypeClass_EXCEPTION == tc ||
com::sun::star::uno::TypeClass_STRUCT == tc )
@@ -298,7 +298,7 @@ PyObject *importToGlobal(PyObject *str,
OUStringToOString( pDesc->ppEnumNames[i], RTL_TEXTENCODING_ASCII_US) );
PyDict_SetItemString(
dict, (char*)enumElementName.getStr(),
- PyUNO_Enum_new(PyString_AsString(str) , enumElementName.getStr(), runtime ) );
+ PyUNO_Enum_new(PyBytes_AsString(str) , enumElementName.getStr(), runtime ) );
}
}
Py_INCREF( Py_None );
@@ -319,7 +319,7 @@ PyObject *importToGlobal(PyObject *str,
else
{
OStringBuffer buf;
- buf.append( "constant " ).append(PyString_AsString(str)).append( " unknown" );
+ buf.append( "constant " ).append(PyBytes_AsString(str)).append( " unknown" );
PyErr_SetString( PyExc_RuntimeError, buf.getStr() );
}
}
@@ -379,8 +379,8 @@ static PyObject* callCtor( const Runtime
PyObject *PyUNO_Enum_new( const char *enumBase, const char *enumValue, const Runtime &r )
{
PyRef args( PyTuple_New( 2 ), SAL_NO_ACQUIRE );
- PyTuple_SetItem( args.get() , 0 , PyString_FromString( enumBase ) );
- PyTuple_SetItem( args.get() , 1 , PyString_FromString( enumValue ) );
+ PyTuple_SetItem( args.get() , 0 , PyBytes_FromString( enumBase ) );
+ PyTuple_SetItem( args.get() , 1 , PyBytes_FromString( enumValue ) );
return callCtor( r, "Enum" , args );
}
@@ -391,7 +391,7 @@ PyObject* PyUNO_Type_new (const char *ty
// retrieve type object
PyRef args( PyTuple_New( 2 ), SAL_NO_ACQUIRE );
- PyTuple_SetItem( args.get() , 0 , PyString_FromString( typeName ) );
+ PyTuple_SetItem( args.get() , 0 , PyBytes_FromString( typeName ) );
PyObject *typeClass = PyUNO_Enum_new( "com.sun.star.uno.TypeClass" , typeClassToString(t), r );
if( ! typeClass )
return NULL;
@@ -417,7 +417,7 @@ PyObject *PyUNO_ByteSequence_new(
const com::sun::star::uno::Sequence< sal_Int8 > &byteSequence, const Runtime &r )
{
PyRef str(
- PyString_FromStringAndSize( (char*)byteSequence.getConstArray(), byteSequence.getLength()),
+ PyBytes_FromStringAndSize( (char*)byteSequence.getConstArray(), byteSequence.getLength()),
SAL_NO_ACQUIRE );
PyRef args( PyTuple_New( 1 ), SAL_NO_ACQUIRE );
PyTuple_SetItem( args.get() , 0 , str.getAcquired() );
Modified: incubator/ooo/trunk/main/pyuno/source/module/pyuno_util.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/pyuno/source/module/pyuno_util.cxx?rev=1399089&r1=1399088&r2=1399089&view=diff
==============================================================================
--- incubator/ooo/trunk/main/pyuno/source/module/pyuno_util.cxx (original)
+++ incubator/ooo/trunk/main/pyuno/source/module/pyuno_util.cxx Wed Oct 17 04:28:19 2012
@@ -74,7 +74,7 @@ PyRef ustring2PyUnicode( const OUString
PyRef ustring2PyString( const OUString &str )
{
OString o = OUStringToOString( str, osl_getThreadTextEncoding() );
- return PyRef( PyString_FromString( o.getStr() ), SAL_NO_ACQUIRE );
+ return PyRef( PyBytes_FromString( o.getStr() ), SAL_NO_ACQUIRE );
}
OUString pyString2ustring( PyObject *pystr )
@@ -86,13 +86,13 @@ OUString pyString2ustring( PyObject *pys
ret = OUString( (sal_Unicode * ) PyUnicode_AS_UNICODE( pystr ) );
#else
PyObject* pUtf8 = PyUnicode_AsUTF8String(pystr);
- ret = OUString(PyString_AsString(pUtf8), PyString_Size(pUtf8), RTL_TEXTENCODING_UTF8);
+ ret = OUString(PyBytes_AsString(pUtf8), PyBytes_Size(pUtf8), RTL_TEXTENCODING_UTF8);
Py_DECREF(pUtf8);
#endif
}
else
{
- char *name = PyString_AsString(pystr );
+ char *name = PyBytes_AsString(pystr );
ret = OUString( name, strlen(name), osl_getThreadTextEncoding() );
}
return ret;