PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 3 4 [5] 6 7 ... 12

Author Topic: Josť, if you're bored...  (Read 11861 times)

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3205
Re: Josť, if you're bored...
« Reply #60 on: August 09, 2018, 06:35:29 PM »

Seems that the problem happens when compiling with 64 bit. I will check it. It works with 32 bit.

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3205
Re: Josť, if you're bored...
« Reply #61 on: August 09, 2018, 07:14:25 PM »

It fails with 64 bit if you use the -O switch. Without it, it works fine.
« Last Edit: August 09, 2018, 07:19:08 PM by Josť Roca »
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8865
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #62 on: August 09, 2018, 08:08:24 PM »

It fails with 64 bit if you use the -O switch. Without it, it works fine.

That is interesting. It was failing for me in 32-bit because I am using additional compiler switches " -gen gcc -Wc -O2 "
Strange that the -O switch causes it to fail in both 32 and 64 bit.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3205
Re: Josť, if you're bored...
« Reply #63 on: August 09, 2018, 08:17:47 PM »

These gcc optimizations seem dangerous. Next time, don't forget to post which switches are you using or we will end with you saying "It GPF's" and I saying "It works". If at least there was a way to disable optimizations in parts of the code...


« Last Edit: August 09, 2018, 08:20:29 PM by Josť Roca »
Logged

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8865
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #64 on: August 09, 2018, 08:29:44 PM »

I have removed the optimization switch from all of my compiles. I fear though that others may fall into this trap if they use CFileStream with -O as I've seen the -O switch being talked about a lot and somewhat recommended on the forums (well, at least the lower number -O optimizations).
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3205
Re: Josť, if you're bored...
« Reply #65 on: August 09, 2018, 08:56:44 PM »

As I never have used the O switch to test my code, I don't know if other parts will fail. It has been a happy coincidence that I had the -O 2 switch added in the 64 bit build configurations; otherwise, I will be still scratching my head. I remember that I did it to try the difference on size.

Johan Klassen

  • Junior Member
  • **
  • Posts: 85
  • FF3 User
Re: Josť, if you're bored...
« Reply #66 on: August 09, 2018, 08:58:14 PM »

... If at least there was a way to disable optimizations in parts of the code...
I agree, gcc already has pragmas to turn optimization on/off, so it seems feasible to add to fbc, actually I made a feature request https://www.freebasic.net/forum/viewtopic.php?p=225167
but sadly it got no attention.
« Last Edit: August 09, 2018, 09:00:48 PM by Johan Klassen »
Logged

Johan Klassen

  • Junior Member
  • **
  • Posts: 85
  • FF3 User
Re: Josť, if you're bored...
« Reply #67 on: August 09, 2018, 09:05:56 PM »

hello Josť Roca
please see this post https://www.freebasic.net/forum/viewtopic.php?p=249654#p249654
Quote from: deltarho[1859]
In the opening post replace
Code: [Select]
dim as ulongint i,jwith
Code: [Select]
dim as ulongint i
dim shared as ulongint j
and the loop is no longer optimized out.

Compiled with -gen gcc -Wc -O3
is it possible to perhaps use key shared variables to trick gcc in not over optimizing?
« Last Edit: August 09, 2018, 09:08:21 PM by Johan Klassen »
Logged

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3205
Re: Josť, if you're bored...
« Reply #68 on: August 09, 2018, 09:16:32 PM »

I'm not using loops. Just calls to the methods of the IStream interface. I have no idea why the O switch is messing it.

Johan Klassen

  • Junior Member
  • **
  • Posts: 85
  • FF3 User
Re: Josť, if you're bored...
« Reply #69 on: August 09, 2018, 10:28:47 PM »

I can't get your example http://www.planetsquires.com/protect/forum/index.php?topic=4191.msg32153#msg32153 to crash, am using WinFBE 1.7.3, build options -s gui -gen gcc -Wc -O2, tried both 32 and 64-bit
Logged

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3205
Re: Josť, if you're bored...
« Reply #70 on: August 09, 2018, 11:26:07 PM »

Hi Paul,

If I rem the line DyLibFree(pLib) in this function, located at the top of CStream.inc, it works with 64 bit and the -O switch. Why? I have no idea.

Code: [Select]
' ========================================================================================
' Opens or creates a file and retrieves a stream to read or write to that file.
' ========================================================================================
PRIVATE FUNCTION AfxSHCreateStreamOnFileEx (BYVAL pwszFile AS WSTRING PTR, BYVAL grfMode AS DWORD, _
BYVAL dwAttributes AS DWORD, BYVAL fCreate AS WINBOOL, BYVAL ppStream AS IStream PTR PTR) AS HRESULT
   DIM AS ANY PTR pLib = DyLibLoad("shlwapi.dll")
   IF pLib = NULL THEN EXIT FUNCTION
   DIM pShCreateStreamOnFileEx AS FUNCTION (BYVAL pwszFile AS WSTRING PTR, BYVAL grfMode AS DWORD, BYVAL dwAttributes AS DWORD, _
       BYVAL fCreate AS WINBOOL, BYVAL pstmTemplate AS IStream PTR, BYVAL ppStream AS IStream PTR PTR) AS HRESULT
   pShCreateStreamOnFileEx = DyLibSymbol(pLib, "SHCreateStreamOnFileEx")
   IF pShCreateStreamOnFileEx = NULL THEN EXIT FUNCTION
   DIM hr AS HRESULT = pShCreateStreamOnFileEx(pwszFile, grfMode, dwAttributes, fCreate, NULL, ppStream)
'   DyLibFree(pLib)
   RETURN hr
END FUNCTION
' ========================================================================================

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3205
Re: Josť, if you're bored...
« Reply #71 on: August 09, 2018, 11:58:43 PM »

I have slightly modified the function changing two EXIT FUNCTION to RETURN E_POINTER. If I use EXIT FUNCTION it will return 0, that can be interpreted as success.

Code: [Select]
' ========================================================================================
' Opens or creates a file and retrieves a stream to read or write to that file.
' ========================================================================================
PRIVATE FUNCTION AfxSHCreateStreamOnFileEx (BYVAL pwszFile AS WSTRING PTR, BYVAL grfMode AS DWORD, _
BYVAL dwAttributes AS DWORD, BYVAL fCreate AS WINBOOL, BYVAL ppStream AS IStream PTR PTR) AS HRESULT
   DIM AS ANY PTR pLib = DyLibLoad("shlwapi.dll")
   IF pLib = NULL THEN RETURN E_POINTER
   DIM pShCreateStreamOnFileEx AS FUNCTION (BYVAL pwszFile AS WSTRING PTR, BYVAL grfMode AS DWORD, BYVAL dwAttributes AS DWORD, _
       BYVAL fCreate AS WINBOOL, BYVAL pstmTemplate AS IStream PTR, BYVAL ppStream AS IStream PTR PTR) AS HRESULT
   pShCreateStreamOnFileEx = DyLibSymbol(pLib, "SHCreateStreamOnFileEx")
   IF pShCreateStreamOnFileEx = NULL THEN RETURN E_POINTER
   DIM hr AS HRESULT = pShCreateStreamOnFileEx(pwszFile, grfMode, dwAttributes, fCreate, NULL, ppStream)
   ' For some reason, if we free the library, calling the methods that use the returned
   ' IStream pointer will GPF if compiled with the -O switch.
'   DyLibFree(pLib)
   RETURN hr
END FUNCTION
' ========================================================================================
« Last Edit: August 10, 2018, 03:59:35 AM by Josť Roca »
Logged

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3205
Re: Josť, if you're bored...
« Reply #72 on: August 10, 2018, 02:07:14 AM »

Modified again to check if the library is already loaded to avoid multiple loadings.

Code: [Select]
' ========================================================================================
' Opens or creates a file and retrieves a stream to read or write to that file.
' ========================================================================================
PRIVATE FUNCTION AfxSHCreateStreamOnFileEx (BYVAL pwszFile AS WSTRING PTR, BYVAL grfMode AS DWORD, _
BYVAL dwAttributes AS DWORD, BYVAL fCreate AS WINBOOL, BYVAL ppStream AS IStream PTR PTR) AS HRESULT
   ' // See if the library is already loaded in the address space
   DIM AS ANY PTR pLib = GetModuleHandleW("shlwapi.dll")
   ' // If it is not loaded, load it
   IF pLib = NULL THEN pLib = DyLibLoad("shlwapi.dll")
   IF pLib = NULL THEN RETURN E_POINTER
   DIM pShCreateStreamOnFileEx AS FUNCTION (BYVAL pwszFile AS WSTRING PTR, BYVAL grfMode AS DWORD, BYVAL dwAttributes AS DWORD, _
       BYVAL fCreate AS WINBOOL, BYVAL pstmTemplate AS IStream PTR, BYVAL ppStream AS IStream PTR PTR) AS HRESULT
   pShCreateStreamOnFileEx = DyLibSymbol(pLib, "SHCreateStreamOnFileEx")
   IF pShCreateStreamOnFileEx = NULL THEN RETURN E_POINTER
   DIM hr AS HRESULT = pShCreateStreamOnFileEx(pwszFile, grfMode, dwAttributes, fCreate, NULL, ppStream)
   ' For some reason, if we free the library, calling the methods that use the returned
   ' IStream pointer will GPF if compiled with the -O switch.
'   DyLibFree(pLib)
   RETURN hr
END FUNCTION
' ========================================================================================
« Last Edit: August 12, 2018, 10:43:23 PM by Josť Roca »
Logged

Chris Maher

  • Little Newbie
  • *
  • Posts: 24
  • New FF3 User
Re: Josť, if you're bored...
« Reply #73 on: August 10, 2018, 04:37:42 AM »

Hi Josť,

CPrint.PrintBitmapToFile is working fine for the 'Microsoft Print to PDF' printer, but it needs the lpszDocName member available too to be able to view, control and debug the print queue.

Thanks.
Logged

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3205
Re: Josť, if you're bored...
« Reply #74 on: August 10, 2018, 06:57:21 AM »

Added a parameter for the document name.
« Last Edit: August 12, 2018, 06:02:44 AM by Josť Roca »
Logged
Pages: 1 ... 3 4 [5] 6 7 ... 12