Issue 80769

Summary: Macros will not be loaded if OOo is started with parameter
Product: General Reporter: oc
Component: codeAssignee: oc
Status: CLOSED FIXED QA Contact: issues@framework <issues>
Severity: Trivial    
Priority: P2 CC: issues, Mathias_Bauer
Version: 680m225Keywords: regression
Target Milestone: OOo 2.3   
Hardware: All   
OS: All   
Issue Type: DEFECT Latest Confirmation in: ---
Developer Difficulty: ---
Issue Depends on:    
Issue Blocks: 80294    
Attachments:
Description Flags
Bugdoc with macro
none
sugegsted patch none

Description oc 2007-08-17 07:39:10 UTC
Start OOo with parameter -enableautomation and load attached bugdoc => there is
no warning about the macro and the macro will not be loaded
Comment 1 oc 2007-08-17 07:41:38 UTC
Created attachment 47581 [details]
Bugdoc with macro
Comment 2 ab 2007-08-17 13:33:00 UTC
ab->as: According to gh -enableautomation is only used for low level things like 
different window manager handling for testtool. So the connection to macro
import is unclear. Anyway this is done in the framework. Please have a look.
Comment 3 oc 2007-08-21 13:37:37 UTC
cc'ing mba
Comment 4 Mathias_Bauer 2007-08-21 18:36:24 UTC
Frank, this is a problem with the basic code you added to binfilter. If any
non-binfilter document has been created before  the binfilter basic module is
dysfunctional. ("-enableautomation" errornouosly always creates an empty Writer
doc and so triggers the bug.)

The following code in binfilter/bf_basic/source/basmgr/basmgr.cxx:

BOOL BasicManager::HasBasicWithModules( const SotStorage& rStorage, const
String& rBaseURL )
{
	if( !rStorage.IsStream( ManagerStreamName ) )
        return FALSE;

    StarBASIC* pDummyParentBasic = new StarBASIC();
    BasicManager* pBasMgr = new BasicManager( (SotStorage&)rStorage, rBaseURL,
pDummyParentBasic );
    BOOL bRet = FALSE;

	USHORT nLibs = pBasMgr->GetLibCount();
	for( USHORT nL = 0; nL < nLibs; nL++ )
	{
		BasicLibInfo* pInfo = pBasMgr->pLibs->GetObject( nL );
		StarBASIC* pLib = pInfo->GetLib();
		if( !pLib )
        {
            BOOL bLoaded = pBasMgr->ImpLoadLibary( pInfo, NULL, FALSE );
            if( bLoaded )
                pLib = pInfo->GetLib();
        }
		if( pLib )
        {
	        SbxArray* pModules = pLib->GetModules();
            if( pModules->Count() ) // ***
            {
                bRet = TRUE;
                break;
            }
        }
    }

    delete pBasMgr;
    return bRet;
}

always returns "FALSE" in the marked code line when the bug is triggered. This
is different if the binary document is the first to be loaded.

This reminds me of a problem with SHL_PTR in Basic but AFAIR it was fixed by
Carsten. So it seems that there is another global variable that is shared
between binfilter's basic and the "other one".

In result basic from binary files is always lost as soon as the first non-binary
file was loaded. I have no idea if this is a showstopper but surely it's a
regression.
Comment 5 Mathias_Bauer 2007-08-21 18:43:47 UTC
I found binfilter/bf_basic/source/sbx/sbxbase.cxx:

SbxAppData* GetSbxData_Impl()
{
#ifndef DOS
	SbxAppData** ppData = (SbxAppData**) ::GetAppData( SHL_SBX );
	SbxAppData* p = *ppData;
	if( !p )
		p = *ppData  = new SbxAppData;
	return p;
#else
	SbxAppData** ppData;
	SbxAppData* p;
	p = *ppData  = new SbxAppData;
	return p;
#endif
}

That looks as if the "SHL_PTR" bug is not or only partially fixed.
Comment 6 Mathias_Bauer 2007-08-21 19:01:37 UTC
This is the killer - together with another bug:

StarBASIC::StarBASIC( StarBASIC* p )
	: SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASIC") ) )
{
	SetParent( p );
	pLibInfo = NULL;
	bNoRtl = bBreak = FALSE;
	pModules = new SbxArray;

	if( !GetSbData()->nInst++ ) // ***
	{
		pSBFAC = new SbiFactory;
		AddFactory( pSBFAC );
		pUNOFAC = new SbUnoFactory;
		AddFactory( pUNOFAC );
		pTYPEFAC = new SbTypeFactory;
		AddFactory( pTYPEFAC );
		pCLASSFAC = new SbClassFactory;
		AddFactory( pCLASSFAC );
		pOLEFAC = new SbOLEFactory;
		AddFactory( pOLEFAC );
	}
//	pRtl = new SbiStdObject( String( RTL_CONSTASCII_USTRINGPARAM(RTLNAME) ), this );
	// Suche ueber StarBASIC ist immer global
	SetFlag( SBX_GBLSEARCH );
}

The marked line is an object that is shared between binfilter and "the other
code". So as soon as the first "sb" instance is created elsewhere binfilter
refuses to instantiate its own SbxFactories. So even fixing the first problem
(replacing SHL_PTR by a static pointer) is not enough. We need an own instance
counter for binfilter:

SbiGlobals* GetSbData()
{
	SbiGlobals** pp = (SbiGlobals**) ::GetAppData( SHL_SBC );
	SbiGlobals* p = *pp;
	if( !p )
		p = *pp = new SbiGlobals;
	return p;
}

is the culprit - again a SHL_PTR problem. 

grepping for "SHL_" in bf_basic showed me more of them. :-(
So I'm afraid that this will take some more work to do.
Comment 7 Mathias_Bauer 2007-08-21 19:07:48 UTC
I was too pessimistic. :-)
All occurrences where either includes or code that was commented out. :-)

So fixing the quoted methods is enough. Frank, please comment.

Oliver, what about the target?
Comment 8 Frank Schönheit 2007-08-21 20:18:43 UTC
Excellent analysis, I'd say. Going to attach a patch.

Oliver, this patch can go into any version you like ... I'd fix this for 2.4,
but if you need it earlier, tell me. (Though, the bug exists for quite a while
now, and has never been noticed so far, so I assume it isn't that urgent.)
Comment 9 Frank Schönheit 2007-08-21 20:21:09 UTC
Created attachment 47694 [details]
sugegsted patch
Comment 10 Mathias_Bauer 2007-08-22 07:31:10 UTC
Thanks, Frank.

Oliver, as Frank pointed out this issue is not new but IIRC it was not present
in 2.2.x so it is a regression.
In case Christian Guenther didn't complain we could add the patch to the CWS
binfilterregression though it is already "ready for QA". Perhaps you can
negotiate with Christian.
Comment 11 oc 2007-08-22 07:53:09 UTC
adjusting prio and target 2.3
Comment 12 Frank Schönheit 2007-08-22 08:21:55 UTC
fix committed in CWS bfbasic
Comment 13 Frank Schönheit 2007-08-22 08:55:53 UTC
fs-> oc: please verify in CWS bfbasic
Comment 14 oc 2007-08-23 08:21:29 UTC
verified in internal build cws_bfbasic
Comment 15 oc 2008-02-12 10:39:05 UTC
closed because fix available in builds OOH680_m7 (OOo 2.4) and SRC680_m245 (OOo 3.0)