Re: [fpc-pascal] Get user ID for name on Linux

2018-01-03 Thread Giuliano Colla

  
  
Il 03/01/2018 01:12, Tobias Giesen ha scritto:


  I would like to get the user ID for a Linux user name.


You might execute from the application the "/usr/bin/id" command
which should exist in any Linux flavour passing the required user
name ( if it's the current user, UserName :=
GetEnvironmentVariableUTF8('USERNAME'); ) as a parameter and then
parse the resulting output, sort of:

uid=500(colla) gid=500(colla)
  groups=500(colla),3(sys),5(tty),18(dialout)

Giuliano

  

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

Re: [fpc-pascal] Get user ID for name on Linux

2018-01-03 Thread Tobias Giesen
Many thanks! That's great. The completeness of FPC units and packages is really
astonishing.

Cheers,
Tobias



On Wed, 3 Jan 2018 06:36:32 +
Graeme Geldenhuys  wrote:

> On 2018-01-03 00:12, Tobias Giesen wrote:
> > Unfortunately Libc and UnixUtils don't seem to be available in 64-bit, so I 
> > can't call the
> > functions getpwnam or GetUserId.
> 
> As Marco said, you can use the "users" unit. Here is an example of how I 
> use in in fpGUI, and it supports 32-bit and 64-bit systems.
> 
>  
> https://github.com/graemeg/fpGUI/blob/develop/src/corelib/x11/fpg_x11.pas#L4010-L4044
> 
> Note though that it only works for Linux. So other UNIX-type systems 
> like FreeBSD and Solaris are not supported.
> 
> 
> Regards,
>Graeme
> 
> -- 
> fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
> http://fpgui.sourceforge.net/
> 
> My public PGP key:  http://tinyurl.com/graeme-pgp
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Kind Regards,
Tobias Giesen

Super Flexible Software Ltd. & Co. KG
Buddenstr. 29-31
48143 Münster, Germany
www.superflexible.com
www.tgtools.com

---
Registered at register court Münster as HRA 9716
Liability / general partner: TGTools Ltd.
Company No. 05513299
Registered in England and Wales
Directors: Tobias Giesen and Claudia Giesen

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

[fpc-pascal] Possible Memory Leak in TThread.Synchronize

2018-01-03 Thread Tony Whyman
I have been investigating a possible memory leak in a multi-threading 
Lazarus program compiled with 3.0.4 where the stack trace with heaptrc 
shows:


Heap dump by heaptrc unit
7014 memory blocks allocated : 131978472/131992352
7004 memory blocks freed : 114543216/114557096
10 unfreed memory blocks : 17435256
True heap size : 19267584
True free heap : 1831200
Should be : 1831048
Call trace for block $7FFFE2A9D0C0 size 96
  $0043B31A line 354 of ../inc/heap.inc
  $00450FE8 line 888 of ../unix/cthreads.pp
  $0043DB9F line 294 of ../inc/thread.inc
  $004AE6B4 line 322 of ../objpas/classes/classes.inc
  $004AE754 line 344 of ../objpas/classes/classes.inc
  $004AE7F0 line 357 of ../objpas/classes/classes.inc
  

Line 322 of classes.inc reads:

    FSynchronizeEntry^.SyncEvent := RtlEventCreate;

Hence the implication is that the SyncEvent is not being disposed of 
correctly. Later on TThread.DoneSynchronizeEvent reads


procedure TThread.DoneSynchronizeEvent;
  begin
    if not Assigned(FSynchronizeEntry) then
  Exit;

    RtlEventDestroy(FSynchronizeEntry^.SyncEvent);
    Dispose(FSynchronizeEntry);
    FSynchronizeEntry := Nil;
  end;

So no problem here it seems. However, investigating further, this is not 
the only place that a SynchronizeEvent is disposed of. At line 379 of 
classes.inc we see:


function CheckSynchronize(...)

and this ends with:

    else
  begin
  { for Queue entries we dispose the entry and raise the exception }
  Dispose(tmpentry);
  if Assigned(exceptobj) then
    raise exceptobj;
  end;
    tmpentry := PopThreadQueueHead;
    end;

The line "Dispose(tmpentry);" also disposes of a SynchronizeEvent but, 
unlike TThread.DoneSynchronizeEvent, there is no RtlEventDestroy.


Am I correct in pointing the finger here for the memory leak?

Tony Whyman

MWA


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

Re: [fpc-pascal] Possible Memory Leak in TThread.Synchronize

2018-01-03 Thread Michael Van Canneyt



On Wed, 3 Jan 2018, Tony Whyman wrote:



The line "Dispose(tmpentry);" also disposes of a SynchronizeEvent but, 
unlike TThread.DoneSynchronizeEvent, there is no RtlEventDestroy.


Am I correct in pointing the finger here for the memory leak?


I doubt it, since AFAIK the RTL event is a OS object, and as such is not 
allocated on the
heap ?

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

Re: [fpc-pascal] Possible Memory Leak in TThread.Synchronize

2018-01-03 Thread Tony Whyman
Thanks, I found the problem - the thread was not being destroyed 
correctly on completion and this manifested itself in what looked like a 
weird memory leak.



On 03/01/18 11:49, Michael Van Canneyt wrote:



On Wed, 3 Jan 2018, Tony Whyman wrote:



The line "Dispose(tmpentry);" also disposes of a SynchronizeEvent 
but, unlike TThread.DoneSynchronizeEvent, there is no RtlEventDestroy.


Am I correct in pointing the finger here for the memory leak?


I doubt it, since AFAIK the RTL event is a OS object, and as such is 
not allocated on the

heap ?

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



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

Re: [fpc-pascal] Possible Memory Leak in TThread.Synchronize

2018-01-03 Thread Sven Barth via fpc-pascal
Am 03.01.2018 12:32 schrieb "Tony Whyman" :


function CheckSynchronize(...)

and this ends with:

else
  begin
  { for Queue entries we dispose the entry and raise the exception }
  Dispose(tmpentry);
  if Assigned(exceptobj) then
raise exceptobj;
  end;
tmpentry := PopThreadQueueHead;
end;

The line "Dispose(tmpentry);" also disposes of a SynchronizeEvent but,
unlike TThread.DoneSynchronizeEvent, there is no RtlEventDestroy.

Am I correct in pointing the finger here for the memory leak?


I know you already found your problem, but nevertheless as explanation:
this code is only reached by asynchronously added events (TThread.Queue())
and there no event is needed, this none is freed or even allocated.

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Get user ID for name on Linux

2018-01-03 Thread geneb

On Wed, 3 Jan 2018, Tobias Giesen wrote:


Many thanks! That's great. The completeness of FPC units and packages is really
astonishing.


Is there a complete list of packages available somewhere?

tnx.

g.

--
Proud owner of F-15C 80-0007
http://www.f15sim.com - The only one of its kind.
http://www.diy-cockpits.org/coll - Go Collimated or Go Home.
Some people collect things for a hobby.  Geeks collect hobbies.

ScarletDME - The red hot Data Management Environment
A Multi-Value database for the masses, not the classes.
http://scarlet.deltasoft.com - Get it _today_!
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Get user ID for name on Linux

2018-01-03 Thread Marco van de Voort
In our previous episode, geneb said:
> 
> > Many thanks! That's great. The completeness of FPC units and packages is 
> > really
> > astonishing.
> >
> Is there a complete list of packages available somewhere?

There is some info(1) in the wiki, though many details are missing, and the
status of each package is not explicitely recorded.

There however is a page specific about the libc_unit (2) that named the
 "users" package as a replacement for certain calls.

(1) http://wiki.freepascal.org/Package_List
(2) http://wiki.freepascal.org/libc_unit
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] any existing units/libraries for sorting?

2018-01-03 Thread Dennis

I have a list of records (each with a few fields).
I want to let users display this list of records in ascending orders of 
any record field.

Is there any existing units/library I can use?

Thanks in advance.

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

Re: [fpc-pascal] any existing units/libraries for sorting?

2018-01-03 Thread Santiago A.
El 03/01/2018 a las 16:09, Dennis escribió:
> I have a list of records (each with a few fields).

What do you mean with list?
A TList? You can use sort method

-- 
Saludos

Santiago A.

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

Re: [fpc-pascal] any existing units/libraries for sorting?

2018-01-03 Thread Ryan Joseph
Determine the sorting key for each of the fields and use quick sort? If the 
field you’re sorting by is a name for example then use alphabetic order. Sounds 
like a generic sorting by comparison problem and doesn’t require any specific 
library.

> On Jan 3, 2018, at 10:09 PM, Dennis  wrote:
> 
> I have a list of records (each with a few fields).
> I want to let users display this list of records in ascending orders of any 
> record field.
> Is there any existing units/library I can use?
> 
> Thanks in advance.

Regards,
Ryan Joseph

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

Re: [fpc-pascal] any existing units/libraries for sorting?

2018-01-03 Thread Dennis Poon



Santiago A. wrote:

El 03/01/2018 a las 16:09, Dennis escribió:

I have a list of records (each with a few fields).

What do you mean with list?
A TList? You can use sort method


Thanks for the reminder. I forgot about it.

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

Re: [fpc-pascal] Get user ID for name on Linux

2018-01-03 Thread geneb

On Wed, 3 Jan 2018, Marco van de Voort wrote:


In our previous episode, geneb said:


> Many thanks! That's great. The completeness of FPC units and packages is 
really
> astonishing.
>
Is there a complete list of packages available somewhere?


There is some info(1) in the wiki, though many details are missing, and the
status of each package is not explicitely recorded.

There however is a page specific about the libc_unit (2) that named the
"users" package as a replacement for certain calls.


Thanks for the info Marco.
g
.

--
Proud owner of F-15C 80-0007
http://www.f15sim.com - The only one of its kind.
http://www.diy-cockpits.org/coll - Go Collimated or Go Home.
Some people collect things for a hobby.  Geeks collect hobbies.

ScarletDME - The red hot Data Management Environment
A Multi-Value database for the masses, not the classes.
http://scarlet.deltasoft.com - Get it _today_!
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal