Sign in Join

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

Mailing lists / fpc-pascal / 2006-06

Clueless here

13 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

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

Darius Blaszijk

Hi,

I have two overloaded functions. One overloaded function just rearanges one parameter from an array of extended to an array of ^extended and calls the other overloaded function. The problem is however that the 2nd function call crashes the app. I really have no idea why therefore I'm posting the code in the hope someone with more insight can help me here.

So what happens is the following; the first debugmessages are ok and as expected. However the second debugmessages (array of PJmFloat) crash the application. I have attached the backtrace.

Darius

type
  TJmFloat = extended;
  PJmFloat = ^TJmFloat;
  TDynTJmFloatArray = array of TJmFloat;
Function FitSession( Parameters : array of PJmFloat; ChiSquareFunc : TOFitFunc ) : IFit;
var i: integer;
begin
  //debug only
  for i := 0 to High(Parameters) do
    ShowMessage('array of PJmFloat ' + FloatToStr(Parameters[i]^));
 Result := TFit.Create( Parameters, ChiSquareFunc );
end;
function FitSession(Parameters: TDynTJmFloatArray; ChiSquareFunc: TOFitFunc): IFit;
var
  Params: array of PJmFloat;
  i: integer;
begin
  SetLength(Params, Length(Parameters));
  for i := 0 to High(Parameters) do
  begin
    Params[i] := AllocMem(SizeOf(TJmFloat));
    Params[i] := @Parameters[i];
  end;
  //debug only
  for i := 0 to High(Params) do
    ShowMessage('TDynTJmFloatArray ' + FloatToStr(Params[i]^));
  Result := FitSession(Params, ChiSquareFunc);
end;
begin
    SetLength(c, 2);
    c[0] := 2;
    c[1] := 0.2;
    Fit := FitSession(c, @ChiSquareFunc);
end;
Michalis Kamburelis
to Darius Blaszijk: I have two overloaded functions. One overloaded function just rearanges one parameter…
Darius Blaszijk wrote 42 lines
Hi, I have two overloaded functions. One overloaded function just rearanges one parameter from an array of extended to an array of ^extended and calls the other overloaded function. The problem is however that the 2nd function call crashes the app. I really have no idea why therefore I'm posting the code in the hope someone with more insight can help me here. So what happens is the following; the first debugmessages are ok and as expected. However the second debugmessages (array of PJmFloat) crash the application. I have attached the backtrace. Darius type TJmFloat = extended; PJmFloat = ^TJmFloat; TDynTJmFloatArray = array of TJmFloat; Function FitSession( Parameters : array of PJmFloat; ChiSquareFunc : TOFitFunc ) : IFit; var i: integer; begin //debug only for i := 0 to High(Parameters) do ShowMessage('array of PJmFloat ' + FloatToStr(Parameters[i]^)); Result := TFit.Create( Parameters, ChiSquareFunc ); end; function FitSession(Parameters: TDynTJmFloatArray; ChiSquareFunc: TOFitFunc): IFit; var Params: array of PJmFloat; i: integer; begin SetLength(Params, Length(Parameters)); for i := 0 to High(Parameters) do begin Params[i] := AllocMem(SizeOf(TJmFloat)); Params[i] := @Parameters[i];

Don't you want to write here

  Params[i]^ := Parameters[i];

?

Show quoted text 16 lines
end; //debug only for i := 0 to High(Params) do ShowMessage('TDynTJmFloatArray ' + FloatToStr(Params[i]^)); Result := FitSession(Params, ChiSquareFunc); end; begin SetLength(c, 2); c[0] := 2; c[1] := 0.2; Fit := FitSession(c, @ChiSquareFunc); end;
Darius Blaszijk
to mariano podesta: hi daruis change this line Params[i] := @Parameters[i]; with this Params[i]^ :=…

I did as you and Michalis suggested, but it makes no difference the application keeps crashing. I keep getting a " Invalid floating point operation".

Darius

Earlier message 28 lines
----- Original Message ----- From: mariano podesta To: FPC-Pascal users discussions Sent: Thursday, June 29, 2006 10:20 PM Subject: Re: [fpc-pascal] Clueless here hi daruis change this line Params[i] := @Parameters[i]; with this Params[i]^ := Parameters[i]; hope it works. marianop ------------------------------------------------------------------------------
Dominique Leducq
to Darius Blaszijk
I did as you and Michalis suggested, but it makes no difference the application keeps crashing. I keep getting a " Invalid floating point operation".

What architecture are you working on? what version(s) of the compiler did you try? There are known bugs with floating point numbers on AMD64 with fpc 2.0.2 (and older 2.1.1), which seem to be fixed in fpc 2.0.3 (upcoming 2.0.4) and recent 2.1.1.

Dominique

Darius Blaszijk
to Dominique Leducq

I'm using 2.0.2 on winxp

Darius

Earlier message 24 lines
----- Original Message ----- From: "Dominique Leducq" To: Sent: Friday, June 30, 2006 5:15 PM Subject: Re: [fpc-pascal] Clueless here > On Fri, 30 Jun 2006 12:30:33 +0200 > "Darius Blaszijk" wrote: > >> I did as you and Michalis suggested, but it makes no difference the >> application keeps crashing. I keep getting a " Invalid floating point >> operation". > > What architecture are you working on? what version(s) of the compiler did > you try? There are known bugs with floating point numbers on AMD64 with > fpc 2.0.2 (and older 2.1.1), which seem to be fixed in fpc 2.0.3 (upcoming > 2.0.4) and recent 2.1.1. > > Dominique > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Ole J. Røtne
to Darius Blaszijk

Can anyone explain why i get output like this in a small test program: Inside Thread
Main Loop
Inside Thread
Main Loop
Inside Thread
Main Loop

On Windows the output are lined up just as I would expect: Inside Thread
Main Loop
Inside Thread
Main Loop

Here's a snip of the code:

// Main Prog
Thr := threadtest.Create;
Repeat
  k := PollKeyEvent;
  WriteLn('Mein Loop');
  Sleep(100);
Until k  0;

And the ThreadTest.Execute i just:

Procedure ThreadTest.Execute;
Begin
  Repeat
    WriteLn('Inside Thread');
    Sleep(100);
  Until Terminated
End;

And if this is a "wrong way" of doing this thing, could someone tell me how it should be..

Oh and BTW. Using FPC 2.1.1 snapshot from 14.06.06 (from Lazarus site), on OpenSuSe 10.1..

Florian Klaempfl
to Ole J. Røtne
Ole J. Røtne wrote 41 lines
Can anyone explain why i get output like this in a small test program: Inside Thread Main Loop Inside Thread Main Loop Inside Thread Main Loop On Windows the output are lined up just as I would expect: Inside Thread Main Loop Inside Thread Main Loop Here's a snip of the code: // Main Prog Thr := threadtest.Create; Repeat k := PollKeyEvent; WriteLn('Mein Loop'); Sleep(100); Until k 0; And the ThreadTest.Execute i just: Procedure ThreadTest.Execute; Begin Repeat WriteLn('Inside Thread'); Sleep(100); Until Terminated End; And if this is a "wrong way" of doing this thing, could someone tell me how it should be..

You probably want to guard the output with mutexes or semaphores. Writing unsynchronized to a stream has always unexpected results.

Show quoted text 11 lines
Oh and BTW. Using FPC 2.1.1 snapshot from 14.06.06 (from Lazarus site), on OpenSuSe 10.1.. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Ole J. Røtne
to Florian Klaempfl
Show quoted text 15 lines
-----Opprinnelig melding----- Fra: På vegne av Florian Klaempfl Sendt: 2. juli 2006 12:46 Til: FPC-Pascal users discussions Emne: Re: [fpc-pascal] writeln in threads on linux > And if this is a "wrong way" of doing this thing, could someone tell > me how it should be.. You probably want to guard the output with mutexes or semaphores. Writing unsynchronized to a stream has always unexpected results.

Did try to wrap both of the WriteLn() with
EnterCriticalSection/LeaveCriticalSection.
Same result..

And to answer another post at the same time..

If I use: Writeln('.....', LineEnding);
I get the double lineshift thing all over again, same as using #13#10..

Inside Thread

Main Program

Inside Thread

And so on...

And as I said in my last post.

When the program terminates, the lineshift thing is still there. Seem like something isn't cleared/reset at program termination.. If I press enter, the next prompt end up after the other. (no lineshift)

Example:

>

Ole JR

Florian Klaempfl
to Ole J. Røtne
Ole J. Røtne wrote 21 lines
> -----Opprinnelig melding----- > Fra: > På vegne av > Florian Klaempfl > Sendt: 2. juli 2006 12:46 > Til: FPC-Pascal users discussions > Emne: Re: [fpc-pascal] writeln in threads on linux > >> And if this is a "wrong way" of doing this thing, could > someone tell >> me how it should be.. > You probably want to guard the output with mutexes or semaphores. > Writing unsynchronized to a stream has always unexpected results. > Did try to wrap both of the WriteLn() with EnterCriticalSection/LeaveCriticalSection. Same result..

Please post the complete code.

Ole J. Røtne
to Florian Klaempfl: Please post the complete code.
Please post the complete code.

Here goes (Typed from my Linux box, as i don't have filesharing going there):

<---- Start Unit1
Unit unit1;
{$mode objfpc}{$H+}
Interface
Uses
  Classes, SysUtils;
Type
  threadtest = class(tthread)
    constructor Create;
    procedure Execute: override;
End;
Var
  crit:TRTLCriticalSection;
Implementation
Constructor threadtest.Create;
Begin
  FreeOnTerminate := True;
  Inherited Create(False);
End;
Procedure threadtest.Execute;
Begin
  Repeat
    EnterCriticalSection(crit); // Get the same result with/without
    WriteLn('Inside Thread');
    LeaveCriticalSection(crit); // Get the same result with/without
  Until Terminated;
End;

End.
<--- End Unit1
<--- Start Program1
Program Program1

{$mode objfpc}{$H+}
{$DEFINE UseCThreads}
Uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils, Unit1, Keyboard;
Var
  MyThread:threadtest;
  k:TKeyEvent;
Begin
InitKeyboard;
InitCriticalSection(crit);
MyThread := ThreadTest.Create;
Repeat
  k := PollKeyEvent;
  EnterCriticalSection(crit); // Get the same result with/without
  WriteLn('Main Program');
  LeaveCriticalSection(crit); // Get the same result with/without
Until k  0;
MyThread.Terminate;
End.
<--- End Program1

Ole JR