Re: [fpc-pascal] Testing set membership for unicode chars
Thanks, I'll have a look at it. On 2013/01/21 04:07 PM, Honza wrote: > 2013/1/20 Paul Ishenin : >> 20.01.13, 23:21, Wimpie Nortje пишет: >>> Hi list >>> >>> I want to test membership of a unicode char in a set / array of unicode >>> chars. Something like >>> >>> var ucCh: unicodechar; >>> >>> if ucCh in [ UnicodeChar('0')..UnicodeChar('9')] then >>> dosomething; >>> >>> I am using fpc 2.6.0 and the '..' operator converts the data to a pascal >>> set, which is limited to 1 byte data. >>> >>> Is there another way? >> Delphi has CharInSet() function for this: >> http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/SysUtils_CharInSet@ansic...@tsyscharset.html >> >> I don't remember whether we have it in FPC at the moment. > Don't know if it can be helpful for the OP, but some years ago, I sent > 'Unicode category membership checking functions' here: > http://bugs.freepascal.org/view.php?id=16400 > > Please feel free to use that code for whatever you want w/o restrictions. > > -j > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Testing set membership for unicode chars
Thanks, I had already written a CharInSet(UnicodeChar; UnicodeString) function, but I hoped there were a language construct equivalent to the ansi char method. On 21 January 2013 10:32, Marco van de Voort wrote: > In our previous episode, Paul Ishenin said: > > > > > > I am using fpc 2.6.0 and the '..' operator converts the data to a > pascal > > > set, which is limited to 1 byte data. > > > > > > Is there another way? > > Delphi has CharInSet() function for this: > > > http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/SysUtils_CharInSet@ansic...@tsyscharset.html > > > > I don't remember whether we have it in FPC at the moment. > > 2.6.0 has it iirc, but before you point to that, it only checks the low > byte. IOW it is a stop gap, not a solution for set of char in the unicode > world. > > Since unicode printable characters are effectively strings, if you want a > pure set you will probably have to treat it as a hash or so. > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Testing set membership for unicode chars
Hi list I want to test membership of a unicode char in a set / array of unicode chars. Something like var ucCh: unicodechar; if ucCh in [ UnicodeChar('0')..UnicodeChar('9')] then dosomething; I am using fpc 2.6.0 and the '..' operator converts the data to a pascal set, which is limited to 1 byte data. Is there another way? Thanks Wimpie ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Linux sound (especially MIDI) programming: ALSA?
On 2012/05/06 05:49 PM, Mark Morgan Lloyd wrote: > Wimpie Nortje wrote: >> I have used ALSA to record sound. It was some time ago, I think on >> Kubuntu 10.04 or so. >> >> I can send you some code I used but I have no idea whether it will work >> under newer Linux's > > Thanks, but since it's specifically MIDI I'm interested in it might > not be relevant. > > Can you remember which Pascal interface to the ALSA libraries you were > using? I think I've seen two, but I've not yet checked to see whether > they were actually minor variants of the same thing. > > The readme file says: ALSAPAS (ALSA library for Pascal) Version 0.9.7, September 2003. Copyright (c) 2002-2003, Pedro Lopez-Cabanillas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Linux sound (especially MIDI) programming: ALSA?
I have used ALSA to record sound. It was some time ago, I think on Kubuntu 10.04 or so. I can send you some code I used but I have no idea whether it will work under newer Linux's On 2012/05/06 10:09 AM, Mark Morgan Lloyd wrote: > Has anybody used FPC to control ALSA on Linux? I need to filter a MIDI > stream in real time, and handle transposition etc. > > If anybody knows of useful resources I'd appreciate any hints. > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Stunnel replaced by FPC?
Have a look at BEEP (beepcore.org) and Vortex (www.aspl.es/vortex). I think it covers all of your requirements. Currently the closest to a Pascal version is BeepFp, which uses Vortex. BeepFp is however not finished yet, so it may or may not work for you. On 2011/10/13 01:15 PM, Reinier Olislagers wrote: > Hi list, > > For my remote assistance screen sharing project > https://bitbucket.org/reiniero/checkride/ > I'm currently using stunnel on Windows to tunnel VNC traffic over an > SSL/TLS tunnel. > > Can I replace stunnel with e.g. Synapse code? The Synapse documentation > only shows https examples. > > I'd like to tunnel stuff (right now VNC traffic) over an encrypted > connection, preferably with the option to authenticate both ends (e.g. > use certificates). > > It there is a possibility for multiplexing (in my case: push VNC as well > as text chat, voice chat, commands, responses through the tunnel and > deal with it at the other end) that would be great. > > Cross-platform ability would be a big plus. > > Any thoughts/hints/links to documentation/stories? > > Thanks, > Reinier > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Self pointer existence
Thanks > There is probably a bug in your code, but without seeing the code > there is no way to tell. It was something to do with converting strings to pchar before passing to a C library. Looks like it is fixed now ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Self pointer existence
Hi When does the self pointer's value become valid? I need a reference to the object being created inside the object's own create method. The last statement in Create uses self, but that causes program crashes. Is this too early to use self? Is there another way? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Variable argument list for cdecl functions
Hi How do one access the array of const members for a function declared as cdecl? Eg. function A(args: array of const): integer;cdecl; I get a warning that cdecl'ared functions have no high parameter, which now makes sense to me since I tried to use High(args) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Sharing dynamic arrays between threads
> Calling dispose() on a record with a dynamic array field will free the > array (and recursively finalize all its elements) as long as the > pointer on which you call it is correctly typed in the source code. > The fact that you still get memory leaks after everything you are > doing suggests that something else is wrong in your program. > Thank you. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Sharing dynamic arrays between threads
Thanks for the resonse Jonas >> Is it safe to create a dynamic array with setlength() in one thread and >> free the array using finalize() in another thread? > > Normally, you should not call finalize() on dynamic arrays. When the > last reference to a dynamic array goes out of scope, it is finalised > automatically. It is safe when this happens in a different thread than > the one in which it was created. I have a producer thread that allocates memory for a record using new(). This record also contains a dynamic array, which is allocated with setlength(). The record address is then put in a TThreadList. The consumer thread gets the record address from the TThreadlist and processes the data. The memory must then be free'd, in the consumer thread. Initially I only disposed the record. This lead to lots of memory leaks. Then I set dynarray:= nil before disposing the record. Less mem leaks, but still a lot. Then I started to finalize the dynamic array before disposing the record. A huge improvement but still some leaks. I get the feeling the arrays are sometimes not free'd but I don't understand why. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Sharing dynamic arrays between threads
Hi, Is it safe to create a dynamic array with setlength() in one thread and free the array using finalize() in another thread? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Context of TThread.OnTerminate
Thanks Mattias and Michael On 2011/02/24 05:51 PM, michael.vancann...@wisa.be wrote: > > > On Thu, 24 Feb 2011, Wimpie Nortje wrote: > >> Hi everybody, >> >> The manual (possibly Delphi one) says that TThread.OnTerminate executes >> in the GUI thread. This is easy if the GUI thread owns the TThread. >> >> Suppose the GUI owns a TTHread which owns a subthread. In which context >> does the subthread's OnTerminate execute? > > Always the main thread; no matter in which thread a thread was started. > > There simply is no information about which thread has started another > particular thread. > > Michael. > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Context of TThread.OnTerminate
Hi everybody, The manual (possibly Delphi one) says that TThread.OnTerminate executes in the GUI thread. This is easy if the GUI thread owns the TThread. Suppose the GUI owns a TTHread which owns a subthread. In which context does the subthread's OnTerminate execute? Thanks ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Dynamic array as result of class method?
TByteDynArray is defined in unit 'types' On 2010/11/07 12:23 PM, Jonas Maebe wrote: > > On 07 Nov 2010, at 11:05, Bo Berglund wrote: > >>function Read(Count: Cardinal): array of byte; overload; >> end; >> >> But when I use the Ctrl-Shift-C command on this to make Lazarus >> complete the code I get an error on the second Read line: >> sscomm.pas(40,37) Error: identifier expected, but array found >> >> Is it illegal to specify a dynamic array as the result type of a >> function? > > No, but you cannot declare it inline, just like you cannot have > > function read(count: cardinal): record b: byte end; > > Use a separately defined type: > > type > tbytearray = array of byte; > > > Jonas > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] [ANN] BeepFp v1.1 released
I don't understand what you mean Johann Glaser wrote: Isn't that as easy as just using Write(^G); ? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] [ANN] BeepFp v1.1 released
Release note: - BeepFp 1.1 was released on April 18, 2010. BeepFp is a Free Pascal component to provide BEEP services in the object pascal language. It is written as a binding on top of Vortex library. Changes from v1.0 --- - BeepFp events are now triggered inside the main application thread. Received data can be used safely inside the Lazarus GUI. - A Lazarus component is included to manage thread synchronisation. Managing threads is automatically, just drop the component on a form. - BeepFp does not require Lazarus nor a GUI. It works in any kind of FP program. - Various fixes and improvements More information can be found at http://wiki.lazarus.freepascal.org/BeepFp The component can be download from http://sourceforge.net/projects/lazarus-ccr/files/BeepFp/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Determining procedure's name
Thanks, I will look at the suggestions Mattias Gaertner wrote: On Wed, 03 Mar 2010 21:33:45 +0200 Wimpie Nortje wrote: Hello everybody, Is there a macro or function that gives the current procedure's name? E.g. procedure TClass.SomeProc; begin writeln(Format('This procedure's name is %s', [THE_MACRO])); end; If you use Lazarus you can create a code template. Then you can type w plus Ctrl+J and you will get: writeln(Format('This procedure's name is %s', ['TClass.SomeProc'])); I prefer writeln('TClass.SomeProc '|); The | symbol is where the cursor is positioned after the template was added. should print This procedure's name is TClass.SomeProc or This procedure's name is SomeProc Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Determining procedure's name
Hello everybody, Is there a macro or function that gives the current procedure's name? E.g. procedure TClass.SomeProc; begin writeln(Format('This procedure's name is %s', [THE_MACRO])); end; should print This procedure's name is TClass.SomeProc or This procedure's name is SomeProc ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Thread IDs
I found some inconsistencies a couple of months ago, but never got to creating a bug report: http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg17337.html lists.freepascal.org seems down, so I found this link. VIncent ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal Bug report created. http://bugs.freepascal.org/view.php?id=15821 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Thread IDs
Jonas Maebe wrote: On 18 Feb 2010, at 16:35, Wimpie Nortje wrote: What is the difference between GetThreadID() and GetCurrentThreadID()? There is a threadvar called "threadid" in the system unit. When a new thread is started, GetCurrentThreadID is called to obtain the thread id of the new thread (via the thread manager) and the result is stored in the threadid threadvar. GetThreadID simply returns the value of this threadvar. So in summary: there is no semantic difference. They return different values. I think GetCurrentThreadID is the more trustworthy one. When control returns to my main thread then GetCurrentThreadID = MainThreadID and GetThreadID <>MainThreadID ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Thread IDs
Hello list, What is the difference between GetThreadID() and GetCurrentThreadID()? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] C thread callbacks
Hi I have a C library that uses threads. These threads use callbacks into my pascal for events. What must happen for the pascal events handlers to be able to safely access the main thread's resources? This is the same situation where I would use TThread.Synchronize if the threads were TThread objects. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] YAML support
JSON is not related to YAML at all except in that it is a simple data format. That's true, but from the yaml v1.2 spec: "YAML can therefore be viewed as a natural superset of JSON, offering improved human readability and a more complete information model. This is also the case in practice; every JSON file is also a valid YAML file." And as far as I can see from the specs, YAML also does not offer a direct way to capture binary data. That is also true. I got the impression from wikipedia that YAML has a direct way to capture the binary data. From the specs I see that YAML uses base64 coding for binary data, which was what I hoped to prevent because it causes a lot of computation overhead. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] YAML support
Hi list, Are there plans to implement YAML? I found JSON support but that is missing a feature I would like to use. Apparently JSON is a subset of YAML, but it doesn't have a direct way to capture binary data. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Swopping two items in TCollection
Done. http://bugs.freepascal.org/view.php?id=15517 Michael Van Canneyt wrote: Please do, this way we won't forget it. Michael. On Thu, 14 Jan 2010, Wimpie Nortje wrote: Thanks. An exhange() would be usefull. Should I file a bug report? Michael Van Canneyt wrote: On Thu, 14 Jan 2010, Wimpie Nortje wrote: Hi list I have a class derived from Tcollection, holding items derived from TCollectionItem. How do I swop two items in the collection? FItem is of type TList which has an exchange function, but that is private and not accessable to me. You can set the Items' Index property. Maybe we should introduce a method Exchange(I,J : Integer) which does this automatically in 1 go. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Swopping two items in TCollection
Thanks. An exhange() would be usefull. Should I file a bug report? Michael Van Canneyt wrote: On Thu, 14 Jan 2010, Wimpie Nortje wrote: Hi list I have a class derived from Tcollection, holding items derived from TCollectionItem. How do I swop two items in the collection? FItem is of type TList which has an exchange function, but that is private and not accessable to me. You can set the Items' Index property. Maybe we should introduce a method Exchange(I,J : Integer) which does this automatically in 1 go. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Swopping two items in TCollection
Hi list I have a class derived from Tcollection, holding items derived from TCollectionItem. How do I swop two items in the collection? FItem is of type TList which has an exchange function, but that is private and not accessable to me. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Where do I contribute units to?
Hi all I have translated a C header file for interfacing with a National Instruments data acquisition device. This is a standalone, independant unit which will rarely if ever change. It also has no dependancy on lazarus. Where is the best place to put these kinds of files? The lazarus CCR? I had a look at the 'Contributed Units' page on FPC wiki but that page does not seem to be used a lot. Thanks Wimpie ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Using C functions
Jonas Maebe wrote: On 21 Nov 2009, at 20:16, Wimpie Nortje wrote: Is there any way to use a C library that use the __fastcall calling convention? Not at this time. Also note that that the fastcall convention is not standardised and varies between different C compilers. Thanks, I thought so. I am considering to write a C library (cdecl) to wrap the calls to the C library(fastcall), but it doesn't feel right. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Using C functions
Hi all, Is there any way to use a C library that use the __fastcall calling convention? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] h2pas truncates strings
indent can only add or delete whitespace. Comments that start with // and extend beyond the -lcn limit are left alone. Henry Vermaak wrote: 2009/11/10 Wimpie Nortje : Ok, I've tried indent and it doesn't do the job because the comments are also 400 chars long. >From indent man page: -ln, --line-lengthn Set maximum line length for non-comment lines to n. See BREAKING LONG LINES. -lcn, --comment-line-lengthn Set maximum line length for comment formatting to n. See COMMENTS. Henry ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] h2pas truncates strings
Ok, I've tried indent and it doesn't do the job because the comments are also 400 chars long. I also tried to add {$H+} to the top of h2pas.pas but the solution is not that easy. If someone could give me a pointer of where to start, maybe I can try to fix it. For starters, what is the yacc and lex files for? Henry Vermaak wrote: 2009/11/10 Wimpie Nortje : Hallo I am trying to convert a .h to pascal with h2pas. The header file contains many declarations with lines of 400 characters or longer. h2pas creates the *.tmp.h file with all the code intact but the .pas file's lines are cut off at 256 characters. Is there an easy way around this problem, ie not manually changing the .h file? I guess patching h2pas for this is the right thing to do, but as a workaround you can always run `indent` over the h file first to chop the lines. Henry ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] h2pas truncates strings
Thanks, I will try that. Henry Vermaak wrote: 2009/11/10 Wimpie Nortje : Hallo I am trying to convert a .h to pascal with h2pas. The header file contains many declarations with lines of 400 characters or longer. h2pas creates the *.tmp.h file with all the code intact but the .pas file's lines are cut off at 256 characters. Is there an easy way around this problem, ie not manually changing the .h file? I guess patching h2pas for this is the right thing to do, but as a workaround you can always run `indent` over the h file first to chop the lines. Henry ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] h2pas truncates strings
Hallo I am trying to convert a .h to pascal with h2pas. The header file contains many declarations with lines of 400 characters or longer. h2pas creates the *.tmp.h file with all the code intact but the .pas file's lines are cut off at 256 characters. Is there an easy way around this problem, ie not manually changing the .h file? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Stopping daemon in linux
Joost van der Sluis wrote: On Mon, 2009-11-09 at 13:02 +0200, Wimpie Nortje wrote: Michael Van Canneyt wrote: It should stop the daemons properly. This is the code that gets executed: Procedure DoShutDown(Sig : Longint; Info : PSigInfo; Context : PSigContext); cdecl; begin Application.StopDaemons(True); Application.Terminate; end; If it doesn't, something is wrong :( I think something is wrong. :( For my TDaemon descendant I assigned the following events: OnDestroy OnExecute OnPause OnShutdown OnStart OnStop When I type "./daemon -r &" The following handlers are executed: 1. OnStart 2. OnExecute When I type "kill -TERM daemon_pid" The following handler is executed 1. OnDestroy I am also a bit confused by the wiki. According to the wiki Start and stop are triggered under linux but shutdown is not. The 'Taming the daemon' article does not specify which of these 3 are called under linux. As I mentioned earlier, I use FPC 2.2.4. Could that be the problem? I don't know how I did it exactly, but I ahve this working properly in a production system. (Even created my own SysV init script for it. It should be generally usable for all fpc-daemon applications) But I did use fpc 2.3.1, so try the new 2.4.0rc1. And I think that it won't work always now I've read Jonas' mail about it. Maybe I'll look at that later. Thanks, I will try the new compiler. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Stopping daemon in linux
Michael Van Canneyt wrote: It should stop the daemons properly. This is the code that gets executed: Procedure DoShutDown(Sig : Longint; Info : PSigInfo; Context : PSigContext); cdecl; begin Application.StopDaemons(True); Application.Terminate; end; If it doesn't, something is wrong :( I think something is wrong. :( For my TDaemon descendant I assigned the following events: OnDestroy OnExecute OnPause OnShutdown OnStart OnStop When I type "./daemon -r &" The following handlers are executed: 1. OnStart 2. OnExecute When I type "kill -TERM daemon_pid" The following handler is executed 1. OnDestroy I am also a bit confused by the wiki. According to the wiki Start and stop are triggered under linux but shutdown is not. The 'Taming the daemon' article does not specify which of these 3 are called under linux. As I mentioned earlier, I use FPC 2.2.4. Could that be the problem? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Stopping daemon in linux
Marc Santhoff wrote: You can send any defined signal using kill. Try: # kill -TERM for sending the TERM signal. At least FreeBSDs kill works that way. If yours doesn't try: That is what I did. This doesn't run my daemon's exit routines. I don't know if Linux just kills the daemon or if the daemon receives the signal and exits properly without calling the exit routines. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Stopping daemon in linux
Marco van de Voort wrote: No plans yet. The problem is also a bit that whatever you do is an island. I think this is more something for freedesktop to standarize first. I know there is a standard/recomended way to write a daemon. If you use KDevelop it will create such a template. I don't know if that includes stopping the daemon but I will have a look there. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Stopping daemon in linux
Marco van de Voort wrote: In our previous episode, Wimpie Nortje said: I am writing an application using lazdaemon. How does one stop the daemon gracefully, ie not killing it. The wiki says the daemon runs until it receives the TERM signal. THe only way I know to send the TERM signal is using 'kill'. This kills the app rather letting it exit gracefully. Known issue, see http://bugs.freepascal.org/view.php?id=14741 there are some more signals that are handled. Are there plans to fix/change this, or must I implement some kind of pid check myself? I also see a mention of a '-b' parameter in the report but it doesn't daemonize my application. Is it new? I am using fpc 2.2.4 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Stopping daemon in linux
Hi I am writing an application using lazdaemon. How does one stop the daemon gracefully, ie not killing it. The wiki says the daemon runs until it receives the TERM signal. THe only way I know to send the TERM signal is using 'kill'. This kills the app rather letting it exit gracefully. Thanks Wimpie ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Byte array manipulation
Andrew Brunner wrote: Hi there, I have a ByteArray unit that's pretty extensive. function toString(Var Item:TByteArray):string var iLen:Integer; begin iLen:=System.Length(Item); SetLength(Result,iLen); if iLen>0 then System.Move(Item[0],Result[1],iLen); end; Thanks, this will be a useful function. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Byte array manipulation
theo wrote: AnsiString does not have problems with #0. Test: var aStr:AnsiString; begin aStr:='test-test-test'; aStr:=StringReplace(aStr,'-',#0,[rfReplaceAll]); //if you ouput now, you'll only see 'test'... aStr:=StringReplace(aStr,#0,'-',[rfReplaceAll]); //...but the text is still in the String; Edit1.text:=aStr; end; Thanks. I tested it and it works. The reference manual is a bit confusing though: "Ansistrings are strings that have no length limit. They are reference counted and null terminated." "i.e. a variable of type PChar is a pointer that points to an array of type Char, which is ended by a null-character (#0). " The above quotes does not agree with the code above, which makes discovering this info a bit difficult. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Byte array manipulation
Hi all, I have a lot of byte arrays which contains mostly text but also #0. I am looking for functions to manipulate these arrays. The stuff in strutils are mainly what I need but they operate on strings which is not usable to me due to the #0. Are there any such functions in FPC? And while I am onto strings...does anyone know of a quick and easy way to convert strings to a byte array. Much like aPchar := PChar(aString)? Thanks Wimpie ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Stack problem in externally called callback function
Jonas Maebe wrote: I think the "easiest" way for you to do this would be to do something similar to what the FPC rtl does: write your own function that does all of this initialisation, and pass that one to pthread_create as the function to run in the new thread. Then from this function perform all initialisation, and finally call the original function. Thanks. I have done this and it is working. It is not the ideal solution thoughBeginThread expects a 'register' function as the thread function, while the library provides a 'cdecl' function. This means I had to wrap the C thread function into another function call. So there are now quite a bit of layering happening on top of the original thread function. I think it would be good if BeginThread can accept both register functions and cdecl functions. And then I hope the library author accept my changes. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Stack problem in externally called callback function
The FPC thread setup code (CAllocateThreadVars, InitThread) happens inside the newly created thread before the user's thread function starts. The only viable way I see to get support from the C library is for it to inform FPC about a new thread after creation, but this means that the C user's thread function has already started executing when FPC gets the new ID. Is it possible to do the FPC thread setup from outside the new thread? Suppose this setup can be completed before the library starts calling FPC callbacks, would all the current memory problems then be solved? Jonas Maebe wrote: On 02 Aug 2009, at 20:02, Wimpie Nortje wrote: Thanks for the response. The library uses a centralised function to start all its threads using pthread_create. If I can make this central function inform FPC about all the threads created, would this work? There is no interface in the RTL to inform it about newly created external threads, so it would be quite hard. Assuming it would work: what information would FPC require? When would this info be required, before or after thread creation? What needs to be done on the FPC side with this info? Look at rtl/unix/cthreads.pp, in the functions CBeginThread/ThreadMain and CEndThread (they also call generic code from rtl/inc/thread.inc, such as InitThread and DoneThread). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Stack problem in externally called callback function
Thanks, I'll have a look Jonas Maebe wrote: On 02 Aug 2009, at 20:02, Wimpie Nortje wrote: Thanks for the response. The library uses a centralised function to start all its threads using pthread_create. If I can make this central function inform FPC about all the threads created, would this work? There is no interface in the RTL to inform it about newly created external threads, so it would be quite hard. Assuming it would work: what information would FPC require? When would this info be required, before or after thread creation? What needs to be done on the FPC side with this info? Look at rtl/unix/cthreads.pp, in the functions CBeginThread/ThreadMain and CEndThread (they also call generic code from rtl/inc/thread.inc, such as InitThread and DoneThread). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Stack problem in externally called callback function
Thanks for the response. The library uses a centralised function to start all its threads using pthread_create. If I can make this central function inform FPC about all the threads created, would this work? Assuming it would work: what information would FPC require? When would this info be required, before or after thread creation? What needs to be done on the FPC side with this info? Wimpie Jonas Maebe wrote: On 31 Jul 2009, at 19:05, Wimpie Nortje wrote: I am trying to use a shared lib written in C in my FPC program. The lib creates a number of threads and requires callbacks into the main app. It can call the callback from any of the threads. Calling FPC code from threads not created by FPC does not work at this time on any unix-like platform. When I compile without stack checking everything (seems) to work fine but when stack checking is on I get stack error (error 202) on entry to the callback function. I can break on the callback's 'begin' and see valid values for all the function parameters but when I step into the function body it crashes. That's because the stack checking has to be initialised per thread and this is normally done when you create a thread via tthread.create() or beginthread(). Disable stack checking. I say 'seems' when not using stack checking because when the app becomes large I get a lot of strange problems which would probably be explained by stack problems. No, the problems are probably due to the FPC rtl not being initialised for multi-threading. You will probably get slightly less problems if you include the "cthreads" unit in your uses-clause and create a dummy thread as soon as your program starts (after which you can destroy it again), but even then you will get memory leaks and sporadic random errors due to threadvars containing wrong values. As said above: it does not work at this time (under unix-like platforms; in 2.3.1, it should work on Windows). The reason that it does not work on Unix-like platforms, is that there is no way to make libthread inform FPC whenever a thread is created (while this is possible on Windows), so the FPC rtl cannot initialise the per-thread information properly. There is no known way to fix this problem (although some people have guesses, no one really knows for sure). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Stack problem in externally called callback function
Hi everybody, I am trying to use a shared lib written in C in my FPC program. The lib creates a number of threads and requires callbacks into the main app. It can call the callback from any of the threads. When I compile without stack checking everything (seems) to work fine but when stack checking is on I get stack error (error 202) on entry to the callback function. I can break on the callback's 'begin' and see valid values for all the function parameters but when I step into the function body it crashes. I say 'seems' when not using stack checking because when the app becomes large I get a lot of strange problems which would probably be explained by stack problems. The .h file: typedef int (*VortexOnAcceptedConnection) (VortexConnection * connection, axlPointer data); The pascal file: type PVortexConnection = Pointer; TaxlPointer = Pointer; TVortexOnAcceptedConnection = function (connection:PVortexConnection; data:TaxlPointer):longint;cdecl; {This is the callback function called by the C library. It never gets called from the pascal code.} function on_accepted(connection: PVortexConnection; data: TaxlPointer): longint;cdecl; begin Result := 1; end; I have tried all the function modifiers, they all give the same problem. I run fpc 2.2.4 on Kubuntu 9.04. I ran the C version of this test application using valgrind and it doesn't give a single problem. Any ideas or opinions will be appreciated. Wimpie ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal