[fpc-pascal]blockread in a procedure

2004-02-29 Thread David Emerson
Hi there,

I'm having trouble using blockread. It was working for... oh, a year... and all of a 
sudden it's not working. I'm getting a runtime error 87 in win32/i386 (fpc 1.0.10) and 
an error 217 in linux/i386 (fpc 1.0.6). Since I always compile with -gl it tells me 
it's failing right at blockread. Here's the code...


const
  test_file_name = 'test.txt';
  the_source : ansistring = '';

procedure read_source_file;

  const
bufsize = 2048;
  var
source_file : file;
buf : array [1..bufsize] of char;
count_read : longint;   // longint required by blockread

  begin

write ('Reading source file.');
assign (source_file, test_file_name);
reset (source_file);
the_source := '';
repeat
  blockread (source_file, buf, bufsize, count_read);
  the_source := the_source + copy (buf, 1, count_read);
  until count_read = 0;
close (source_file);
the_source := the_source + chr(255);
writeln ('Source file successfully read');

  end;

begin
  read_source_file;
end.


If I get rid of the procedure read_source_file and put its code directly into the main 
"begin end." then it works. So for some reason, suddenly it can't stand having 
blockread inside a procedure. I haven't touched the procedure or any of the 
constants/variables associated with it in a long time, so it's bizarre that it 
suddenly decided to fail.


Incidentally, fpc 1.0.10 rpm failed to install on redhat. I struggled with it for a 
good hour. Any tips? Does the gz work better than the rpm?


Cheers,
David 



___
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal]blockread in a procedure

2004-02-29 Thread Michael . VanCanneyt


On Sun, 29 Feb 2004, David Emerson wrote:

> Hi there,
> 
> I'm having trouble using blockread. It was working for... oh, a year... and all of a 
> sudden it's not working. I'm getting a runtime error 87 in win32/i386 (fpc 1.0.10) 
> and an error 217 in linux/i386 (fpc 1.0.6). Since I always compile with -gl it tells 
> me it's failing right at blockread. Here's the code...
> 
> 
> const
>   test_file_name = 'test.txt';
>   the_source : ansistring = '';
> 
> procedure read_source_file;
> 
>   const
> bufsize = 2048;
>   var
> source_file : file;
> buf : array [1..bufsize] of char;
> count_read : longint;   // longint required by blockread
> 
>   begin
> 
> write ('Reading source file.');
> assign (source_file, test_file_name);
> reset (source_file);
> the_source := '';
> repeat
>   blockread (source_file, buf, bufsize, count_read);
>   the_source := the_source + copy (buf, 1, count_read);
>   until count_read = 0;
> close (source_file);
> the_source := the_source + chr(255);
> writeln ('Source file successfully read');
> 
>   end;
> 
> begin
>   read_source_file;
> end.
> 
> 
> If I get rid of the procedure read_source_file and put its code directly into the 
> main 
> "begin end." then it works. So for some reason, suddenly it can't stand having 
> blockread 
> inside a procedure. I haven't touched the procedure or any of the 
> constants/variables 
> associated with it in a long time, so it's bizarre that it suddenly decided to fail.

did you change the compiler, or one of the compiler flags ?

> 
> 
> Incidentally, fpc 1.0.10 rpm failed to install on redhat. I struggled with it for a 
> good hour. Any tips? Does the gz work better than the rpm?

What error do you get ? What version of rpm do you use ?

If the .rpm fails, the .gz should always install.

Michael.

___
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal]blockread in a procedure

2004-02-29 Thread Michael . VanCanneyt


On Sun, 29 Feb 2004, David Emerson wrote:

> Hi there,
> 
> I'm having trouble using blockread. It was working for... oh, a year... and all of a 
> sudden it's not working. I'm getting a runtime error 87 in win32/i386 (fpc 1.0.10) 
> and an error 217 in linux/i386 (fpc 1.0.6). Since I always compile with -gl it tells 
> me it's failing right at blockread. Here's the code...
> 

I tested some things with the current compiler. The error occurs there as
well. It's a stack problem. If you move the 'buf' definition 
out of the procedure, I.e. define it as a global var, it works fine.

Assuming you don't want to use a global variable (bad programming practice), 
you can also try the following, which works fine as well: 
(ansistrings are allocated on the heap, bypassing the stack);

Michael.

program testb;

const
  test_file_name = 'test.txt';
  the_source : ansistring = '';

const
  bufsize = 2048;

procedure read_source_file;


  var
source_file : file;
count_read : longint;   // longint required by blockread
Buf : AnsiString;

  begin
SetLength(Buf,BufSize);
write ('Reading source file.');
assign (source_file, test_file_name);
reset (source_file);
the_source := '';
repeat
  blockread (source_file, buf[1], bufsize, count_read);
  the_source := the_source + copy (buf, 1, count_read);
  until count_read = 0;
close (source_file);
the_source := the_source + chr(255);
writeln ('Source file successfully read');
  end;

begin
  read_source_file;
end.

___
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal]blockread in a procedure (last try!)

2004-02-29 Thread Michael . VanCanneyt


On Sun, 29 Feb 2004, David Emerson wrote:

> Hi there,
> 
> I'm having trouble using blockread. It was working for... oh, a year... and all of a 
> sudden it's not working. I'm getting a runtime error 87 in win32/i386 (fpc 1.0.10) 
> and an error 217 in linux/i386 (fpc 1.0.6). Since I always compile with -gl it tells 
> me it's failing right at blockread. Here's the code...
> 

OK, last try. Not being entirely satisfied with my previous posts, I dug a
little deeper. The strace on linux pointed me to the error.

> 
> const
>   test_file_name = 'test.txt';
>   the_source : ansistring = '';
> 
> procedure read_source_file;
> 
>   const
> bufsize = 2048;
>   var
> source_file : file;
> buf : array [1..bufsize] of char;
> count_read : longint;   // longint required by blockread
> 
>   begin
> 
> write ('Reading source file.');
> assign (source_file, test_file_name);
> reset (source_file);

This is the culprit. It should read
  reset (source_file,1);
By default, the blocksize is 128.


> the_source := '';
> repeat
>   blockread (source_file, buf, bufsize, count_read);

With a blocksize of 128, this will try to read 128*2028 (256K) 
bytes.  My guess is that the OS decides this is outside the 
valid stack range, and bails out. Chaning the blocksize to 1 in your
original procedure makes things work just fine.

Remains the question how this ever could have worked.

Michael.

___
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal]blockread in a procedure

2004-02-29 Thread Marco van de Voort
> On Sun, 29 Feb 2004, David Emerson wrote:
> > end.
> > 
> > 
> > If I get rid of the procedure read_source_file and put its code directly
> > into the main "begin end." then it works. So for some reason, suddenly
> > it can't stand having blockread inside a procedure. I haven't touched
> > the procedure or any of the constants/variables associated with it in a
> > long time, so it's bizarre that it suddenly decided to fail.
> 
> did you change the compiler, or one of the compiler flags ?

It could be the copy(array of char). It was bugged in 1.9.x too, and got
fixed somewhere in august-september (it was pretty much the bug that prevented
the compiled twsocket from working).
 
IOW, try 1.9.2

___
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal]Database objects

2004-02-29 Thread Philip Plant
Hello,

I've been porting a legacy Delphi application to FPC, with a fair degree
of success.  However, the application uses woll2woll's InfoPower
components, and I was wondering if anyone knows of an appropriate FPC
replacement for these before I embark on writing my own?

Thanks in advance,

Philip.

-- 
http://www.greenfinch.com/

___
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal]Berkeley DB + FPC

2004-02-29 Thread Taj Morton
Hi All,
Have any interfaces been written for BerkeleyDB (preferabl...
Googled it but nothing turned up :(.
Any leads would be nice.
Thanks!
--Taj

-- 
Pohl's law:
Nothing is so good that somebody, somewhere, will not hate it.

___
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal