pyuno_module.cxx (5c3821d8) pyuno_module.cxx (564d9007)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 211 unchanged lines hidden (view full) ---

220 if( !PyTuple_Check( args ) || PyTuple_Size( args) != 1 )
221 {
222 OStringBuffer buf;
223 buf.append( funcName ).append( ": expecting one string argument" );
224 PyErr_SetString( PyExc_RuntimeError, buf.getStr() );
225 return NULL;
226 }
227 PyObject *obj = PyTuple_GetItem( args, 0 );
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 211 unchanged lines hidden (view full) ---

220 if( !PyTuple_Check( args ) || PyTuple_Size( args) != 1 )
221 {
222 OStringBuffer buf;
223 buf.append( funcName ).append( ": expecting one string argument" );
224 PyErr_SetString( PyExc_RuntimeError, buf.getStr() );
225 return NULL;
226 }
227 PyObject *obj = PyTuple_GetItem( args, 0 );
228 if( !PyString_Check( obj ) && ! PyUnicode_Check(obj))
228 if( !PyBytes_Check( obj ) && ! PyUnicode_Check(obj))
229 {
230 OStringBuffer buf;
231 buf.append( funcName ).append( ": expecting one string argument" );
232 PyErr_SetString( PyExc_TypeError, buf.getStr());
233 return NULL;
234 }
235 return obj;
236}

--- 6 unchanged lines hidden (view full) ---

