Issue 120458 - [PyUNO] freeze on calling methods of method node of Basic (basprov::BasicMethodNodeImpl)
Summary: [PyUNO] freeze on calling methods of method node of Basic (basprov::BasicMeth...
Status: CONFIRMED
Alias: None
Product: App Dev
Classification: Unclassified
Component: scripting (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: All All
: P3 Normal
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-03 16:35 UTC by hanya
Modified: 2013-07-12 09:26 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Proposed patch to fix this problem (27.25 KB, patch)
2013-03-18 11:26 UTC, hanya
no flags Details | Diff
Unittest script for the attached patch (6.42 KB, text/x-python)
2013-03-18 11:30 UTC, hanya
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description hanya 2012-08-03 16:35:58 UTC
When I try to list method names in Basic module using script provider which 
can be taken from document model by css.script.provider.XScriptProviderSupplier interface.

It seems this problem is based on NULL invocation kept by pyuno instance. 
Here is the result from gdb, first line is the result of print(method_node): 
pyuno object (com.sun.star.script.browse.XBrowseNode)0x-4f7d2bdc{, supportedInterfaces={com.sun.star.script.browse.XBrowseNode,com.sun.star.script.XInvocation,com.sun.star.lang.XTypeProvider,com.sun.star.uno.XWeak,com.sun.star.beans.XPropertySet,com.sun.star.beans.XFastPropertySet,com.sun.star.beans.XMultiPropertySet}}

Program received signal SIGSEGV, Segmentation fault.
0x0608b91e in pyuno::PyUNO_getattr (self=0xb0c5f8b0, name=0x838fa74 "getType")
    at /mnt/hd/ooo/main/pyuno/source/module/pyuno.cxx:499
warning: Source file is more recent than executable.
499	        if (me->members->xInvocation->hasMethod (attrName))
(gdb) p me
$1 = (pyuno::PyUNO *) 0xb0c5f8b0
(gdb) p me->members
$2 = (pyuno::PyUNOInternals *) 0xb0852648
(gdb) p me->members->xInvocation
$3 = {<com::sun::star::uno::BaseReference> = {
    _pInterface = 0x0}, <No data fields>}


# python macro to reproduce the problem

def create(ctx, name, args=None):
    smgr = ctx.getServiceManager()
    if args is None:
        return smgr.createInstanceWithContext(name, ctx)
    else:
        return smgr.createInstanceWithArgumentsAndContext(name, args, ctx)

def get_basic_macros_provider(ctx, context):
    return create(ctx, "com.sun.star.script.provider.ScriptProviderForBasic", (context,))


def get_list_of_macros(sp):
    macros = []
    for lib_node in sp.getChildNodes():
        print(lib_node.getName())
        for module_node in lib_node.getChildNodes():
            print(module_node.getName())
            for method_node in module_node.getChildNodes():
                print(method_node)
                #print(dir(method_node))
                print(method_node.getType()) # segmentation fault
                #macros.append(method_node.getName(), method_node.getPropertyValue("URI"))
    return macros

def test(*args):
    ctx = XSCRIPTCONTEXT.getComponentContext()
    doc = XSCRIPTCONTEXT.getDocument()
    
    #sp = get_document_basic_macros_provider(ctx, doc)
    sp = get_basic_macros_provider(ctx, "user")
    macros = get_list_of_macros(sp)
    print(macros)
Comment 1 hanya 2012-08-03 17:13:44 UTC
If target which supports css.script.XInvocation interface passed 
to make invocation bridge by css.script.Invocation, 
calling methods of XInvocation and XInvocation2 are delegated to the target.

basprov::BasicMethodNodeImpl implements css.script.XInvocation to execute macros 
but not for adaption use and XInvocation2 is not implemented.
In PyUNO_new_UNCHECKED, Reference<XInvocation2> tmp_invocation (tmp_interface, UNO_QUERY); 
will keep invalid reference to the interface.
Comment 2 hanya 2012-08-03 17:26:36 UTC
Here is the workaround: 

def get_list_of_macros(ctx, sp):
    introspection = create(ctx, "com.sun.star.beans.Introspection")
    macros = []
    for lib_node in sp.getChildNodes():
        print(lib_node.getName())
        for module_node in lib_node.getChildNodes():
            print(module_node.getName())
            for method_node in module_node.getChildNodes():
                d = None
                inspected = introspection.inspect(method_node)
                idl_getName = inspected.getMethod("getName", -1)
                idl_getPropertyValue = inspected.getMethod("getPropertyValue", -1)
                name, d = idl_getName.invoke(method_node, ())
                uri, d = idl_getPropertyValue.invoke(method_node, ("URI",))
                macros.append((name, uri))
                #macros.append(method_node.getName(), method_node.getPropertyValue("URI"))
    return macros
Comment 3 hanya 2013-03-18 11:26:33 UTC
Created attachment 80423 [details]
Proposed patch to fix this problem

This patch provides fixes: 
If self->members->xInvocation is not valid reference in PyUNO_new_UNCHECKED function, 
introspection mechanism is used to call method and to get property values. 
To get list of methods and properties is also requires this switching.

It seems this way is used in Basic runtime.
Comment 4 hanya 2013-03-18 11:30:00 UTC
Created attachment 80424 [details]
Unittest script for the attached patch

Place this python script into user's profile/Scripts/python and 
execute function "execute_unittest" through Python script organizer. 
The result will be shown in new Writer document.
This test uses some unittest functions introduced on Pytho 2.7, so it does not work with Python 2.6.X.
Comment 5 hanya 2013-07-12 09:26:07 UTC
The attached patch should be tested on current version. 
And also, it is better if pyuno and callable struct are redesigned.