Hi Sven,

I don't know how to find that, could you please explain?  Attached
dbg.tar.bz2 is the demo program and assembly code generated by the compile.
Where is the "point of specialization" in that file?

My working program is quite complex, I copied part of the code related to
this problem in snippet.pas

Thank you!
Xiangrong


2014-02-13 23:53 GMT+08:00 Sven Barth <pascaldra...@googlemail.com>:

> Am 13.02.2014 16:42, schrieb Xiangrong Fang:
>
>> Hi All,
>>
>> I encountered a very strange problem. The code looks like this:
>>
>> //In Unit1.pas:
>>
>> //sel is an object of TIntVector and
>> //TIntVector = specialize TVector<Integer>
>> *sel.Sort([soEliminateNA, soReversed]);
>>
>> *
>>
>> //In vector.pas:
>>
>> procedure TVector.Sort(Options: SortOptions);
>> var
>> i, gap, order, first, last, pos: Integer;
>> Temp: T;
>> begin
>> *if FCount < 2 then**Exit; <-- problem here*
>>
>> if soReversed in Options then order := 1 else order := -1;
>> ... ...
>>
>> My purpose is to skip sorting if the vector's element count is less than
>> 2.
>>
>> Now the problem is that this statement does not have any effect (see
>> attached screenshot). The debugger refuse to stop on the breakpoint, but
>> goes directly to the line below it!
>>
>> What's more strange is that if I change the line to break after “then”,
>> i.e.:
>>
>> begin
>> *if FCount < 2 then***
>> *Exit;*
>>
>> if soReversed in Options then order := 1 else order := -1;
>> ... ...
>>
>> Now it worked!
>>
>> I also wrote a simple test program, but can NOT reproduce this bug there.
>>
>> My TVector source code is here: https://github.com/xrfang/
>> fpcollection/blob/master/src/units/vector.pas
>>
>>
>> Any help is greatly appreciated.
>>
> Could you please check/compare the generated assembler code? Use "-al" to
> have the compiler generate it and you'll need to look at the file where you
> specialized the TVector.
>
> Regards,
> Sven
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>

Attachment: dbg.tar.bz2
Description: BZip2 compressed data

type
  TWaveStack = specialize TVector<Pointer>;
  TIntVector = specialize TVector<Integer>;
... ...

var
  i: Integer;
  cw: TCmhWave;
  n: TTreeNode;
  ws: TWaveStack;
  sel: TIntVector;
  had_first: Boolean;
  procedure RecNodeIndex(node: TTreeNode);
  begin
    if (node.Level = 0) and (node.Text <> '') then sel.Push(node.Index);
  end;
begin  
  ws := TWaveStack.Create(nil);
  with tvb, tvb.Items do try
    if SelectionCount <= 1 then begin
      n := Selected;
      if n <> nil then begin
        while n.Parent <> nil do n := n.Parent;
        tbCfm.Enabled := TCmhWave(n.Data).Mode >= 0;
      end;
      for i := 0 to TopLvlCount - 1 do begin
        if TopLvlItems[i].Text = '' then Continue;
        ws.Push(TopLvlItems[i].Data);
      end;
    end else begin
      had_first := False;
      sel := TIntVector.Create(-1);
      try
        for i := 0 to SelectionCount - 1 do begin
          n := GetSelections(i);
          if n.Index = Selected.Index then had_first := True;
          RecNodeIndex(n);
        end;
        if (not had_first) then RecNodeIndex(Selected);
        sel.Sort([soEliminateNA, soReversed]);
        while sel.Count > 0 do ws.Push(TopLvlItems[sel.Pop].Data);
      finally
        sel.Free;
      end;
    end;
    ... ...
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to