243 try
244 {
245 Runtime runtime;
246 if( PyTuple_Size( args ) == 2 )
247 {
248 PyObject *structName = PyTuple_GetItem( args,0 );
249 PyObject *initializer = PyTuple_GetItem( args ,1 );
250
229 {
230 OStringBuffer buf;
231 buf.append( funcName ).append( ": expecting one string argument" );
232 PyErr_SetString( PyExc_TypeError, buf.getStr());
233 return NULL;
234 }
235 return obj;
236}

--- 6 unchanged lines hidden (view full) ---

243 try
244 {
245 Runtime runtime;
246 if( PyTuple_Size( args ) == 2 )
247 {
248 PyObject *structName = PyTuple_GetItem( args,0 );
249 PyObject *initializer = PyTuple_GetItem( args ,1 );
250
251 if( PyString_Check( structName ) )
251 if( PyBytes_Check( structName ) )
252 {
253 if( PyTuple_Check( initializer ) )
254 {
252 {
253 if( PyTuple_Check( initializer ) )
254 {
255 OUString typeName( OUString::createFromAscii(PyString_AsString(structName)));
255 OUString typeName( OUString::createFromAscii(PyBytes_AsString(structName)));
256 RuntimeCargo *c = runtime.getImpl()->cargo;
257 Reference<XIdlClass> idl_class ( c->xCoreReflection->forName (typeName),UNO_QUERY);
258 if (idl_class.is ())
259 {
260 idl_class->createObject (IdlStruct);
261 PyUNO *me = (PyUNO*)PyUNO_new_UNCHECKED( IdlStruct, c->xInvocation );
262 PyRef returnCandidate( (PyObject*)me, SAL_NO_ACQUIRE );
263 if( PyTuple_Size( initializer ) > 0 )

--- 18 unchanged lines hidden (view full) ---

282 }
283 }
284 ret = returnCandidate;
285 }
286 else
287 {
288 OStringBuffer buf;
289 buf.append( "UNO struct " );
256 RuntimeCargo *c = runtime.getImpl()->cargo;
257 Reference<XIdlClass> idl_class ( c->xCoreReflection->forName (typeName),UNO_QUERY);
258 if (idl_class.is ())
259 {
260 idl_class->createObject (IdlStruct);
261 PyUNO *me = (PyUNO*)PyUNO_new_UNCHECKED( IdlStruct, c->xInvocation );
262 PyRef returnCandidate( (PyObject*)me, SAL_NO_ACQUIRE );
263 if( PyTuple_Size( initializer ) > 0 )

--- 18 unchanged lines hidden (view full) ---

282 }
283 }
284 ret = returnCandidate;
285 }
286 else
287 {
288 OStringBuffer buf;
289 buf.append( "UNO struct " );
290 buf.append( PyString_AsString(structName) );
290 buf.append( PyBytes_AsString(structName) );
291 buf.append( " is unkown" );
292 PyErr_SetString (PyExc_RuntimeError, buf.getStr());
293 }
294 }
295 else
296 {
297 PyErr_SetString(
298 PyExc_RuntimeError,

--- 159 unchanged lines hidden (view full) ---

458 PyObject *obj = extractOneStringArg( args, "pyuno.getClass");
459 if( ! obj )
460 return NULL;
461
462 try
463 {
464 Runtime runtime;
465 PyRef ret = getClass(
291 buf.append( " is unkown" );
292 PyErr_SetString (PyExc_RuntimeError, buf.getStr());
293 }
294 }
295 else
296 {
297 PyErr_SetString(
298 PyExc_RuntimeError,

--- 159 unchanged lines hidden (view full) ---

458 PyObject *obj = extractOneStringArg( args, "pyuno.getClass");
459 if( ! obj )
460 return NULL;
461
462 try
463 {
464 Runtime runtime;
465 PyRef ret = getClass(
466 OUString( PyString_AsString( obj), strlen(PyString_AsString(obj)),RTL_TEXTENCODING_ASCII_US),
466 OUString( PyBytes_AsString( obj), strlen(PyBytes_AsString(obj)),RTL_TEXTENCODING_ASCII_US),
467 runtime );
468 Py_XINCREF( ret.get() );
469 return ret.get();
470 }
471 catch( RuntimeException & e)
472 {
473 // NOOPT !!!
474 // gcc 3.2.3 crashes here in the regcomp test scenario

--- 123 unchanged lines hidden (view full) ---

598
599static PyObject * invoke ( PyObject *, PyObject * args )
600{
601 PyObject *ret = 0;
602 if( PyTuple_Check( args ) && PyTuple_Size( args ) == 3 )
603 {
604 PyObject *object = PyTuple_GetItem( args, 0 );
605
467 runtime );
468 Py_XINCREF( ret.get() );
469 return ret.get();
470 }
471 catch( RuntimeException & e)
472 {
473 // NOOPT !!!
474 // gcc 3.2.3 crashes here in the regcomp test scenario

--- 123 unchanged lines hidden (view full) ---

598
599static PyObject * invoke ( PyObject *, PyObject * args )
600{
601 PyObject *ret = 0;
602 if( PyTuple_Check( args ) && PyTuple_Size( args ) == 3 )
603 {
604 PyObject *object = PyTuple_GetItem( args, 0 );
605
606 if( PyString_Check( PyTuple_GetItem( args, 1 ) ) )
606 if( PyBytes_Check( PyTuple_GetItem( args, 1 ) ) )
607 {
607 {
608 const char *name = PyString_AsString( PyTuple_GetItem( args, 1 ) );
608 const char *name = PyBytes_AsString( PyTuple_GetItem( args, 1 ) );
609 if( PyTuple_Check( PyTuple_GetItem( args , 2 )))
610 {
611 ret = PyUNO_invoke( object, name , PyTuple_GetItem( args, 2 ) );
612 }
613 else
614 {
615 OStringBuffer buf;
616 buf.append( "uno.invoke expects a tuple as 3rd argument, got " );
609 if( PyTuple_Check( PyTuple_GetItem( args , 2 )))
610 {
611 ret = PyUNO_invoke( object, name , PyTuple_GetItem( args, 2 ) );
612 }
613 else
614 {
615 OStringBuffer buf;
616 buf.append( "uno.invoke expects a tuple as 3rd argument, got " );
617 buf.append( PyString_AsString( PyObject_Str( PyTuple_GetItem( args, 2) ) ) );
617 buf.append( PyBytes_AsString( PyObject_Str( PyTuple_GetItem( args, 2) ) ) );
618 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
619 }
620 }
621 else
622 {
623 OStringBuffer buf;
624 buf.append( "uno.invoke expected a string as 2nd argument, got " );
618 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
619 }
620 }
621 else
622 {
623 OStringBuffer buf;
624 buf.append( "uno.invoke expected a string as 2nd argument, got " );
625 buf.append( PyString_AsString( PyObject_Str( PyTuple_GetItem( args, 1) ) ) );
625 buf.append( PyBytes_AsString( PyObject_Str( PyTuple_GetItem( args, 1) ) ) );
626 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
627 }
628 }
629 else
630 {
631 OStringBuffer buf;
632 buf.append( "uno.invoke expects object, name, (arg1, arg2, ... )\n" );
633 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );

--- 33 unchanged lines hidden (view full) ---

667 if( (a.hasValue() && (a >>= context)) || ! a.hasValue() )
668 {
669 ret = com::sun::star::uno::setCurrentContext( context ) ? Py_True : Py_False;
670 }
671 else
672 {
673 OStringBuffer buf;
674 buf.append( "uno.setCurrentContext expects an XComponentContext implementation, got " );
626 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
627 }
628 }
629 else
630 {
631 OStringBuffer buf;
632 buf.append( "uno.invoke expects object, name, (arg1, arg2, ... )\n" );
633 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );

--- 33 unchanged lines hidden (view full) ---

667 if( (a.hasValue() && (a >>= context)) || ! a.hasValue() )
668 {
669 ret = com::sun::star::uno::setCurrentContext( context ) ? Py_True : Py_False;
670 }
671 else
672 {
673 OStringBuffer buf;
674 buf.append( "uno.setCurrentContext expects an XComponentContext implementation, got " );
675 buf.append( PyString_AsString( PyObject_Str( PyTuple_GetItem( args, 0) ) ) );
675 buf.append( PyBytes_AsString( PyObject_Str( PyTuple_GetItem( args, 0) ) ) );
676 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
677 }
678 }
679 else
680 {
681 OStringBuffer buf;
682 buf.append( "uno.setCurrentContext expects exactly one argument (the current Context)\n" );
683 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );

--- 28 unchanged lines hidden (view full) ---

712 {NULL, NULL, 0, NULL}
713};
714
715}
716
717extern "C" PY_DLLEXPORT void initpyuno()
718{
719 // noop when called already, otherwise needed to allow multiple threads
676 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
677 }
678 }
679 else
680 {
681 OStringBuffer buf;
682 buf.append( "uno.setCurrentContext expects exactly one argument (the current Context)\n" );
683 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );

--- 28 unchanged lines hidden (view full) ---

712 {NULL, NULL, 0, NULL}
713};
714
715}
716
717extern "C" PY_DLLEXPORT void initpyuno()
718{
719 // noop when called already, otherwise needed to allow multiple threads
720 // This has to be reworked for Python 3.
720 PyEval_InitThreads();
721 Py_InitModule (const_cast< char * >("pyuno"), PyUNOModule_methods);
722}
721 PyEval_InitThreads();
722 Py_InitModule (const_cast< char * >("pyuno"), PyUNOModule_methods);
723}