Janitorial: remove unnecessary const_casts
The python C API has consts at these places
This commit is contained in:
@@ -76,7 +76,7 @@ static void raiseRuntimeExceptionWhenNeeded() throw ( RuntimeException )
|
||||
static PyRef getLoaderModule() throw( RuntimeException )
|
||||
{
|
||||
PyRef module(
|
||||
PyImport_ImportModule( const_cast< char * >("pythonloader") ),
|
||||
PyImport_ImportModule( "pythonloader" ),
|
||||
SAL_NO_ACQUIRE );
|
||||
raiseRuntimeExceptionWhenNeeded();
|
||||
if( !module.is() )
|
||||
|
@@ -373,7 +373,7 @@ PyObject *PyUNO_invoke( PyObject *object, const char *name , PyObject *args )
|
||||
if( PyObject_IsInstance( element , getAnyClass( runtime ).get() ) )
|
||||
{
|
||||
element = PyObject_GetAttrString(
|
||||
element, const_cast< char * >("value") );
|
||||
element, "value" );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -647,7 +647,7 @@ static PyObject* PyUNO_cmp( PyObject *self, PyObject *that, int op )
|
||||
static PyTypeObject PyUNOType =
|
||||
{
|
||||
PyVarObject_HEAD_INIT( &PyType_Type, 0 )
|
||||
const_cast< char * >("pyuno"),
|
||||
"pyuno",
|
||||
sizeof (PyUNO),
|
||||
0,
|
||||
(destructor) PyUNO_del,
|
||||
|
@@ -197,7 +197,7 @@ PyObject* PyUNO_callable_call (PyObject* self, PyObject* args, PyObject*)
|
||||
static PyTypeObject PyUNO_callable_Type =
|
||||
{
|
||||
PyVarObject_HEAD_INIT( &PyType_Type, 0 )
|
||||
const_cast< char * >("PyUNO_callable"),
|
||||
"PyUNO_callable",
|
||||
sizeof (PyUNO_callable),
|
||||
0,
|
||||
(destructor) ::pyuno::PyUNO_callable_del,
|
||||
|
@@ -174,7 +174,7 @@ static PyRef createClass( const OUString & name, const Runtime &runtime )
|
||||
if( isInterface )
|
||||
{
|
||||
PyObject_SetAttrString(
|
||||
ret.get(), const_cast< char * >("__pyunointerface__"),
|
||||
ret.get(), "__pyunointerface__",
|
||||
ustring2PyString(name).get() );
|
||||
}
|
||||
else
|
||||
@@ -186,23 +186,23 @@ static PyRef createClass( const OUString & name, const Runtime &runtime )
|
||||
PyRef eq = getObjectFromUnoModule( runtime,"_uno_struct__eq__" );
|
||||
|
||||
PyObject_SetAttrString(
|
||||
ret.get(), const_cast< char * >("__pyunostruct__"),
|
||||
ret.get(), "__pyunostruct__",
|
||||
ustring2PyString(name).get() );
|
||||
PyObject_SetAttrString(
|
||||
ret.get(), const_cast< char * >("typeName"),
|
||||
ret.get(), "typeName",
|
||||
ustring2PyString(name).get() );
|
||||
PyObject_SetAttrString(
|
||||
ret.get(), const_cast< char * >("__init__"), ctor.get() );
|
||||
ret.get(), "__init__", ctor.get() );
|
||||
PyObject_SetAttrString(
|
||||
ret.get(), const_cast< char * >("__getattr__"), getter.get() );
|
||||
ret.get(), "__getattr__", getter.get() );
|
||||
PyObject_SetAttrString(
|
||||
ret.get(), const_cast< char * >("__setattr__"), setter.get() );
|
||||
ret.get(), "__setattr__", setter.get() );
|
||||
PyObject_SetAttrString(
|
||||
ret.get(), const_cast< char * >("__repr__"), repr.get() );
|
||||
ret.get(), "__repr__", repr.get() );
|
||||
PyObject_SetAttrString(
|
||||
ret.get(), const_cast< char * >("__str__"), repr.get() );
|
||||
ret.get(), "__str__", repr.get() );
|
||||
PyObject_SetAttrString(
|
||||
ret.get(), const_cast< char * >("__eq__"), eq.get() );
|
||||
ret.get(), "__eq__", eq.get() );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -210,10 +210,10 @@ static PyRef createClass( const OUString & name, const Runtime &runtime )
|
||||
bool isInstanceOfStructOrException( PyObject *obj)
|
||||
{
|
||||
PyRef attr(
|
||||
PyObject_GetAttrString(obj, const_cast< char * >("__class__")),
|
||||
PyObject_GetAttrString(obj, "__class__"),
|
||||
SAL_NO_ACQUIRE );
|
||||
return PyObject_HasAttrString(
|
||||
attr.get(), const_cast< char * >("__pyunostruct__"));
|
||||
attr.get(), "__pyunostruct__");
|
||||
}
|
||||
|
||||
sal_Bool isInterfaceClass( const Runtime &runtime, PyObject * obj )
|
||||
@@ -233,11 +233,11 @@ PyRef getClass( const OUString & name , const Runtime &runtime)
|
||||
ret = createClass( name, runtime );
|
||||
cargo->exceptionMap[name] = ret;
|
||||
if( PyObject_HasAttrString(
|
||||
ret.get(), const_cast< char * >("__pyunointerface__") ) )
|
||||
ret.get(), "__pyunointerface__" ) )
|
||||
cargo->interfaceSet.insert( ret );
|
||||
|
||||
PyObject_SetAttrString(
|
||||
ret.get(), const_cast< char * >("__pyunointerface__"),
|
||||
ret.get(), "__pyunointerface__",
|
||||
ustring2PyString(name).get() );
|
||||
}
|
||||
else
|
||||
|
@@ -447,7 +447,7 @@ static PyObject *getTypeByName( PyObject *, PyObject *args )
|
||||
{
|
||||
char *name;
|
||||
|
||||
if (PyArg_ParseTuple (args, const_cast< char * >("s"), &name))
|
||||
if (PyArg_ParseTuple (args, "s", &name))
|
||||
{
|
||||
OUString typeName ( OUString::createFromAscii( name ) );
|
||||
TypeDescription typeDesc( typeName );
|
||||
@@ -479,7 +479,7 @@ static PyObject *getConstantByName( PyObject *, PyObject *args )
|
||||
{
|
||||
char *name;
|
||||
|
||||
if (PyArg_ParseTuple (args, const_cast< char * >("s"), &name))
|
||||
if (PyArg_ParseTuple (args, "s", &name))
|
||||
{
|
||||
OUString typeName ( OUString::createFromAscii( name ) );
|
||||
Runtime runtime;
|
||||
@@ -801,21 +801,21 @@ static PyObject *setCurrentContext( PyObject *, PyObject * args )
|
||||
|
||||
struct PyMethodDef PyUNOModule_methods [] =
|
||||
{
|
||||
{const_cast< char * >("getComponentContext"), getComponentContext, METH_VARARGS, NULL},
|
||||
{const_cast< char * >("_createUnoStructHelper"), reinterpret_cast<PyCFunction>(createUnoStructHelper), METH_VARARGS | METH_KEYWORDS, NULL},
|
||||
{const_cast< char * >("getTypeByName"), getTypeByName, METH_VARARGS, NULL},
|
||||
{const_cast< char * >("getConstantByName"), getConstantByName, METH_VARARGS, NULL},
|
||||
{const_cast< char * >("getClass"), getClass, METH_VARARGS, NULL},
|
||||
{const_cast< char * >("checkEnum"), checkEnum, METH_VARARGS, NULL},
|
||||
{const_cast< char * >("checkType"), checkType, METH_VARARGS, NULL},
|
||||
{const_cast< char * >("generateUuid"), generateUuid, METH_VARARGS, NULL},
|
||||
{const_cast< char * >("systemPathToFileUrl"), systemPathToFileUrl, METH_VARARGS, NULL},
|
||||
{const_cast< char * >("fileUrlToSystemPath"), fileUrlToSystemPath, METH_VARARGS, NULL},
|
||||
{const_cast< char * >("absolutize"), absolutize, METH_VARARGS | METH_KEYWORDS, NULL},
|
||||
{const_cast< char * >("isInterface"), isInterface, METH_VARARGS, NULL},
|
||||
{const_cast< char * >("invoke"), invoke, METH_VARARGS | METH_KEYWORDS, NULL},
|
||||
{const_cast< char * >("setCurrentContext"), setCurrentContext, METH_VARARGS, NULL},
|
||||
{const_cast< char * >("getCurrentContext"), getCurrentContext, METH_VARARGS, NULL},
|
||||
{"getComponentContext", getComponentContext, METH_VARARGS, NULL},
|
||||
{"_createUnoStructHelper", reinterpret_cast<PyCFunction>(createUnoStructHelper), METH_VARARGS | METH_KEYWORDS, NULL},
|
||||
{"getTypeByName", getTypeByName, METH_VARARGS, NULL},
|
||||
{"getConstantByName", getConstantByName, METH_VARARGS, NULL},
|
||||
{"getClass", getClass, METH_VARARGS, NULL},
|
||||
{"checkEnum", checkEnum, METH_VARARGS, NULL},
|
||||
{"checkType", checkType, METH_VARARGS, NULL},
|
||||
{"generateUuid", generateUuid, METH_VARARGS, NULL},
|
||||
{"systemPathToFileUrl", systemPathToFileUrl, METH_VARARGS, NULL},
|
||||
{"fileUrlToSystemPath", fileUrlToSystemPath, METH_VARARGS, NULL},
|
||||
{"absolutize", absolutize, METH_VARARGS | METH_KEYWORDS, NULL},
|
||||
{"isInterface", isInterface, METH_VARARGS, NULL},
|
||||
{"invoke", invoke, METH_VARARGS | METH_KEYWORDS, NULL},
|
||||
{"setCurrentContext", setCurrentContext, METH_VARARGS, NULL},
|
||||
{"getCurrentContext", getCurrentContext, METH_VARARGS, NULL},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
@@ -845,7 +845,7 @@ PyObject* PyInit_pyuno()
|
||||
void initpyuno()
|
||||
{
|
||||
PyEval_InitThreads();
|
||||
Py_InitModule (const_cast< char * >("pyuno"), PyUNOModule_methods);
|
||||
Py_InitModule ("pyuno", PyUNOModule_methods);
|
||||
}
|
||||
#endif /* PY_MAJOR_VERSION >= 3 */
|
||||
|
||||
|
@@ -74,7 +74,7 @@ namespace pyuno
|
||||
static PyTypeObject RuntimeImpl_Type =
|
||||
{
|
||||
PyVarObject_HEAD_INIT (&PyType_Type, 0)
|
||||
const_cast< char * >("pyuno_runtime"),
|
||||
"pyuno_runtime",
|
||||
sizeof (RuntimeImpl),
|
||||
0,
|
||||
(destructor) RuntimeImpl::del,
|
||||
@@ -138,7 +138,7 @@ static void getRuntimeImpl( PyRef & globalDict, PyRef &runtimeImpl )
|
||||
Reference< XInterface > () );
|
||||
}
|
||||
|
||||
globalDict = PyRef( PyModule_GetDict(PyImport_AddModule(const_cast< char * >("__main__"))));
|
||||
globalDict = PyRef( PyModule_GetDict(PyImport_AddModule("__main__")));
|
||||
|
||||
if( ! globalDict.is() ) // FATAL !
|
||||
{
|
||||
@@ -151,7 +151,7 @@ static void getRuntimeImpl( PyRef & globalDict, PyRef &runtimeImpl )
|
||||
static PyRef importUnoModule( ) throw ( RuntimeException )
|
||||
{
|
||||
// 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() )
|
||||
{
|
||||
PyRef excType, excValue, excTraceback;
|
||||
@@ -551,7 +551,7 @@ PyRef Runtime::any2PyObject (const Any &a ) const
|
||||
PyTuple_SetItem( args.get(), 0 , pymsg.getAcquired() );
|
||||
// the exception base functions want to have an "args" tuple,
|
||||
// which contains the message
|
||||
PyObject_SetAttrString( ret.get(), const_cast< char * >("args"), args.get() );
|
||||
PyObject_SetAttrString( ret.get(), "args", args.get() );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -626,7 +626,7 @@ static Sequence< Type > invokeGetTypes( const Runtime & r , PyObject * o )
|
||||
{
|
||||
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 );
|
||||
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
|
||||
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;
|
||||
if( PyString_Check( str.get() ) )
|
||||
{
|
||||
@@ -786,7 +786,7 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con
|
||||
}
|
||||
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();
|
||||
Reference< XMaterialHolder > holder( obj->members->xInvocation, UNO_QUERY );
|
||||
if( holder.is( ) )
|
||||
@@ -832,9 +832,9 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con
|
||||
{
|
||||
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;
|
||||
pyObject2Any( PyRef( PyObject_GetAttrString( o, const_cast< char * >("type") ), SAL_NO_ACQUIRE ) ) >>= t;
|
||||
pyObject2Any( PyRef( PyObject_GetAttrString( o, "type" ), SAL_NO_ACQUIRE ) ) >>= t;
|
||||
|
||||
try
|
||||
{
|
||||
|
@@ -147,7 +147,7 @@ PyRef getAnyClass( const Runtime & r )
|
||||
|
||||
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() ) )
|
||||
{
|
||||
throw RuntimeException(
|
||||
@@ -169,8 +169,8 @@ sal_Unicode PyChar2Unicode( PyObject *obj ) throw ( RuntimeException )
|
||||
Any PyEnum2Enum( PyObject *obj ) throw ( RuntimeException )
|
||||
{
|
||||
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);
|
||||
PyRef typeName( PyObject_GetAttrString( obj,"typeName" ), SAL_NO_ACQUIRE);
|
||||
PyRef value( PyObject_GetAttrString( obj, "value" ), SAL_NO_ACQUIRE);
|
||||
if( !PyString_Check( typeName.get() ) || ! PyString_Check( value.get() ) )
|
||||
{
|
||||
throw RuntimeException(
|
||||
@@ -226,7 +226,7 @@ Any PyEnum2Enum( PyObject *obj ) 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() ) )
|
||||
{
|
||||
throw RuntimeException(
|
||||
@@ -234,7 +234,7 @@ Type PyType2Type( PyObject * o ) throw(RuntimeException )
|
||||
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() );
|
||||
|
||||
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" ) );
|
||||
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() );
|
||||
PyDict_SetItemString( dict, "unotypes" , typesModule.get() );
|
||||
}
|
||||
|
Reference in New Issue
Block a user