[fpc-pascal] initializing pointer values

2011-12-16 Thread dhkblaszyk
  

On implementing a linked list I hit to some unexpected (doesn't
mean incorrect though) behaviour. 

 ptest = ^test;
 test = record
 p:
pointer;
 end; 

 new(mytest); 

When I allocate "mytest" the pointer
variable "p" is initialized as $ instead of nil as I did
suspect. In my code though I am relying on the fact that new pointers
are indeed nil so I can allocate them accordingly. How can I force and
rely on the fact that p is always nil? What is the correct procedure
here? 

TIA, Darius ___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] initializing pointer values

2011-12-16 Thread Michael Van Canneyt



On Fri, 16 Dec 2011, dhkblas...@zeelandnet.nl wrote:



On implementing a linked list I hit to some unexpected (doesn't mean incorrect 
though) behaviour.

 

  ptest = ^test;
  test = record
    p: pointer;
  end;

 

  new(mytest);

 

When I allocate "mytest" the pointer variable "p" is initialized as $ 
instead of nil as I did suspect. In my code though I am
relying on the fact that new pointers are indeed nil so I can allocate them 
accordingly. How can I force and rely on the fact that
p is always nil? What is the correct procedure here?


Newly allocated memory is never zeroed out. You must do this manually with 
FillChar or FillWord.
This is only done automatically for class instances.

I will add a note to the docs.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

RE : [fpc-pascal] Distributing unit object files

2011-12-16 Thread Ludo Brands
> How do I make FPC not rebuild the unit object file when 
> contributing units to the compiled unit have been modified? 
> What is the best strategy - if at all? 

If the contributing unit is a stand-alone unit which doesn't depend on other
units (fe. a database connector), you can copy the source codes of that unit
into your project. This way you'll basically freeze the code of that unit
and remove the external dependency. Evaluate carefully the pros and cons
before doing so.

Ludo

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] initializing pointer values

2011-12-16 Thread dhkblaszyk
  

On 16 dec '11, Michael Van Canneyt wrote: 

> On Fri, 16 Dec 2011,
dhkblas...@zeelandnet.nl [1]wrote:
> 
>> On implementing a linked list I
hit to some unexpected (doesn't mean incorrect though) behaviour. ptest
= ^test; test = record p: pointer; end; new(mytest); When I allocate
"mytest" the pointer variable "p" is initialized as $ instead of
nil as I did suspect. In my code though I am relying on the fact that
new pointers are indeed nil so I can allocate them accordingly. How can
I force and rely on the fact that p is always nil? What is the correct
procedure here?
> 
> Newly allocated memory is never zeroed out. You
must do this manually with FillChar or FillWord.
> This is only done
automatically for class instances.
> 
> I will add a note to the docs.
>

> Michael.

I wasn't sure about this, but now I know. 

Thanks Michael.


  

Links:
--
[1] mailto:dhkblas...@zeelandnet.nl
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] Testing applications with FPCUnit

2011-12-16 Thread luciano de souza
Hello listers,

Navigating in FPC source codes, I found fpcunit. It's really
wonderful. With the tTestCase class, we can  generate a report with
the success or the failure of our tests.

However, only observing the source code, it's not easy to comprehend
how it works. I found a single parcial example, showing the usage of
AssertEqual, but it was not enough to understand.

I have never used something like that. I know other languages have
similar features, but I have never programed tests in other languages.

Is there documentation on the usage of fpcunit? What is the best way
to study it?

regards,

Luciano
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Testing applications with FPCUnit

2011-12-16 Thread Vincent Snijders
2011/12/16 luciano de souza :
> Hello listers,
>
> Navigating in FPC source codes, I found fpcunit. It's really
> wonderful. With the tTestCase class, we can  generate a report with
> the success or the failure of our tests.
>
> Is there documentation on the usage of fpcunit? What is the best way
> to study it?

Google found this (old) article:
http://www.freepascal.org/olddocs-html/fpcunit.pdf

Vincent
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Testing applications with FPCUnit

2011-12-16 Thread Michael Van Canneyt



On Fri, 16 Dec 2011, Vincent Snijders wrote:


2011/12/16 luciano de souza :

Hello listers,

Navigating in FPC source codes, I found fpcunit. It's really
wonderful. With the tTestCase class, we can  generate a report with
the success or the failure of our tests.

Is there documentation on the usage of fpcunit? What is the best way
to study it?


