compiler hang in backend-C only

Just starting out? Need help? Post your questions and find answers here.
morosh
Enthusiast
Enthusiast
Posts: 329
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

compiler hang in backend-C only

Post by morosh »

Hello:
when compiling the following program in C backend-x64, the compiler hang indefinitely till I kill it with the task manager. It compiles normally in asm, after killing it I got the following message:
the compiler appears to have crashed or quit unexpectedly. it will be restarted, Please report the conditions that caused this as a bug

Code: Select all

EnableExplicit

Define Event.i, GadgetID.i, fname.s{1000}, cmd.s, tmp.s, prg.i, directory.s

Structure OPENFILENAME_EX Extends OPENFILENAME
  pvReserved.i
  dwReserved.i
  FlagsEx.i
EndStructure 

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
  MessageRequester("Error","Choose x64 compiler")
  End
CompilerEndIf

; CreateFile(0, GetTemporaryDirectory() + "ffmpegx.exe")
; WriteData(0, ?MyFile1, ?MyFile1End-?MyFile1)
; CloseFile(0)

Procedure close()
  DeleteFile_(GetTemporaryDirectory() + "ffmpegx.exe")
EndProcedure

Procedure.s OpenFileRequester_Ex(Title$,Pattern$,Defdir$,Deffile$)
  Define *Buffer, i.i , of.OPENFILENAME_EX, tmp.s
  
  *Buffer = AllocateMemory(StringByteLength(Pattern$)+2)
  For i = 0 To StringByteLength(Pattern$)     
    PokeB(*Buffer+i,PeekB(@Pattern$+i))
    If PeekB(@Pattern$+i) = 124
      PokeB(*Buffer+i,0)
    EndIf
  Next
  of.OPENFILENAME_EX
  of\lStructSize = SizeOf(of)
  of\lpstrTitle = @Title$
  of\lpstrInitialDir = @Defdir$
  of\lpstrFilter = *Buffer
  of\nMaxFile = #MAX_PATH
  of\lpstrFile = @Deffile$
  of\lCustData = 0 ; OpenYesNo
  of\Flags     = #OFN_EXPLORER | #OFN_LONGNAMES | #OFN_CREATEPROMPT | #OFN_ENABLEHOOK| #OFN_ENABLESIZING
  of\FlagsEx   = 0
  If GetOpenFileName_(of)
    tmp = PeekS(of\lpstrFile)
  EndIf
  ProcedureReturn tmp
EndProcedure

#OFN_ENABLESIZING       = $800000

Import  ""
  PB_Gadget_SendGadgetCommand(hWnd, EventType)
EndImport

Enumeration
  #Form
  #Panel
  #Text=#Panel+100
  #String=#Text+100
  #Button=#String+100
  #Editor=#Button+100
  #Option=#Editor+100
  #Spin=#Option+100
  #Image=#Spin+100
  #Check=#Image+100
EndEnumeration

SetGadgetFont(#PB_Default, LoadFont(0, "Arial", 10))

OpenWindow(0,100, 100, 800, 400, "TEST1",  #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar )
PanelGadget(#Panel, 10, 10, 600, 350)

AddGadgetItem(#Panel, -1, "ts to mp3")
TextGadget(#Text,10,10,70,20,"File name:")
StringGadget(#String,80,10,250,20,"")
ButtonGadget(#Button,350,10,40,20,"File")
ButtonGadget(#Button+1,460,10,70,20,"Convert")
EditorGadget(#Editor, 10,50,500,100,#PB_Editor_ReadOnly)

CloseGadgetList()
SetGadgetState(#Panel,0)

;PB_Gadget_SendGadgetCommand(GadgetID(#Check), #PB_EventType_LeftClick)
Repeat 
  Event = WaitWindowEvent()
  GadgetID = EventGadget() ; Is it a gadget event?
  Select Event
    Case #PB_Event_Gadget         ;Event = WaitWindowEvent()
      If GadgetID=#Button         ; choose file
        fname = OpenFileRequester_Ex("Choose a file","Ts files (*.ts)|*.ts","",Space(250)) 
        SetGadgetText(#String,fname)

      ElseIf GadgetID=#Button+1     ; Convert
       ; MyBeep(300,250,100)
      EndIf    
  EndSelect  
  
Until Event = #PB_Event_CloseWindow
close()
End

DataSection
  MyFile1:
  IncludeBinary "E:\install\dvd2\multimedia\ffmpeg\bin\ffmpeg.exe"   ; 107MB
  MyFile1End:
EndDataSection
After investigating, I noticed that the problem disappears when I comment the DataSection (last 5 lines), is the size 107MB too big or what?
Can anyone confirm?
using W10, PB6.12-x64
Thanks
PureBasic: Surprisingly simple, diabolically powerful
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: compiler hang in backend-C only

Post by infratec »

I can not confirm, but ...

you don't use FreeMemory(*Buffer)
you don't check if the allocation was ok
better use PokeA and PeekA instead of B

have you already used the purifier with granularity 1, 1, 1, 1?
normeus
Enthusiast
Enthusiast
Posts: 472
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: compiler hang in backend-C only

Post by normeus »

Try loading a smaller program like "C:\Windows\System32\ntoskrnl.exe"
( it is 10mb and takes about 30 seconds to compile on my system ).
I figure it would take about 300 seconds to create your program. It might have to do with GCC optimizing the data.

Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Fred
Administrator
Administrator
Posts: 18247
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: compiler hang in backend-C only

Post by Fred »

The binary is converted in a static data array in in the C source, so it means than a 107MB exe will result in a 500MB or more C output (you can try with the --commented flag) which could take a while to assemble. You can try to pack it before including it to reduce the footprint. If you are targerting Windows only, you can use resources instead.
morosh
Enthusiast
Enthusiast
Posts: 329
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: compiler hang in backend-C only

Post by morosh »

Thanks all, I'll stick to asm
PureBasic: Surprisingly simple, diabolically powerful
Post Reply