Freebasic 1.20.0 Development

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
fxm
Moderator
Posts: 12498
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Freebasic 1.20.0 Development

Post by fxm »

fan2006 wrote: Oct 29, 2024 1:43

Code: Select all

   Dim As String syspath = GetSystemPath(CSIDL_SYSTEM)
   Dim As String windir = GetSystemPath(CSIDL_WINDOWS)
   Print syspath
   Print windir
   Print windir & "notepad.exe "& syspath & "drivers\etc\hosts"
the code works well to output the hosts file path with fb 1.10.1 but & operator does not work with fb 1.20。

What should be included to compile this code above?
Otherwise, are you using the latest fbc 1.20 version (https://users.freebasic-portal.de/stw/builds/)?
fan2006
Posts: 32
Joined: Jun 07, 2020 3:05

Re: Freebasic 1.20.0 Development

Post by fan2006 »

it's my fault.I didn't got new new changes with string type. i just upgrade to fb 1.20 today.everything goes well now. thx .
fxm
Moderator
Posts: 12498
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Freebasic 1.20.0 Development

Post by fxm »

REDIM syntax bug in working version 1.20, for a procedure pointer array member and its access via pointer

Only for a procedure pointer array member and the REDIM instruction, accessing the array name via an instance pointer does not work anymore since the working-version 1.20 ("syntax error").
That works with the last official version 1.10.
No problem with LBOUND/UBOUND or ERASE.

Example:

Code: Select all

Type UDT
    Dim As Integer i(Any)
    Dim As Sub() s(Any)
End Type

Dim As UDT u : Dim As UDT Ptr pu = @u

Redim u.i(0)
Redim u.s(0)

Redim pu->i(0)
Redim pu->s(0)    '' error 17: Syntax error, found '(' in 'Redim pu->s(0)' (with fbc version 1.20)
Redim (pu->s)(0)  '' error 17: Syntax error, found '(' in 'Redim (pu->s)(0)' (with fbc version 1.20)

Workaround from UDT pointer only:

Code: Select all

With *pu
    Redim .i(0)
    Redim .s(0)
End With
coderJeff
Site Admin
Posts: 4377
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Freebasic 1.20.0 Development

Post by coderJeff »

fxm wrote: Nov 16, 2024 21:24 REDIM syntax bug in working version 1.20, for a procedure pointer array member and its access via pointer
...
No problem with LBOUND/UBOUND or ERASE.
Hey there, fxm. Thanks for the report. I looked at this yesterday because it reminded me of a different bug I was looking at - a syntax problem with indexed PROPERTY arrays returning byref objects and getting confused parsing parens - but it is not related.

Yes, there is no problem with LBOUND/UBOUND or ERASE because the parser never expects any left paren '(' after the array name or array expression name, so there is no ambiguity.

There is ambiguity with REDIM because the paren '(' could either be a continuation of the array expression as an array index or the beginning of the '(lower [to upper])' bounds.

I experimented with fixing this REDIM bug and I believe only way to fix will be allowing syntax using parens to wrap the array expression.
REDIM (array-expression-name)(lower [to upper])
Probably within the context of parsing REDIM specifically, because I think used anywhere else the array-expression-name should expect index to follow (except LBOUND/UBOUND or ERASE)
fxm
Moderator
Posts: 12498
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Freebasic 1.20.0 Development

Post by fxm »

Thanks, but why does this work with all array types, except specifically procedure pointer arrays (otherwise it works with string pointer arrays for example) ?
coderJeff
Site Admin
Posts: 4377
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Freebasic 1.20.0 Development

Post by coderJeff »

Similar to this:

Code: Select all

type A
	dim as integer x(any)
end type

type B
	dim as A y(any) 
end type

dim z as B

redim z.y(0).x(0)    '' error 3: Expected End-of-Line, found '.' in 'redim z.y(0).x(0)'
redim (z.y(0)).x(0)  '' error 73: Array access, index expected, found '(' in 'redim (z.y(0)).x(0)'
redim (z.y(0).x)(0)  '' OK
The parser doesn't know how much expression to parse before it has found the final name of the array. I think in the case of the procedure pointer, there must be checks missing telling the parser either what to expect next or what to accept, or both. At the moment I don't fully know the exact problem with procedure pointers.
fxm
Moderator
Posts: 12498
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Freebasic 1.20.0 Development

Post by fxm »

fxm wrote: Nov 16, 2024 21:24 REDIM syntax bug in working version 1.20, for a procedure pointer array member and its access via pointer

Only for a procedure pointer array member and the REDIM instruction, accessing the array name via an instance pointer does not work anymore since the working-version 1.20 ("syntax error").
That works with the last official version 1.10.
No problem with LBOUND/UBOUND or ERASE.

Example:

Code: Select all

Type UDT
    Dim As Integer i(Any)
    Dim As Sub() s(Any)
End Type

Dim As UDT u : Dim As UDT Ptr pu = @u

Redim u.i(0)
Redim u.s(0)

Redim pu->i(0)
Redim pu->s(0)    '' error 17: Syntax error, found '(' in 'Redim pu->s(0)' (with fbc version 1.20)
Redim (pu->s)(0)  '' error 17: Syntax error, found '(' in 'Redim (pu->s)(0)' (with fbc version 1.20)

Workaround from UDT pointer only:

Code: Select all

With *pu
    Redim .i(0)
    Redim .s(0)
End With

'Redim (*pu).i(0)', 'Redim ((*pu).i)(0)', 'Redim (*pu).s(0)', and 'Redim ((*pu).s)(0)' do not work also (whatever fbc version).

Another workaround from UDT pointer only:

Code: Select all

Dim Byref As UDT ru = *pu
Redim ru.i(0)
Redim ru.s(0)
fxm
Moderator
Posts: 12498
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Freebasic 1.20.0 Development

Post by fxm »

coderJeff
Site Admin
Posts: 4377
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Freebasic 1.20.0 Development

Post by coderJeff »

I recently merged in this pull request by SkyFish https://github.com/freebasic/fbc/pull/427
and here is my reason:

There's a couple of interesting things going on in this change that I can see from the changes in source and the submitted example, though to be honest I don't for certain know the full intent of the goal. But after more than 6 months and no other has reviewed the change, I merged in to the main development branch 1.20.0 so that others can play around with this.

- Supports optimizing purely abstract types, and only preserve used pure abstract types
- feature is enabled by '-z optabstract'

It appears to me to be like a 'typelib' or one part of implementing interfaces implemented through 'ABSTRACT'. But I can't tell if that is the whole intent. Seems like there should be another modifier for TYPE rather than relying on the '-z optabstract' command line option.
Josep Roca
Posts: 594
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Freebasic 1.20.0 Development

Post by Josep Roca »

How can we make comments if we are not clear about what these changes do?

To implement abstract methods declarations to external COM servers, I have been using:

Code: Select all

#ifndef __Afx_IUnknown_INTERFACE_DEFINED__
#define __Afx_IUnknown_INTERFACE_DEFINED__
TYPE Afx_IUnknown AS Afx_IUnknown_
TYPE Afx_IUnknown_ EXTENDS OBJECT
	DECLARE ABSTRACT FUNCTION QueryInterface (BYVAL riid AS REFIID, BYVAL ppvObject AS LPVOID PTR) AS HRESULT
	DECLARE ABSTRACT FUNCTION AddRef () AS ULONG
	DECLARE ABSTRACT FUNCTION Release () AS ULONG
END TYPE
TYPE AFX_LPUNKNOWN AS Afx_IUnknown PTR
#endif

#ifndef __Afx_IDispatch_INTERFACE_DEFINED__
#define __Afx_IDispatch_INTERFACE_DEFINED__
TYPE Afx_IDispatch AS Afx_IDispatch_
TYPE Afx_IDispatch_  EXTENDS Afx_IUnknown
   DECLARE ABSTRACT FUNCTION GetTypeInfoCount (BYVAL pctinfo AS UINT PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION GetTypeInfo (BYVAL iTInfo AS UINT, BYVAL lcid AS LCID, BYVAL ppTInfo AS ITypeInfo PTR PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION GetIDsOfNames (BYVAL riid AS CONST IID CONST PTR, BYVAL rgszNames AS LPOLESTR PTR, BYVAL cNames AS UINT, BYVAL lcid AS LCID, BYVAL rgDispId AS DISPID PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION Invoke (BYVAL dispIdMember AS DISPID, BYVAL riid AS CONST IID CONST PTR, BYVAL lcid AS LCID, BYVAL wFlags AS WORD, BYVAL pDispParams AS DISPPARAMS PTR, BYVAL pVarResult AS VARIANT PTR, BYVAL pExcepInfo AS EXCEPINFO PTR, BYVAL puArgErr AS UINT PTR) AS HRESULT
END TYPE
TYPE AFX_LPDISPATCH AS Afx_IDispatch PTR
#endif

Code: Select all

' ########################################################################################
' Interface name = IDictionary
' IID = {42C642C1-97E1-11CF-978F-00A02463E06F}
' Attributes = 4176 [&H1050] [Hidden] [Dual] [Dispatchable]
' Inherited interface = IDispatch
' ########################################################################################

#ifndef __Afx_IDictionary_INTERFACE_DEFINED__
#define __Afx_IDictionary_INTERFACE_DEFINED__

TYPE Afx_IDictionary_ EXTENDS Afx_IDispatch
   DECLARE ABSTRACT FUNCTION putref_Item (BYVAL vKey AS VARIANT PTR, BYVAL vNewItem AS VARIANT PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION put_Item (BYVAL vKey AS VARIANT PTR, BYVAL vNewItem AS VARIANT PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION get_Item (BYVAL vKey AS VARIANT PTR, BYVAL vRetItem AS VARIANT PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION Add (BYVAL vKey AS VARIANT PTR, BYVAL vItem AS VARIANT PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION get_Count (BYVAL pCount AS long PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION Exists (BYVAL vKey AS VARIANT PTR, BYVAL pExists AS SHORT PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION Items (BYVAL pItemsArray AS VARIANT PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION put_Key (BYVAL vKey AS VARIANT PTR, BYVAL vItem AS VARIANT PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION Keys (BYVAL pKeysArray AS VARIANT PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION Remove (BYVAL vKey AS VARIANT PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION RemoveAll () AS HRESULT
   DECLARE ABSTRACT FUNCTION put_CompareMode (BYVAL pcomp AS COMPAREMETHOD) AS HRESULT
   DECLARE ABSTRACT FUNCTION get_CompareMode (BYVAL pcomp AS COMPAREMETHOD PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION get__NewEnum (BYVAL ppunk AS Afx_IUnknown PTR PTR) AS HRESULT
   DECLARE ABSTRACT FUNCTION get_HashVal (BYVAL vKey AS VARIANT PTR, BYVAL HashVal AS VARIANT PTR) AS HRESULT
END TYPE

TYPE AFX_LPDICTIONARY AS Afx_IDictionary PTR

#endif
Last edited by Josep Roca on Jan 26, 2025 16:42, edited 1 time in total.
Josep Roca
Posts: 594
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Freebasic 1.20.0 Development

Post by Josep Roca »

And when implementing my own class, I add the keyword PRIVATE so that the code for the unused methods is not included in the executable. Maybe this is what the proposed modification intends to do? Doing what PRIVATE does, but not including this keyword as a prefix of the function?

e.g.

Code: Select all

' ========================================================================================
' Returns a counted reference to the hosted ActiveX control dispatch interface.
' You must call IUnknown_Release when no longer need it.
' ========================================================================================
PRIVATE FUNCTION CAxHost.OcxDispObj () AS IDispatch PTR
   IF m_pOcx <> NULL THEN
      m_pOcx->lpvtbl->AddRef(m_pOcx)
      RETURN m_pOcx
   END IF
END FUNCTION
' ========================================================================================
Adding PRIVATE, if the OcxDispObj method is never called, the code won't be included in the executable.

BTW PRIVATE works with all kind of procedures for dead code removal, not just with abstract methods.
coderJeff
Site Admin
Posts: 4377
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Freebasic 1.20.0 Development

Post by coderJeff »

Josep Roca wrote: Jan 26, 2025 16:28 How can we make comments if we are not clear about what these changes do?
Commenting on issues and pull requests is available to anyone logged in at github. A number of times in the past when I comment on pull requests, the author just closes ticket and abandons the effort, so trying to go a different way this time since I could not figure this one out on my own.
Josep Roca wrote: Jan 26, 2025 16:41 And when implementing my own class, I add the keyword PRIVATE so that the code for the unused methods is not included in the executable. Maybe this is what the proposed modification intends to do? Doing what PRIVATE does, but not including this keyword as a prefix of the function?
That makes sense. Thanks, does seems like a likely goal of the change. I had originally thought this may have to do with errors related to unimplemented abstract methods, even if the class is never references, but I didn't build a test case yet.

One thing that caught my interest (and if I am reading source correctly) is that if the pure abstract class is never used, then the default methods are never even emitted to begin with which is a difference of using PRIVATE methodology only.
fxm
Moderator
Posts: 12498
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Freebasic 1.20.0 Development

Post by fxm »

Compile option '-z optabstract'

Yes, unused pure abstract types are no longer emitted.
But unused empty types (extending only OBJECT) are still emitted.
On the other hand, unused empty types extending a pure abstract type are not emitted.

Documentation updated:
CompilerOptz → fxm [added compile option '-z optabstract']
coderJeff
Site Admin
Posts: 4377
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Freebasic 1.20.0 Development

Post by coderJeff »

Changes to announce:

sf.net # 795 - changed the handling for "\Unnnnnnnn" unicode escape sequences in strings for code points greater than &hFFFFul so that on windows, these get mapped correctly to a surrogate pair. This change doesn't completely solve the bug. I added because it helps for writing tests for a Unicode UTF-8/16/32 library I started.

basic-macros: __FB_QUERY_SYMBOL__( fbc.FB_QUERY_SYMBOL.mangleid, symbol ) to return the mangled name of a symbol. This continues to be a work in progress (as it exposes internals). I added because it helps writing tests for fb's name mangling

New contributor Ahmad Khalifa (thekhalifa) contributed pull requests last month that are now merged in:
- added 'examples/Makefile' to help find compile errors in the example files. Because has been long time since these example files have been touched, some examples do fail to compile so will be an on going effort to improve
- changed to pcre2 regex library in fbdoc generation tool since pcre is being obsoleted. So any scripts that automatically install packages and build the doc generator will need to be updated
fxm
Moderator
Posts: 12498
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Freebasic 1.20.0 Development

Post by fxm »

KeyPgDdfbquerysymbol → fxm [latest example updated for new fbc 1.20 version]
Post Reply