Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2012-10

Unwanted finalization

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ludo Brands

Dear all,

In comobj.pp I'm getting sometimes a SIGSEGV in the following code:

    function TAutoObject.Invoke(DispID: LongInt; const iid: TGUID;
      LocaleID: longint; Flags: Word; var params; VarResult, ExcepInfo,
      ArgErr: pointer): HResult; stdcall;
	...
      begin
	...
          Result := TAutoObjectFactory(Factory).DispTypeInfo.Invoke(Pointer(
            PtrUint(Self) +

TAutoObjectFactory(Factory).DispIntfEntry^.IOffset), DispID, Flags, TDispParams(Params), PVariant(VarResult)^, PExcepInfo(ExcepInfo)^, PUINT(ArgErr)^);
...

	end;
The interface method called (ITypeInfo::Invoke) is defined in activex.pp as
     Function  Invoke(pvInstance: Pointer; memid: MEMBERID; wFlags: WORD;
VAR pDispParams: DISPPARAMS; OUT pVarResult: VARIANT; OUT pExcepInfo:
EXCEPINFO; OUT puArgErr: UINT):HResult;StdCall;

The problem is with the ExcepInfo parameter which is a record. ITypeInfo::Invoke can have a null pExcepInfo parameter and the PExcepInfo(ExcepInfo)^ cast causes a call to fpc_finalize with a null pointer.

Is there a way to avoid the finalisation of PExcepInfo(ExcepInfo)^ ? EXCEPINFO has a widestring member...

IMO the ITypeInfo::Invoke method should be changed to

     Function  Invoke(pvInstance: Pointer; memid: MEMBERID; wFlags: WORD;

VAR pDispParams: DISPPARAMS; pVarResult: PVARIANT; pExcepInfo: PEXCEPINFO; puArgErr: PUINT):HResult;StdCall;
but that requires changing all the code that calls this method. On the other hand I'm afraid that any code calling this method with the current definition will have potentially the same problem with the finalization of the EXCEPINFO record.

Ludo

Reply by email

Yury Sidorov
to Ludo Brands

Hi,

Funny, but I have also encountered the problem in this place yesterday :) But with PVariant(VarResult)^ in my case.
Yes, the declaration of ITypeInfo.Invoke() should be changed to eliminate unwanted compiler magic with managed types when a nil is passed.
I'll commit the required changes today or tomorrow.

Best Regards!

Yury Sidorov.

Earlier message 58 lines
----- Original Message ----- From: "Ludo Brands" To: "'FPC developers' list'" Sent: Saturday, October 13, 2012 6:34 PM Subject: [fpc-devel] Unwanted finalization Dear all, In comobj.pp I'm getting sometimes a SIGSEGV in the following code: function TAutoObject.Invoke(DispID: LongInt; const iid: TGUID; LocaleID: longint; Flags: Word; var params; VarResult, ExcepInfo, ArgErr: pointer): HResult; stdcall; ... begin ... Result := TAutoObjectFactory(Factory).DispTypeInfo.Invoke(Pointer( PtrUint(Self) + TAutoObjectFactory(Factory).DispIntfEntry^.IOffset), DispID, Flags, TDispParams(Params), PVariant(VarResult)^, PExcepInfo(ExcepInfo)^, PUINT(ArgErr)^); ... end; The interface method called (ITypeInfo::Invoke) is defined in activex.pp as Function Invoke(pvInstance: Pointer; memid: MEMBERID; wFlags: WORD; VAR pDispParams: DISPPARAMS; OUT pVarResult: VARIANT; OUT pExcepInfo: EXCEPINFO; OUT puArgErr: UINT):HResult;StdCall; The problem is with the ExcepInfo parameter which is a record. ITypeInfo::Invoke can have a null pExcepInfo parameter and the PExcepInfo(ExcepInfo)^ cast causes a call to fpc_finalize with a null pointer. Is there a way to avoid the finalisation of PExcepInfo(ExcepInfo)^ ? EXCEPINFO has a widestring member... IMO the ITypeInfo::Invoke method should be changed to Function Invoke(pvInstance: Pointer; memid: MEMBERID; wFlags: WORD; VAR pDispParams: DISPPARAMS; pVarResult: PVARIANT; pExcepInfo: PEXCEPINFO; puArgErr: PUINT):HResult;StdCall; but that requires changing all the code that calls this method. On the other hand I'm afraid that any code calling this method with the current definition will have potentially the same problem with the finalization of the EXCEPINFO record. Ludo

Reply by email

Jonas Maebe
to Yury Sidorov
Yury Sidorov wrote
Funny, but I have also encountered the problem in this place yesterday :) But with PVariant(VarResult)^ in my case. Yes, the declaration of ITypeInfo.Invoke() should be changed to eliminate unwanted compiler magic with managed types when a nil is passed. I'll commit the required changes today or tomorrow.

Can't you add an overloaded version to avoid breaking backward compatibility? Or does this problem occur all the time, so that it's better to break compilation than have people hunt all over the source code to find all possible problem locations?

Jonas

Reply by email

Yury Sidorov
to Jonas Maebe

Hello,

The declaration of ITypeInfo.Invoke() is broken now anyway. Some of out parametrs should accept nil values and it is not possible with the current declaration. I doubt that ITypeInfo.Invoke() is used directly by user code. Especially in this broken form.

Yury Sidorov,

Earlier message 26 lines
----- Original Message ----- From: "Jonas Maebe" To: "FPC developers' list" Sent: Saturday, October 13, 2012 7:05 PM Subject: Re: [fpc-devel] Unwanted finalization On 13 Oct 2012, at 18:01, Yury Sidorov wrote: > Funny, but I have also encountered the problem in this place > yesterday :) But with PVariant(VarResult)^ in my case. > Yes, the declaration of ITypeInfo.Invoke() should be changed to > eliminate unwanted compiler magic with managed types when a nil is > passed. > I'll commit the required changes today or tomorrow. Can't you add an overloaded version to avoid breaking backward compatibility? Or does this problem occur all the time, so that it's better to break compilation than have people hunt all over the source code to find all possible problem locations? Jonas_______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Ludo Brands
to Yury Sidorov
Show quoted text 8 lines
Hello, The declaration of ITypeInfo.Invoke() is broken now anyway. Some of out parametrs should accept nil values and it is not possible with the current declaration. I doubt that ITypeInfo.Invoke() is used directly by user code. Especially in this broken form.

I completely agree. According the MSDN the last 3 out parametes can be nil.

Attached is the patch that works for me. I'm writing a fpc COM server called with late binding from PHP.

Ludo

Reply by email

Marco van de Voort
to Jonas Maebe: Can't you add an overloaded version to avoid breaking backward compatibility? Or does…

In our previous episode, Jonas Maebe said:

Show quoted text 6 lines
> Funny, but I have also encountered the problem in this place yesterday :) But with PVariant(VarResult)^ in my case. > Yes, the declaration of ITypeInfo.Invoke() should be changed to eliminate unwanted compiler magic with managed types when a nil is passed. > I'll commit the required changes today or tomorrow. Can't you add an overloaded version to avoid breaking backward compatibility?

Afaik there is no overloading in interfaces?

Or does this problem occur all the time, so that it's better to break compilation than have people hunt all over the source code to find all possible problem locations?

I also don't think this is used that much. Afaik 2.6.0 is the first release with most of the autoobject and activex stuff merged back.

So if there is a change needed, better do it asap.

Reply by email

Yury Sidorov
to Ludo Brands: I completely agree. According the MSDN the last 3 out parametes can be nil. Attached is…

Committed in r22638. Thanks.

Earlier message 35 lines
----- Original Message ----- From: "Ludo Brands" To: "'FPC developers' list'" Sent: Saturday, October 13, 2012 7:26 PM Subject: Re: [fpc-devel] Unwanted finalization > Hello, > > The declaration of ITypeInfo.Invoke() is broken now anyway. Some of > out parametrs should accept nil values and it is not possible > with the > current declaration. I doubt that ITypeInfo.Invoke() is used > directly > by user code. Especially in this broken form. > I completely agree. According the MSDN the last 3 out parametes can be nil. Attached is the patch that works for me. I'm writing a fpc COM server called with late binding from PHP. Ludo -------------------------------------------------------------------------------- > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel >

Reply by email