Google found this (old) article:
http://www.freepascal.org/olddocs-html/fpcunit.pdf


It is old, but still correct.

I will see about refreshing it, and adding it in the FPC documentation.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] JSON Dataset in FCL-DB.

2011-12-16 Thread Michael Van Canneyt


Hello,

I just committed a JSON dataset in fcl-db.

This is a dataset which stores its data in JSON objects (as in fpjson) in memory. 
The records are in a JSON array, each record can be a JSON object or array.

(not mixed)

The dataset is read-write. It can be used to create JSON data from scratch: 
just add definitions to the fielddefs properties, and call 'Open'. At the end, 
call SaveToStream().


There are 2 descendents which read/write ExtJS JSON data packages (Objects 
or Arrays) from streams but they are usable to handle any kind of JSON data. 
Currently, the dataset does not yet support propagating changes (deltas) back to a server.


I would be glad to recieve feedback, comments.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] JSON Dataset in FCL-DB.

2011-12-16 Thread Leonardo M . Ramé
From: Michael Van Canneyt 
>To: FPC mailing list ; Lazarus mailing list 
> 
>Sent: Friday, December 16, 2011 1:37 PM
>Subject: [fpc-pascal] JSON Dataset in FCL-DB.
> 
>
>Hello,
>
>I just committed a JSON dataset in fcl-db.
>
>This is a dataset which stores its data in JSON objects (as in fpjson) in 
>memory. The records are in a JSON array, each record can be a JSON object or 
>array.
>(not mixed)
>
>The dataset is read-write. It can be used to create JSON data from scratch: 
>just add definitions to the fielddefs properties, and call 'Open'. At the end, 
>call SaveToStream().
>
>There are 2 descendents which read/write ExtJS JSON data packages (Objects or 
>Arrays) from streams but they are usable to handle any kind of JSON data. 
>Currently, the dataset does not yet support propagating changes (deltas) back 
>to a server.
>
>I would be glad to recieve feedback, comments.
>
>Michael.



Does this allow executing selects against an sql database and traverse the 
results using this JSON dataset?
 
-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] JSON Dataset in FCL-DB.

2011-12-16 Thread Michael Van Canneyt



On Fri, 16 Dec 2011, Leonardo M. Ramé wrote:


From: Michael Van Canneyt 
To: FPC mailing list ; Lazarus mailing list  
Sent: Friday, December 16, 2011 1:37 PM

Subject: [fpc-pascal] JSON Dataset in FCL-DB.


Hello,

I just committed a JSON dataset in fcl-db.

This is a dataset which stores its data in JSON objects (as in fpjson) in 
memory. The records are in a JSON array, each record can be a JSON object or 
array.
(not mixed)

The dataset is read-write. It can be used to create JSON data from scratch: 
just add definitions to the fielddefs properties, and call 'Open'. At the end, 
call SaveToStream().

There are 2 descendents which read/write ExtJS JSON data packages (Objects or 
Arrays) from streams but they are usable to handle any kind of JSON data. 
Currently, the dataset does not yet support propagating changes (deltas) back 
to a server.

I would be glad to recieve feedback, comments.

Michael.




Does this allow executing selects against an sql database and traverse the 
results using this JSON dataset?


Yes. I use it as follows:

Normally, Fcl-web server using the sql-db and fpwebdata sends JSON-Formatted 
data to a browser.

I have now a lazarus-written client app which sends a HTTP request to the same webserver, 
reads the returned JSON, and then opens a dataset with the JSON as source of the data.


Combined with the Ext.Direct RPC, I intend to use this for N-tier apps where the client 
can be a native app or a browser.


What is missing currently is the delta to update data on the server, but that 
should be easily added.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] JSON Dataset in FCL-DB.

2011-12-16 Thread Leonardo M . Ramé
- Original Message -

> From: Michael Van Canneyt 
> To: FPC-Pascal users discussions 
> Cc: Lazarus mailing list 
> Sent: Friday, December 16, 2011 2:53 PM
> Subject: Re: [fpc-pascal] JSON Dataset in FCL-DB.
> 
> 
> 
> On Fri, 16 Dec 2011, Leonardo M. Ramé wrote:
> 
>>  From: Michael Van Canneyt 
>>>  To: FPC mailing list ; Lazarus 
> mailing list  
>>>  Sent: Friday, December 16, 2011 1:37 PM
>>>  Subject: [fpc-pascal] JSON Dataset in FCL-DB.
>>> 
>>> 
>>>  Hello,
>>> 
>>>  I just committed a JSON dataset in fcl-db.
>>> 
>>>  This is a dataset which stores its data in JSON objects (as in fpjson) 
> in memory. The records are in a JSON array, each record can be a JSON object 
> or 
> array.
>>>  (not mixed)
>>> 
>>>  The dataset is read-write. It can be used to create JSON data from 
> scratch: just add definitions to the fielddefs properties, and call 
> 'Open'. At the end, call SaveToStream().
>>> 
>>>  There are 2 descendents which read/write ExtJS JSON data packages 
> (Objects or Arrays) from streams but they are usable to handle any kind of 
> JSON 
> data. Currently, the dataset does not yet support propagating changes 
> (deltas) 
> back to a server.
>>> 
>>>  I would be glad to recieve feedback, comments.
>>> 
>>>  Michael.
>> 
>> 
>> 
>>  Does this allow executing selects against an sql database and traverse the 
> results using this JSON dataset?
> 
> Yes. I use it as follows:
> 
> Normally, Fcl-web server using the sql-db and fpwebdata sends JSON-Formatted 
> data to a browser.
> 
> I have now a lazarus-written client app which sends a HTTP request to the 
> same 
> webserver, 
> reads the returned JSON, and then opens a dataset with the JSON as source of 
> the 
> data.
> 
> Combined with the Ext.Direct RPC, I intend to use this for N-tier apps where 
> the 
> client 
> can be a native app or a browser.
> 
> What is missing currently is the delta to update data on the server, but that 
> should be easily added.
> 
> Michael.


Thanks. 

Btw. I've found this dependency related error when I tried to compile.

...
PPU Loading /usr/local/lib/fpc/2.7.1/units/x86_64-linux/fcl-web/fpwebdata.ppu
Recompiling fpwebdata, checksum changed for db
Fatal: Can't find unit fpwebdata used by fpjsondataset
...

--  
Leonardo M. Ramé
http://leonardorame.blogspot.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] JSON Dataset in FCL-DB.

2011-12-16 Thread Michael Van Canneyt



On Fri, 16 Dec 2011, Leonardo M. Ramé wrote:

What is missing currently is the delta to update data on the server, but that 
should be easily added.


Michael.



Thanks. 

Btw. I've found this dependency related error when I tried to compile.



Fixed in revision 19858.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] inline and other modifiers

2011-12-16 Thread Bernd
I have the following:

unit foo;

{$mode objfpc}{$H+}

interface
uses
  foobar;

function BitCnt(ABitmap: TBitBoard): Integer;

implementation

{$ifdef cpu386}
function BitCnt(ABitmap: TBitBoard): Integer; assembler; register; nostackframe;
asm
  ...
end;
{$else}
function BitCnt(ABitmap: TBitBoard): Integer; inline;
begin
  ...
end;

This seems to compile and work as intended, no matter which of the two
implementations I choose. But I wonder how this can work? I always
thought that what is written in the interface section is
authoritative. How can the compiler properly use this unit and call
the function when the implementation actually implements a completely
different calling convention (inline) than the one that is declared in
the interface section?

Bernd
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] inline and other modifiers

2011-12-16 Thread Jonas Maebe

On 16 Dec 2011, at 21:36, Bernd wrote:

> This seems to compile and work as intended, no matter which of the two
> implementations I choose. But I wonder how this can work? I always
> thought that what is written in the interface section is
> authoritative. How can the compiler properly use this unit and call
> the function when the implementation actually implements a completely
> different calling convention (inline) than the one that is declared in
> the interface section?

Inline is not a calling convention, nor does it affect the calling convention.


Jonas___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Testing applications with FPCUnit

2011-12-16 Thread Luciano de Souza
Perhaps becouse I am not an experienced programer, but the code sounds a 
little complex. However, the effort will bring large bennefits.


Thank you very much for the article. It will help me a lot.



Em 16/12/2011 11:44, Michael Van Canneyt escreveu:



On Fri, 16 Dec 2011, Vincent Snijders wrote:


2011/12/16 luciano de souza :

Hello listers,

Navigating in FPC source codes, I found fpcunit. It's really
wonderful. With the tTestCase class, we can  generate a report with
the success or the failure of our tests.

Is there documentation on the usage of fpcunit? What is the best way
to study it?


Google found this (old) article:
http://www.freepascal.org/olddocs-html/fpcunit.pdf


It is old, but still correct.

I will see about refreshing it, and adding it in the FPC documentation.

Michael.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal



--
Luciano de Souza
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

[fpc-pascal] CPU registers and function calls, unclear explanation in the docs

2011-12-16 Thread Bernd
The programmer's guide says in chapter 6.3 that when using "register"
convention then it does not save any registers. A very old version of
this document even said explicitly: "The registers are not saved when
calling a function or procedure", this sentence is no longer in the
programmer's guide but the table 6.3 still says "None" in the column
"registers saved". I interpreted this as "when calling such a function
or procedure it [the function] will not save any registers" or in
other words If I write such a function myself I can do with eax, edx,
ecx, ebx, edi, esi inside my function whatever I want and don't need
to save and restore them, the caller is responsible.

But this does not seem to be true. It seems it will assume that at
least certain registers are saved by the callee, ebx is one of them I
found today by accident because the caller used it as the loop
variable and I believe there are other registers too. Or is this
"none" meant from the perspective of the callee and means that the
*caller* will not save any registers *before* the call? IMHO this
section of the manual is a bit vague or ambiguous and could be
clarified. (btw. there is also something written about "GCC registers"
without mentioning anywhere what a "GCC register" actually is)

Is there maybe any other document somewhere that describes what
*exactly* is expected by the compiler to happen with the registers
during a function call or maybe somebody can show me where in the FPC
sources I have to look to see for myself what exactly is going on?

with exactly I also mean such little details like for example if a
function returns QWord then it returns them in eax and edx but if it
does only return a DWord then can I still use edx for other things and
the caller will just ignore it or will it then be owned by the caller?
And what if it is a procedure (no return value at all) who will then
own eax?

Bernd
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] CPU registers and function calls, unclear explanation in the docs

2011-12-16 Thread Jonas Maebe

On 17 Dec 2011, at 01:46, Bernd wrote:

> Is there maybe any other document somewhere that describes what
> *exactly* is expected by the compiler to happen with the registers
> during a function call or maybe somebody can show me where in the FPC
> sources I have to look to see for myself what exactly is going on?

On i386 with the "register" calling convention,
* eax, ecx and edx are volatile (= caller can overwrite them without saving 
them)
* ebx, esi, edi, ebp and esp and non-volatile (= caller must save/restore them 
if it overwrites them)

On other platforms (including x86-64), all calling conventions follow the 
official platform ABI as far as volatile/non-volatile registers are concerned.


Jonas___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] CPU registers and function calls, unclear explanation in the docs

2011-12-16 Thread Jonas Maebe

On 17 Dec 2011, at 01:59, Jonas Maebe wrote:

> On 17 Dec 2011, at 01:46, Bernd wrote:
> 
>> Is there maybe any other document somewhere that describes what
>> *exactly* is expected by the compiler to happen with the registers
>> during a function call or maybe somebody can show me where in the FPC
>> sources I have to look to see for myself what exactly is going on?
> 
> On i386 with the "register" calling convention,
> * eax, ecx and edx are volatile (= caller can overwrite them without saving 
> them)
> * ebx, esi, edi, ebp and esp and non-volatile (= caller must save/restore 
> them if it overwrites them)

Sorry, caller -> callee


Jonas___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] initializing pointer values

2011-12-16 Thread noreply
>
>
> On Fri, 16 Dec 2011, dhkblas...@zeelandnet.nl wrote:
>
>>
>> On implementing a linked list I hit to some unexpected (doesn't mean
>> incorrect though) behaviour.
>>
>>  
>>
>>   ptest = ^test;
>>   test = record
>>      p: pointer;
>>   end;
>>
>>  
>>
>>   new(mytest);
>>
>>  
>>
>> When I allocate "mytest" the pointer variable "p" is initialized as
>> $ instead of nil as I did suspect. In my code though I am
>> relying on the fact that new pointers are indeed nil so I can allocate
>> them accordingly. How can I force and rely on the fact that
>> p is always nil? What is the correct procedure here?
>
> Newly allocated memory is never zeroed out. You must do this manually with
> FillChar or FillWord.
> This is only done automatically for class instances.
>
> I will add a note to the docs.
>
> Michael.

Also you can Zero out records using:

var r: TSomeRec = ();

Or access the record fields and nil out the ones you want, but () gets it
all done in one shot.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal