pyuno_module.cxx (564d9007) pyuno_module.cxx (77dc4149)
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 PY_MAJOR_VERSION >= 3
229 if( ! PyUnicode_Check(obj) )
230#else
228 if( !PyBytes_Check( obj ) && ! PyUnicode_Check(obj))
231 if( !PyBytes_Check( obj ) && ! PyUnicode_Check(obj))
232#endif
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
233 {
234 OStringBuffer buf;
235 buf.append( funcName ).append( ": expecting one string argument" );
236 PyErr_SetString( PyExc_TypeError, buf.getStr());
237 return NULL;
238 }
239 return obj;
240}

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

247 try
248 {
249 Runtime runtime;
250 if( PyTuple_Size( args ) == 2 )
251 {
252 PyObject *structName = PyTuple_GetItem( args,0 );
253 PyObject *initializer = PyTuple_GetItem( args ,1 );
254
251 if( PyBytes_Check( structName ) )
255 if( PYSTR_CHECK( structName ) )
252 {
253 if( PyTuple_Check( initializer ) )
254 {
256 {
257 if( PyTuple_Check( initializer ) )
258 {
255 OUString typeName( OUString::createFromAscii(PyBytes_AsString(structName)));
259 OUString typeName( pyString2ustring( 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 " );
260 RuntimeCargo *c = runtime.getImpl()->cargo;
261 Reference<XIdlClass> idl_class ( c->xCoreReflection->forName (typeName),UNO_QUERY);
262 if (idl_class.is ())
263 {
264 idl_class->createObject (IdlStruct);
265 PyUNO *me = (PyUNO*)PyUNO_new_UNCHECKED( IdlStruct, c->xInvocation );
266 PyRef returnCandidate( (PyObject*)me, SAL_NO_ACQUIRE );
267 if( PyTuple_Size( initializer ) > 0 )

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

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

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

457{
458 PyObject *obj = extractOneStringArg( args, "pyuno.getClass");
459 if( ! obj )
460 return NULL;
461
462 try
463 {
464 Runtime runtime;
295 buf.append( " is unkown" );
296 PyErr_SetString (PyExc_RuntimeError, buf.getStr());
297 }
298 }
299 else
300 {
301 PyErr_SetString(
302 PyExc_RuntimeError,

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

461{
462 PyObject *obj = extractOneStringArg( args, "pyuno.getClass");
463 if( ! obj )
464 return NULL;
465
466 try
467 {
468 Runtime runtime;
465 PyRef ret = getClass(
466 OUString( PyBytes_AsString( obj), strlen(PyBytes_AsString(obj)),RTL_TEXTENCODING_ASCII_US),
467 runtime );
469 PyRef ret = getClass( pyString2ustring(obj), 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
475 // only since migration to python 2.3.4 ???? strange thing

--- 122 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
470 Py_XINCREF( ret.get() );
471 return ret.get();
472 }
473 catch( RuntimeException & e)
474 {
475 // NOOPT !!!
476 // gcc 3.2.3 crashes here in the regcomp test scenario
477 // only since migration to python 2.3.4 ???? strange thing

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

600
601static PyObject * invoke ( PyObject *, PyObject * args )
602{
603 PyObject *ret = 0;
604 if( PyTuple_Check( args ) && PyTuple_Size( args ) == 3 )
605 {
606 PyObject *object = PyTuple_GetItem( args, 0 );
607
606 if( PyBytes_Check( PyTuple_GetItem( args, 1 ) ) )
608 if( PYSTR_CHECK( PyTuple_GetItem( args, 1 ) ) )
607 {
609 {
610#if PY_VERSION_HEX >= 0x03030000
611 const char *name = PyUnicode_AsUTF8( PyTuple_GetItem( args, 1 ) );
612#elif PY_MAJOR_VERSION >= 3
613 PyRef pUtf8(PyUnicode_AsUTF8String( PyTuple_GetItem( args, 1 ) ), SAL_NO_ACQUIRE);
614 const char *name = PyBytes_AsString( pUtf8.get() );
615#else
608 const char *name = PyBytes_AsString( PyTuple_GetItem( args, 1 ) );
616 const char *name = PyBytes_AsString( PyTuple_GetItem( args, 1 ) );
617#endif
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 " );
618 if( PyTuple_Check( PyTuple_GetItem( args , 2 )))
619 {
620 ret = PyUNO_invoke( object, name , PyTuple_GetItem( args, 2 ) );
621 }
622 else
623 {
624 OStringBuffer buf;
625 buf.append( "uno.invoke expects a tuple as 3rd argument, got " );
626#if PY_MAJOR_VERSION >= 3
627 buf.append( OUStringToOString( pyString2ustring( PyTuple_GetItem( args, 2 ) ), RTL_TEXTENCODING_ASCII_US) );
628#else
617 buf.append( PyBytes_AsString( PyObject_Str( PyTuple_GetItem( args, 2) ) ) );
629 buf.append( PyBytes_AsString( PyObject_Str( PyTuple_GetItem( args, 2) ) ) );
630#endif
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 " );
631 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
632 }
633 }
634 else
635 {
636 OStringBuffer buf;
637 buf.append( "uno.invoke expected a string as 2nd argument, got " );
638#if PY_MAJOR_VERSION >= 3
639 buf.append( OUStringToOString( pyString2ustring( PyTuple_GetItem( args, 1 ) ), RTL_TEXTENCODING_ASCII_US ) );
640#else
625 buf.append( PyBytes_AsString( PyObject_Str( PyTuple_GetItem( args, 1) ) ) );
641 buf.append( PyBytes_AsString( PyObject_Str( PyTuple_GetItem( args, 1) ) ) );
642#endif
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 " );
643 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
644 }
645 }
646 else
647 {
648 OStringBuffer buf;
649 buf.append( "uno.invoke expects object, name, (arg1, arg2, ... )\n" );
650 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );

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

684 if( (a.hasValue() && (a >>= context)) || ! a.hasValue() )
685 {
686 ret = com::sun::star::uno::setCurrentContext( context ) ? Py_True : Py_False;
687 }
688 else
689 {
690 OStringBuffer buf;
691 buf.append( "uno.setCurrentContext expects an XComponentContext implementation, got " );
692#if PY_MAJOR_VERSION >= 3
693 buf.append( OUStringToOString( pyString2ustring( PyTuple_GetItem( args, 0 ) ), RTL_TEXTENCODING_ASCII_US ) );
694#else
675 buf.append( PyBytes_AsString( PyObject_Str( PyTuple_GetItem( args, 0) ) ) );
695 buf.append( PyBytes_AsString( PyObject_Str( PyTuple_GetItem( args, 0) ) ) );
696#endif
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() );

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

689 }
690 return ret.getAcquired();
691}
692
693}
694
695struct PyMethodDef PyUNOModule_methods [] =
696{
697 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
698 }
699 }
700 else
701 {
702 OStringBuffer buf;
703 buf.append( "uno.setCurrentContext expects exactly one argument (the current Context)\n" );
704 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );

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

710 }
711 return ret.getAcquired();
712}
713
714}
715
716struct PyMethodDef PyUNOModule_methods [] =
717{
697 {const_cast< char * >("getComponentContext"), getComponentContext, 1, NULL},
698 {const_cast< char * >("_createUnoStructHelper"), createUnoStructHelper, 2, NULL},
699 {const_cast< char * >("getTypeByName"), getTypeByName, 1, NULL},
700 {const_cast< char * >("getConstantByName"), getConstantByName,1, NULL},
701 {const_cast< char * >("getClass"), getClass,1, NULL},
702 {const_cast< char * >("checkEnum"), checkEnum, 1, NULL},
703 {const_cast< char * >("checkType"), checkType, 1, NULL},
704 {const_cast< char * >("generateUuid"), generateUuid,0, NULL},
705 {const_cast< char * >("systemPathToFileUrl"),systemPathToFileUrl,1, NULL},
706 {const_cast< char * >("fileUrlToSystemPath"),fileUrlToSystemPath,1, NULL},
707 {const_cast< char * >("absolutize"),absolutize,2, NULL},
708 {const_cast< char * >("isInterface"),isInterface,1, NULL},
709 {const_cast< char * >("invoke"),invoke, 2, NULL},
710 {const_cast< char * >("setCurrentContext"),setCurrentContext,1, NULL},
711 {const_cast< char * >("getCurrentContext"),getCurrentContext,1, NULL},
718 {const_cast< char * >("getComponentContext"), getComponentContext, METH_NOARGS, NULL},
719 {const_cast< char * >("_createUnoStructHelper"), createUnoStructHelper, METH_VARARGS, NULL},
720 {const_cast< char * >("getTypeByName"), getTypeByName, METH_VARARGS, NULL},
721 {const_cast< char * >("getConstantByName"), getConstantByName, METH_VARARGS, NULL},
722 {const_cast< char * >("getClass"), getClass, METH_VARARGS, NULL},
723 {const_cast< char * >("checkEnum"), checkEnum, METH_VARARGS, NULL},
724 {const_cast< char * >("checkType"), checkType, METH_VARARGS, NULL},
725 {const_cast< char * >("generateUuid"), generateUuid, METH_NOARGS, NULL},
726 {const_cast< char * >("systemPathToFileUrl"), systemPathToFileUrl, METH_VARARGS, NULL},
727 {const_cast< char * >("fileUrlToSystemPath"), fileUrlToSystemPath, METH_VARARGS, NULL},
728 {const_cast< char * >("absolutize"), absolutize, METH_VARARGS, NULL},
729 {const_cast< char * >("isInterface"), isInterface, METH_VARARGS, NULL},
730 {const_cast< char * >("invoke"), invoke, METH_VARARGS, NULL},
731 {const_cast< char * >("setCurrentContext"), setCurrentContext, METH_VARARGS, NULL},
732 {const_cast< char * >("getCurrentContext"), getCurrentContext, METH_NOARGS, NULL},
712 {NULL, NULL, 0, NULL}
713};
714
733 {NULL, NULL, 0, NULL}
734};
735
736#if PY_MAJOR_VERSION >= 3
737static struct PyModuleDef PyUNOModule =
738{
739 PyModuleDef_HEAD_INIT,
740 const_cast< char * >("pyuno"),
741 NULL,
742 -1,
743 PyUNOModule_methods
744};
745#endif
715}
716
746}
747
748#if PY_MAJOR_VERSION >= 3
749extern "C" PyMODINIT_FUNC PyInit_pyuno(void)
750{
751 PyObject *m;
752
753 PyEval_InitThreads();
754
755 m = PyModule_Create(&PyUNOModule);
756 if (m == NULL)
757 return NULL;
758
759 if (PyType_Ready((PyTypeObject *)getPyUnoClass().get()))
760 return NULL;
761 return m;
762}
763#else
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.
721 PyEval_InitThreads();
722 Py_InitModule (const_cast< char * >("pyuno"), PyUNOModule_methods);
723}
764extern "C" PY_DLLEXPORT void initpyuno()
765{
766 // noop when called already, otherwise needed to allow multiple threads
767 // This has to be reworked for Python 3.
768 PyEval_InitThreads();
769 Py_InitModule (const_cast< char * >("pyuno"), PyUNOModule_methods);
770}
771#endif