Janitorial: remove unnecessary const_casts

The python C API has consts at these places
This commit is contained in:
Lionel Elie Mamane
2011-08-20 17:33:37 +02:00
parent d269a18250
commit 58aa95c944
7 changed files with 50 additions and 50 deletions

View File

@@ -76,7 +76,7 @@ static void raiseRuntimeExceptionWhenNeeded() throw ( RuntimeException )
static PyRef getLoaderModule() throw( RuntimeException ) static PyRef getLoaderModule() throw( RuntimeException )
{ {
PyRef module( PyRef module(
PyImport_ImportModule( const_cast< char * >("pythonloader") ), PyImport_ImportModule( "pythonloader" ),
SAL_NO_ACQUIRE ); SAL_NO_ACQUIRE );
raiseRuntimeExceptionWhenNeeded(); raiseRuntimeExceptionWhenNeeded();
if( !module.is() ) if( !module.is() )

View File

@@ -373,7 +373,7 @@ PyObject *PyUNO_invoke( PyObject *object, const char *name , PyObject *args )
if( PyObject_IsInstance( element , getAnyClass( runtime ).get() ) ) if( PyObject_IsInstance( element , getAnyClass( runtime ).get() ) )
{ {
element = PyObject_GetAttrString( element = PyObject_GetAttrString(
element, const_cast< char * >("value") ); element, "value" );
} }
else else
{ {
@@ -647,7 +647,7 @@ static PyObject* PyUNO_cmp( PyObject *self, PyObject *that, int op )
static PyTypeObject PyUNOType = static PyTypeObject PyUNOType =
{ {
PyVarObject_HEAD_INIT( &PyType_Type, 0 ) PyVarObject_HEAD_INIT( &PyType_Type, 0 )
const_cast< char * >("pyuno"), "pyuno",
sizeof (PyUNO), sizeof (PyUNO),
0, 0,
(destructor) PyUNO_del, (destructor) PyUNO_del,

View File

@@ -197,7 +197,7 @@ PyObject* PyUNO_callable_call (PyObject* self, PyObject* args, PyObject*)
static PyTypeObject PyUNO_callable_Type = static PyTypeObject PyUNO_callable_Type =
{ {
PyVarObject_HEAD_INIT( &PyType_Type, 0 ) PyVarObject_HEAD_INIT( &PyType_Type, 0 )
const_cast< char * >("PyUNO_callable"), "PyUNO_callable",
sizeof (PyUNO_callable), sizeof (PyUNO_callable),
0, 0,
(destructor) ::pyuno::PyUNO_callable_del, (destructor) ::pyuno::PyUNO_callable_del,

View File

@@ -174,7 +174,7 @@ static PyRef createClass( const OUString & name, const Runtime &runtime )
if( isInterface ) if( isInterface )
{ {
PyObject_SetAttrString( PyObject_SetAttrString(
ret.get(), const_cast< char * >("__pyunointerface__"), ret.get(), "__pyunointerface__",
ustring2PyString(name).get() ); ustring2PyString(name).get() );
} }
else else
@@ -186,23 +186,23 @@ static PyRef createClass( const OUString & name, const Runtime &runtime )
PyRef eq = getObjectFromUnoModule( runtime,"_uno_struct__eq__" ); PyRef eq = getObjectFromUnoModule( runtime,"_uno_struct__eq__" );
PyObject_SetAttrString( PyObject_SetAttrString(
ret.get(), const_cast< char * >("__pyunostruct__"), ret.get(), "__pyunostruct__",
ustring2PyString(name).get() ); ustring2PyString(name).get() );
PyObject_SetAttrString( PyObject_SetAttrString(
ret.get(), const_cast< char * >("typeName"), ret.get(), "typeName",
ustring2PyString(name).get() ); ustring2PyString(name).get() );
PyObject_SetAttrString( PyObject_SetAttrString(
ret.get(), const_cast< char * >("__init__"), ctor.get() ); ret.get(), "__init__", ctor.get() );
PyObject_SetAttrString( PyObject_SetAttrString(
ret.get(), const_cast< char * >("__getattr__"), getter.get() ); ret.get(), "__getattr__", getter.get() );
PyObject_SetAttrString( PyObject_SetAttrString(
ret.get(), const_cast< char * >("__setattr__"), setter.get() ); ret.get(), "__setattr__", setter.get() );
PyObject_SetAttrString( PyObject_SetAttrString(
ret.get(), const_cast< char * >("__repr__"), repr.get() ); ret.get(), "__repr__", repr.get() );
PyObject_SetAttrString( PyObject_SetAttrString(
ret.get(), const_cast< char * >("__str__"), repr.get() ); ret.get(), "__str__", repr.get() );
PyObject_SetAttrString( PyObject_SetAttrString(
ret.get(), const_cast< char * >("__eq__"), eq.get() ); ret.get(), "__eq__", eq.get() );
} }
return ret; return ret;
} }
@@ -210,10 +210,10 @@ static PyRef createClass( const OUString & name, const Runtime &runtime )
bool isInstanceOfStructOrException( PyObject *obj) bool isInstanceOfStructOrException( PyObject *obj)
{ {
PyRef attr( PyRef attr(
PyObject_GetAttrString(obj, const_cast< char * >("__class__")), PyObject_GetAttrString(obj, "__class__"),
SAL_NO_ACQUIRE ); SAL_NO_ACQUIRE );
return PyObject_HasAttrString( return PyObject_HasAttrString(
attr.get(), const_cast< char * >("__pyunostruct__")); attr.get(), "__pyunostruct__");
} }
sal_Bool isInterfaceClass( const Runtime &runtime, PyObject * obj ) sal_Bool isInterfaceClass( const Runtime &runtime, PyObject * obj )
@@ -233,11 +233,11 @@ PyRef getClass( const OUString & name , const Runtime &runtime)
ret = createClass( name, runtime ); ret = createClass( name, runtime );
cargo->exceptionMap[name] = ret; cargo->exceptionMap[name] = ret;
if( PyObject_HasAttrString( if( PyObject_HasAttrString(
ret.get(), const_cast< char * >("__pyunointerface__") ) ) ret.get(), "__pyunointerface__" ) )
cargo->interfaceSet.insert( ret ); cargo->interfaceSet.insert( ret );
PyObject_SetAttrString( PyObject_SetAttrString(
ret.get(), const_cast< char * >("__pyunointerface__"), ret.get(), "__pyunointerface__",
ustring2PyString(name).get() ); ustring2PyString(name).get() );
} }
else else

View File

@@ -447,7 +447,7 @@ static PyObject *getTypeByName( PyObject *, PyObject *args )
{ {
char *name; char *name;
if (PyArg_ParseTuple (args, const_cast< char * >("s"), &name)) if (PyArg_ParseTuple (args, "s", &name))
{ {
OUString typeName ( OUString::createFromAscii( name ) ); OUString typeName ( OUString::createFromAscii( name ) );
TypeDescription typeDesc( typeName ); TypeDescription typeDesc( typeName );
@@ -479,7 +479,7 @@ static PyObject *getConstantByName( PyObject *, PyObject *args )
{ {
char *name; char *name;
if (PyArg_ParseTuple (args, const_cast< char * >("s"), &name)) if (PyArg_ParseTuple (args, "s", &name))
{ {
OUString typeName ( OUString::createFromAscii( name ) ); OUString typeName ( OUString::createFromAscii( name ) );
Runtime runtime; Runtime runtime;
@@ -801,21 +801,21 @@ static PyObject *setCurrentContext( PyObject *, PyObject * args )
struct PyMethodDef PyUNOModule_methods [] = struct PyMethodDef PyUNOModule_methods [] =
{ {
{const_cast< char * >("getComponentContext"), getComponentContext, METH_VARARGS, NULL}, {"getComponentContext", getComponentContext, METH_VARARGS, NULL},
{const_cast< char * >("_createUnoStructHelper"), reinterpret_cast<PyCFunction>(createUnoStructHelper), METH_VARARGS | METH_KEYWORDS, NULL}, {"_createUnoStructHelper", reinterpret_cast<PyCFunction>(createUnoStructHelper), METH_VARARGS | METH_KEYWORDS, NULL},
{const_cast< char * >("getTypeByName"), getTypeByName, METH_VARARGS, NULL}, {"getTypeByName", getTypeByName, METH_VARARGS, NULL},
{const_cast< char * >("getConstantByName"), getConstantByName, METH_VARARGS, NULL}, {"getConstantByName", getConstantByName, METH_VARARGS, NULL},
{const_cast< char * >("getClass"), getClass, METH_VARARGS, NULL}, {"getClass", getClass, METH_VARARGS, NULL},
{const_cast< char * >("checkEnum"), checkEnum, METH_VARARGS, NULL}, {"checkEnum", checkEnum, METH_VARARGS, NULL},
{const_cast< char * >("checkType"), checkType, METH_VARARGS, NULL}, {"checkType", checkType, METH_VARARGS, NULL},
{const_cast< char * >("generateUuid"), generateUuid, METH_VARARGS, NULL}, {"generateUuid", generateUuid, METH_VARARGS, NULL},
{const_cast< char * >("systemPathToFileUrl"), systemPathToFileUrl, METH_VARARGS, NULL}, {"systemPathToFileUrl", systemPathToFileUrl, METH_VARARGS, NULL},
{const_cast< char * >("fileUrlToSystemPath"), fileUrlToSystemPath, METH_VARARGS, NULL}, {"fileUrlToSystemPath", fileUrlToSystemPath, METH_VARARGS, NULL},
{const_cast< char * >("absolutize"), absolutize, METH_VARARGS | METH_KEYWORDS, NULL}, {"absolutize", absolutize, METH_VARARGS | METH_KEYWORDS, NULL},
{const_cast< char * >("isInterface"), isInterface, METH_VARARGS, NULL}, {"isInterface", isInterface, METH_VARARGS, NULL},
{const_cast< char * >("invoke"), invoke, METH_VARARGS | METH_KEYWORDS, NULL}, {"invoke", invoke, METH_VARARGS | METH_KEYWORDS, NULL},
{const_cast< char * >("setCurrentContext"), setCurrentContext, METH_VARARGS, NULL}, {"setCurrentContext", setCurrentContext, METH_VARARGS, NULL},
{const_cast< char * >("getCurrentContext"), getCurrentContext, METH_VARARGS, NULL}, {"getCurrentContext", getCurrentContext, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
@@ -845,7 +845,7 @@ PyObject* PyInit_pyuno()
void initpyuno() void initpyuno()
{ {
PyEval_InitThreads(); PyEval_InitThreads();
Py_InitModule (const_cast< char * >("pyuno"), PyUNOModule_methods); Py_InitModule ("pyuno", PyUNOModule_methods);
} }
#endif /* PY_MAJOR_VERSION >= 3 */ #endif /* PY_MAJOR_VERSION >= 3 */

View File

@@ -74,7 +74,7 @@ namespace pyuno
static PyTypeObject RuntimeImpl_Type = static PyTypeObject RuntimeImpl_Type =
{ {
PyVarObject_HEAD_INIT (&PyType_Type, 0) PyVarObject_HEAD_INIT (&PyType_Type, 0)
const_cast< char * >("pyuno_runtime"), "pyuno_runtime",
sizeof (RuntimeImpl), sizeof (RuntimeImpl),
0, 0,
(destructor) RuntimeImpl::del, (destructor) RuntimeImpl::del,
@@ -138,7 +138,7 @@ static void getRuntimeImpl( PyRef & globalDict, PyRef &runtimeImpl )
Reference< XInterface > () ); Reference< XInterface > () );
} }
globalDict = PyRef( PyModule_GetDict(PyImport_AddModule(const_cast< char * >("__main__")))); globalDict = PyRef( PyModule_GetDict(PyImport_AddModule("__main__")));
if( ! globalDict.is() ) // FATAL ! if( ! globalDict.is() ) // FATAL !
{ {
@@ -151,7 +151,7 @@ static void getRuntimeImpl( PyRef & globalDict, PyRef &runtimeImpl )
static PyRef importUnoModule( ) throw ( RuntimeException ) static PyRef importUnoModule( ) throw ( RuntimeException )
{ {
// import the uno module // import the uno module
PyRef module( PyImport_ImportModule( const_cast< char * >("uno") ), SAL_NO_ACQUIRE ); PyRef module( PyImport_ImportModule( "uno" ), SAL_NO_ACQUIRE );
if( PyErr_Occurred() ) if( PyErr_Occurred() )
{ {
PyRef excType, excValue, excTraceback; PyRef excType, excValue, excTraceback;
@@ -551,7 +551,7 @@ PyRef Runtime::any2PyObject (const Any &a ) const
PyTuple_SetItem( args.get(), 0 , pymsg.getAcquired() ); PyTuple_SetItem( args.get(), 0 , pymsg.getAcquired() );
// the exception base functions want to have an "args" tuple, // the exception base functions want to have an "args" tuple,
// which contains the message // which contains the message
PyObject_SetAttrString( ret.get(), const_cast< char * >("args"), args.get() ); PyObject_SetAttrString( ret.get(), "args", args.get() );
} }
return ret; return ret;
} }
@@ -626,7 +626,7 @@ static Sequence< Type > invokeGetTypes( const Runtime & r , PyObject * o )
{ {
Sequence< Type > ret; Sequence< Type > ret;
PyRef method( PyObject_GetAttrString( o , const_cast< char * >("getTypes") ), SAL_NO_ACQUIRE ); PyRef method( PyObject_GetAttrString( o , "getTypes" ), SAL_NO_ACQUIRE );
raiseInvocationTargetExceptionWhenNeeded( r ); raiseInvocationTargetExceptionWhenNeeded( r );
if( method.is() && PyCallable_Check( method.get() ) ) if( method.is() && PyCallable_Check( method.get() ) )
{ {
@@ -765,7 +765,7 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con
// should be removed, in case ByteSequence gets derived from String // should be removed, in case ByteSequence gets derived from String
if( PyObject_IsInstance( o, getByteSequenceClass( runtime ).get() ) ) if( PyObject_IsInstance( o, getByteSequenceClass( runtime ).get() ) )
{ {
PyRef str(PyObject_GetAttrString( o , const_cast< char * >("value") ),SAL_NO_ACQUIRE); PyRef str(PyObject_GetAttrString( o , "value" ),SAL_NO_ACQUIRE);
Sequence< sal_Int8 > seq; Sequence< sal_Int8 > seq;
if( PyString_Check( str.get() ) ) if( PyString_Check( str.get() ) )
{ {
@@ -786,7 +786,7 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con
} }
else if( isInstanceOfStructOrException( o ) ) else if( isInstanceOfStructOrException( o ) )
{ {
PyRef struc(PyObject_GetAttrString( o , const_cast< char * >("value") ),SAL_NO_ACQUIRE); PyRef struc(PyObject_GetAttrString( o , "value" ),SAL_NO_ACQUIRE);
PyUNO * obj = (PyUNO*)struc.get(); PyUNO * obj = (PyUNO*)struc.get();
Reference< XMaterialHolder > holder( obj->members->xInvocation, UNO_QUERY ); Reference< XMaterialHolder > holder( obj->members->xInvocation, UNO_QUERY );
if( holder.is( ) ) if( holder.is( ) )
@@ -832,9 +832,9 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con
{ {
if( ACCEPT_UNO_ANY == mode ) if( ACCEPT_UNO_ANY == mode )
{ {
a = pyObject2Any( PyRef( PyObject_GetAttrString( o , const_cast< char * >("value") ), SAL_NO_ACQUIRE) ); a = pyObject2Any( PyRef( PyObject_GetAttrString( o , "value" ), SAL_NO_ACQUIRE) );
Type t; Type t;
pyObject2Any( PyRef( PyObject_GetAttrString( o, const_cast< char * >("type") ), SAL_NO_ACQUIRE ) ) >>= t; pyObject2Any( PyRef( PyObject_GetAttrString( o, "type" ), SAL_NO_ACQUIRE ) ) >>= t;
try try
{ {

View File

@@ -147,7 +147,7 @@ PyRef getAnyClass( const Runtime & r )
sal_Unicode PyChar2Unicode( PyObject *obj ) throw ( RuntimeException ) sal_Unicode PyChar2Unicode( PyObject *obj ) throw ( RuntimeException )
{ {
PyRef value( PyObject_GetAttrString( obj, const_cast< char * >("value") ), SAL_NO_ACQUIRE ); PyRef value( PyObject_GetAttrString( obj, "value" ), SAL_NO_ACQUIRE );
if( ! PyUnicode_Check( value.get() ) ) if( ! PyUnicode_Check( value.get() ) )
{ {
throw RuntimeException( throw RuntimeException(
@@ -169,8 +169,8 @@ sal_Unicode PyChar2Unicode( PyObject *obj ) throw ( RuntimeException )
Any PyEnum2Enum( PyObject *obj ) throw ( RuntimeException ) Any PyEnum2Enum( PyObject *obj ) throw ( RuntimeException )
{ {
Any ret; Any ret;
PyRef typeName( PyObject_GetAttrString( obj,const_cast< char * >("typeName") ), SAL_NO_ACQUIRE); PyRef typeName( PyObject_GetAttrString( obj,"typeName" ), SAL_NO_ACQUIRE);
PyRef value( PyObject_GetAttrString( obj, const_cast< char * >("value") ), SAL_NO_ACQUIRE); PyRef value( PyObject_GetAttrString( obj, "value" ), SAL_NO_ACQUIRE);
if( !PyString_Check( typeName.get() ) || ! PyString_Check( value.get() ) ) if( !PyString_Check( typeName.get() ) || ! PyString_Check( value.get() ) )
{ {
throw RuntimeException( throw RuntimeException(
@@ -226,7 +226,7 @@ Any PyEnum2Enum( PyObject *obj ) throw ( RuntimeException )
Type PyType2Type( PyObject * o ) throw(RuntimeException ) Type PyType2Type( PyObject * o ) throw(RuntimeException )
{ {
PyRef pyName( PyObject_GetAttrString( o, const_cast< char * >("typeName") ), SAL_NO_ACQUIRE); PyRef pyName( PyObject_GetAttrString( o, "typeName" ), SAL_NO_ACQUIRE);
if( !PyString_Check( pyName.get() ) ) if( !PyString_Check( pyName.get() ) )
{ {
throw RuntimeException( throw RuntimeException(
@@ -234,7 +234,7 @@ Type PyType2Type( PyObject * o ) throw(RuntimeException )
Reference< XInterface > () ); Reference< XInterface > () );
} }
PyRef pyTC( PyObject_GetAttrString( o, const_cast< char * >("typeClass") ), SAL_NO_ACQUIRE ); PyRef pyTC( PyObject_GetAttrString( o, "typeClass" ), SAL_NO_ACQUIRE );
Any enumValue = PyEnum2Enum( pyTC.get() ); Any enumValue = PyEnum2Enum( pyTC.get() );
OUString name( OUString::createFromAscii( PyString_AsString( pyName.get() ) ) ); OUString name( OUString::createFromAscii( PyString_AsString( pyName.get() ) ) );
@@ -277,7 +277,7 @@ PyObject *importToGlobal(PyObject *str, PyObject *dict, PyObject *target)
PyRef typesModule( PyDict_GetItemString( dict, "unotypes" ) ); PyRef typesModule( PyDict_GetItemString( dict, "unotypes" ) );
if( ! typesModule.is() || ! PyModule_Check( typesModule.get() )) if( ! typesModule.is() || ! PyModule_Check( typesModule.get() ))
{ {
typesModule = PyRef( PyModule_New( const_cast< char * >("unotypes") ), SAL_NO_ACQUIRE ); typesModule = PyRef( PyModule_New( "unotypes" ), SAL_NO_ACQUIRE );
Py_INCREF( typesModule.get() ); Py_INCREF( typesModule.get() );
PyDict_SetItemString( dict, "unotypes" , typesModule.get() ); PyDict_SetItemString( dict, "unotypes" , typesModule.get() );
} }