Sign in Join

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

Mailing lists / lazarus / 2011-03

QuickSort procedure - raised exception class 'External SIGSEGV'

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Peter Williams

Hi All,
I am trying to use some legacy Delphi QuickSort code. The problem is that the original defines this var: Var d : ptrArray Absolute da;and I have changed this in my version and it crashes with an error. Project Island_maker.exe raised exception class 'External SIGSEGV' I am trying to use my version of the code, not the original. Original code ---Unit Qsort;
{
Copyright 1990 Trevor J CarlsenAll rights reserved. Author: Trevor J Carlsen PO Box 568 Port Hedland WA 6721 A general purpose sorting Unit.

}
Interface
Type  updown   = (ascending,descending);  str255   = String;  dataType = str255;     { the Type of data to be sorted }  dataptr  = ^dataType;  ptrArray = Array[1..10000] of dataptr;  Arrayptr = ^ptrArray;  Const   maxsize  : Word = 10000;  SortType : updown = ascending; Procedure QuickSort(Var da; left, right : Word);
{============================================================================}Implementation Procedure swap(Var a,b : dataptr);  { Swap the Pointers }  Var  t : dataptr;  begin    t := a;    a := b;    b := t;  end;     Procedure QuickSort(Var da; left,right : Word);  Var    d       : ptrArray Absolute da;    pivot   : dataType;    lower,    upper,    middle  : Word;
  begin    lower := left;    upper := right;    middle:= (left + right) div 2;    pivot := d[middle]^;    Repeat      Case SortType of      ascending :  begin                     While d[lower]^ < pivot do inc(lower);                     While pivot < d[upper]^ do dec(upper);                   end;      descending:  begin                     While d[lower]^ > pivot do inc(lower);                     While pivot > d[upper]^ do dec(upper);                   end;      end; { Case }                          if lower <= upper then begin        { swap the Pointers not the data }        swap(d[lower],d[upper]);        inc(lower);        dec(upper);      end;    Until lower > upper;    if left < upper then QuickSort(d,left,upper);    if lower < right then QuickSort(d,lower,right);  end;  { QuickSort }
end.
My version-----Type  map_detail = record                 Terrain : Terrain_type;                 Terrain_char : char;                 description : string;                 x, y, location_number : integer;                 exits : exit_type;               end;
  island_single_type = array[ 1..(array_max_x * array_max_y) ] of                         map_detail;
Type  updown = (ascending, descending);
Const  SortType : updown = ascending;
var  Form1: TForm1;  max_x, max_y,  max_locations,  start_x, start_y,  finish_x, finish_y : integer;  island : island_2D_type;  island_single_array : island_single_type;
implementation
uses set_max;
{--------------------------------------------------------------------}
Procedure swap(Var a,b : map_detail);  { Swap the Pointers }  Var  t : map_detail;  begin    t := a;    a := b;    b := t;  end;{--------------------------------------------------------------------}
Procedure QuickSort( Var island_single_array : island_single_type;  left, right : integer);  Var    d       : island_single_type;    pivot   : integer;    lower,    upper,    middle  : integer;
  begin    lower := left;    upper := right;    middle:= (left + right) div 2;    pivot := island_single_array[middle].location_number;    Repeat      Case SortType of      ascending :  begin                     While island_single_array[lower].location_number < pivot do                       inc(lower);                     While pivot < island_single_array[upper].location_number do                       dec(upper);                   end;      descending:  begin                     While island_single_array[lower].location_number > pivot do                       inc(lower);                     While pivot > island_single_array[upper].location_number do                       dec(upper);                   end;      end; { Case }      if lower <= upper then      begin        { swap the Pointers not the data }        swap(d[lower],d[upper]);        inc(lower);        dec(upper);      end;    Until lower > upper;    if left < upper then      QuickSort(d,left,upper);    if lower < right then      QuickSort(d,lower,right);  end;  { QuickSort }{--------------------------------------------------------------------}-----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110314/efa6f459/attachment-0001.html>

Reply by email

Joerg Schuelke
to Peter Williams

Am Mon, 14 Mar 2011 15:29:36 +1100
schrieb Peter Williams :

Procedure QuickSort( Var island_single_array : island_single_type; ??left, right : integer); ??Var ?? ?d ? ? ? : island_single_type;

The initialzation of d is missing. Accessing d results SIGSEGV. In the original code d is initialized by

?? ?d ? ? ? : ptrArray Absolute da;

thats now broken. What do you think how many implementations of quicksort are around? Is it realy needed to write a new one? Excuse my bad english, i'm native german speaking.

Reply by email

Peter Williams
to Joerg Schuelke

Hi Joerg,

Show quoted text 22 lines
Date: Mon, 14 Mar 2011 10:17:09 +0100 From: To: Subject: Re: [Lazarus] QuickSort procedure - raised exception class 'External SIGSEGV' Am Mon, 14 Mar 2011 15:29:36 +1100 schrieb Peter Williams : > Procedure QuickSort( Var island_single_array : island_single_type; > left, right : integer); > Var > d : island_single_type; The initialzation of d is missing. Accessing d results SIGSEGV. In the original code d is initialized by > d : ptrArray Absolute da; thats now broken. What do you think how many implementations of quicksort are around? Is it realy needed to write a new one? Excuse my bad english, i'm native german speaking.

I am well aware that that's what is now broken. I am asking how to fix it. I am sure that there are many QuickSorts around but I was trying to work with a legacy one which I had on my hard disk. E.g. I need a version that works. I would really like to know how to make it work. If someone knows how to make it work, then now would be the time to speak up. :-) PEW

Show quoted text 5 lines
-- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110314/7efbae67/attachment.html>

Reply by email

Marc Weustink
to Peter Williams: I am trying to use some legacy Delphi QuickSort code. The problem is that the original…
Peter Williams wrote 12 lines
Hi All, I am trying to use some legacy Delphi QuickSort code. The problem is that the original defines this var: Var d : ptrArray Absolute da; and I have changed this in my version and it crashes with an error. Project Island_maker.exe raised exception class 'External SIGSEGV' I am trying to use my version of the code, not the original.

Where in your code do you assingn d ?

you're using island_single_array in your code everywhere, except in the call to swap ()

Marc

Reply by email

Joerg Schuelke
to Peter Williams: I am well aware that that's what is now broken. I am asking how to fix it. I am sure that…

Am Mon, 14 Mar 2011 23:41:56 +1100
schrieb Peter Williams :

Show quoted text 39 lines
Hi Joerg, > Date: Mon, 14 Mar 2011 10:17:09 +0100 > From: > To: > Subject: Re: [Lazarus] QuickSort procedure - raised exception class > 'External SIGSEGV' > > Am Mon, 14 Mar 2011 15:29:36 +1100 > schrieb Peter Williams : > > > Procedure QuickSort( Var island_single_array : island_single_type; > > left, right : integer); > > Var > > d : island_single_type; > > The initialzation of d is missing. Accessing d results SIGSEGV. In > the original code d is initialized by > > > d : ptrArray Absolute da; > > thats now broken. What do you think how many implementations of > quicksort are around? Is it realy needed to write a new one? > Excuse my bad english, i'm native german speaking. > I am well aware that that's what is now broken. I am asking how to fix it. I am sure that there are many QuickSorts around but I was trying to work with a legacy one which I had on my hard disk. E.g. I need a version that works. I would really like to know how to make it work. If someone knows how to make it work, then now would be the time to speak up. :-) PEW > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Delete the line
	?? ?d ? ? ? : island_single_type;

and replace all occurrences of d by island_single_array.

The absolute directive means there is a variable d taking the same place in memory as the other one - in your example code the untyped formal procedure parameter da -, like an alias.

Reply by email