Re: [fpc-pascal] Be careful of too many features
On 5/30/22 14:59, Steve Litt via fpc-pascal wrote: Hi all, In 1984 I started my programming career with Whitesmith Pascal, Sorry for the off-topic post, folks, but this just opened a wound from my distant past... :( I was a couple of years ahead of you, Steve, but at least in 1982 on the PDP-11, Whitesmith Pascal was a truly *awful* thing - a translation engine, not a compiler. It was a front end to Whitesmith C, which in turn translated to Macro-11 and then compiled and linked that (we watched these steps via RMD). The code produced was horribly inefficient (we looked at the Macro-11 listings), and using RSX-11M rather than M+, with no library space, code space was at a premium. We quickly switched to Oregon Pascal (which DEC later bought as the foundation of RSX Pascal) and it was a *far* superior compiler. Apart from the debugger, that is, which took up so much space that you could just about debug 'Hello, world' and that was it. Hopefully Whitesmiths improved in the couple of years before you started with it, or there was a better implementation if you used it on a machine other than a PDP-11. Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Linux Yad
Has anyone called Yad (linux file manager) as an external program form a main program ? If so can you provide an example of how to do it and retrieve the selected file name? Thanks Brian -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] 50 years of Pascal, by the the author himself
On 5/12/21 3:51 PM, Ryan Joseph via fpc-pascal wrote: On May 12, 2021, at 12:30 PM, Ralf Quint via fpc-pascal wrote: Thought this was kind of interesting, though it leaves short of mentioning the later Object Pascal evolution and thus Delphi and FreePascal... Isn't Free Pascal and Delphi basically the only Pascal compilers left? I used THINK Pascal and Metrowerks Pascal in the distant past but those are all long dead. You can't really talk about Pascal in 2021 without mentioning those 2 compilers. There are still some OpenVMS sites out there, which would lead you to assume that VAX Pascal is still alive and kicking, albeit very much a minority compiler. Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Sending Hex codes over TCP/IP
Use Ararat Synapse . http://synapse.ararat.cz/doc/help/ Unit blcksock Class TTCPBlockSocket Then send and receive byte arrays using : Public function SendBuffer(Buffer: TMemory; Length: Integer): Integer; override; Public function RecvBuffer(Buffer: TMemory; Len: Integer): Integer; override; var Tx_buffer : array[0..n] of byte; SentN := SendBuffer(@Tx_Buffer,NumBytes); -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to implement a circular buffer object in pascal?
>Bo, > >Most of the users on this forum have never interfaced with hardware , as you >can see from the responses. Those who have interfaced with hardware have >developed circular buffers which they know work , and they reuse them again >and again. I did this about 10 years ago when working on a PIC project with serial data coming in from sensors and such, using Ansi-C. And the buffer was just an array of char (byte in pascal) and there was a read and a write index. The read index was only ever changed by the consumer and the write index by the interrupt routine when adding data. The data reception was done in the interrupt and the code stuffed the data into the array using ++ syntax for the index, with a check for overflowing the array and then setting the index back to zero. There was probably also an overrun detection and action if the consumer is not fast enough, but I do not remember now... > >The following assumes you are receiving data from a sender , and in this >case the sender and receiver are connected via 1Gbps Ethernet using Synapse >(works really well). > > >A thread receives data into an array of byte. RxBuffer : Array[0..1500] of >byte ... and copies the number of bytes received into a circular buffer , >which is an array of RxBuffer. This is where I lose you, are you saying the circular buffer is not individual bytes but something larger? What is the size of RxBuffer? Looks like it is an array of byte, can you then make an array of such arrays? ... The CicBuffer is an array of N RxBuffer , which is an array of byte. The main loop extracts the byte array and either decodes them or type casts them into a record structure if it is compatible with the contents of the byte array, Type RxBufferType = array[0..1500] of byte; Var CirBuffer : array[0..N] of RxBufferType; > >In pseudo code it looks like this ... >CircularBuffer : Array[0..N] of RxBuffer >There is a ReadIndex and a WriteIndex , both longword or longint. > >The thread moves the data into the circular buffer continuously increase >the WriteIndex each write of RxBuffer data. If the WriteIndex > N then >WriteIndex := 0 , otherwise it is increased by 1. > >The main loop (below) moves the byte data using MOVE from CircBuffer to >whatever structure it represents , increase the ReadIndex by one and decodes >the data as needed. Looks like an array of some bigger datatype then. But if so then one needs to be able to detect in the receiver that enough data has arrived to make one such object to put onto the next buffer... ... you appear to be thinking of a asynchronous serial (RS-232 / 422) with no delimiters to indicate when a complete message is received. ... think of the byte array as an Ethernet packet of any length data of which the data structure is known. This is received using Synapse (UDP in this case) and copied into RxBuffer byte array by a thread which is always running until the main program is shut down. Whenever the thread receives a "complete" packet from Synapse (it signals a complete packket) , the thread code then puts it into RxBuffer and then copies RxBuffer into CircBuffer[WriteIndex] and increments the WriteIndex. If the WriteIndex < N then WriteIndex := WriteIndex +1 else WriteIndex := 0 // wraps The ReadIndex is incremented similar to the WriteIndex, if ReadIndex < N then ReadIndex := ReadIndex +1 else ReadIndex := 0; The circular buffer can be made as large as you need to "absorb" incoming data while the main loop is busy doing something else. The "nice" aspect of a circular buffer is that if the main loop is very slow and the incoming data stream is very fast , the WriteIndex will eventually overrun the ReadIndex and data is lost but nothing chokes or crashes , and eventually the ReadIndex will catch up. BTW : There are enough things that can go wrong implementing a circular buffer , and while it should be possible (and very nice) to implement it as an object , it may not be worth the effort. At least get it working as non-object code , then decide. > > If ReadIndex <> WriteIndex then > .. do the work as described above and increment the ReadIndex > >I use the Free Pascal unit which allows suspending the thread while the >ReadIndex is being increased. In the old DOS/DPMI days we would disable >interrupts briefly. Do you use CriticalSection for this? No . .. I started to originally but found it wasn't necessary as it uses a semaphore to prevent a Write occurring when the ReadIndex is being incremented. The FPC unit syncobjs is used the create a semaphore which is RESET before incrementing the ReadIndex and SET immediately after. This prevents a potential race condition where data could be written to CircBuffer at the exact time the ReadIndex is being incremented. >If you are innterested I can send you code snippets showing exactly how to >implement the circular buffer. > BTW : The circular buffer approach can also be used when transmitting data. For example Synapse maintains its own transmit
Re: [fpc-pascal] How to implement a circular buffer object in pascal?
Bo, Most of the users on this forum have never interfaced with hardware , as you can see from the responses. Those who have interfaced with hardware have developed circular buffers which they know work , and they reuse them again and again. I will describe in general terms the structure a circular buffer implemented to receive data , as it is usually more difficult to received the data than to send it due to the asynchronism between the sender and receiver. It has been used for many years , starting in 16bit-DOS , the 32bit-DPMI using interrupt handlers , then Linux using threads. The concept is the same for versions. The following assumes you are receiving data from a sender , and in this case the sender and receiver are connected via 1Gbps Ethernet using Synapse (works really well). A thread receives data into an array of byte. RxBuffer : Array[0..1500] of byte ... and copies the number of bytes received into a circular buffer , which is an array of RxBuffer. In pseudo code it looks like this ... CircularBuffer : Array[0..N] of RxBuffer There is a ReadIndex and a WriteIndex , both longword or longint. The thread moves the data into the circular buffer continuously increase the WriteIndex each write of RxBuffer data. If the WriteIndex > N then WriteIndex := 0 , otherwise it is increased by 1. The main loop (below) moves the byte data using MOVE from CircBuffer to whatever structure it represents , increase the ReadIndex by one and decodes the data as needed. If ReadIndex <> WriteIndex then .. do the work as described above and increment the ReadIndex I use the Free Pascal unit which allows suspending the thread while the ReadIndex is being increased. In the old DOS/DPMI days we would disable interrupts briefly. If you are innterested I can send you code snippets showing exactly how to implement the circular buffer. Regards Brian -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Writing to a drive which may be spun down
On 11/21/19 2:38 PM, Winfried Bartnick wrote: <...> > > writeln (txt,'I''m so tired ...'); > closeFile(txt); > io := ioResult; Thanks Winni, that sounds the sort of idea I'm looking for... Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Writing to a drive which may be spun down
On 11/21/19 7:12 AM, wkitt...@windstream.net wrote: > On 11/21/19 1:16 AM, Brian wrote: >> My question: Is there a standard method for handling this situation, >> i.e. making sure that a drive has not spun down, or is it just a case >> of writing a wrapper round the write function and handling the 'No >> such file' error with a wait and a retry? > > > why not just turn off or adjust your power management so that drive > doesn't spin down when it is connected? i do similar here but for my > monitors which sometimes don't want to wake back up after being put to > sleep... > Because on the *overwhelming* majority of occasions, I'm happy for the drives to sleep if not being accessed. Most things that I do don't need the USB drives. Bo's idea of a program which kept the drives spun up had occurred to me if I couldn't find a setting somewhere, but I was hoping for a solution which didn't require me to either disable the drive's power management or do constant accesses. Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Writing to a drive which may be spun down
Hi all, Running Ubuntu 18 LTS, I have a console-mode number-cruncher which writes occasional output files. It works just fine if the output is directed to a drive which is permanently spun up, but can fail if the output is directed to a USB drive (by which I mean a USB-connected 8TB external drive, not one of the keydrives). I've followed things through with the debugger, and it seems that the problem occurs when the drive has powered itself down due to lack of accesses. The assign and rewrite work OK, but then the first attempt to write to the file fails with a 'No such file' error. Putting a large (30 second!) delay before the first write means everything works OK, presumably because the drive gets time to spin up again. My question: Is there a standard method for handling this situation, i.e. making sure that a drive has not spun down, or is it just a case of writing a wrapper round the write function and handling the 'No such file' error with a wait and a retry? Thanks, Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] USB Human Interface Devices
Yes , and it works well on Linux. I use it on a circular (ring) buffer where the main program reads data from the circular buffer and increments the read index while a totally random thread reads data from an incoming Ethernet UDP , serial port or a custom hardware port , writes to the circular buffer and increments the write index. The functions used are : procedure ResetEvent; procedure SetEvent; function WaitFor(); // one of the events in your program READ or WRITE must wait until the other event finishes. The condition for a read of the circular buffer is WriteIndex <> ReadIndex which is in the main loop (not a thread) which is continuously polled in the main loop. Hope this helps. I can send a code clip but not until next week (out of the office) , showing how it is configured. -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] USB Human Interface Devices
A bit of clarification .. Also rather than using critical sections , use syncobs to ensure that you are not trying to /SIMULTANEOUSLY/ read and write to the same USB address or your data memory. Try using an Ethernet UDP connection to simulate the USB connection as it may illuminate an issue in your program. The Synapse UDP function works well -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] USB Human Interface Devices
A few general thoughts. Having been in similar situations when dealing with hardware interfaces .. the hardware is what it is .. and annoying as it is you have to work around it , as the hardware isn't going to change. It seems you have two problems 1) the USB hardware and 2) your program , in which you are not certain if it is doing something wrong .. been there many times. Sometimes it helps to make a simulator program which simulates (how you think the hardware is supposed to work) , and use that to shake out the bugs in your software. It is a lot of extra work but sometime there is no alternative. For example use a 2nd PC and an Ethernet UDP connection to test your software concept. Also rather than using critical sections , use syncobs to ensure that you are not trying to read and write to the same USB address or your data memory. https://www.freepascal.org/docs-html/current/fcl/syncobjs/teventobject.html Most guys/gals when writing interrupt handlers tend to use as simple a mechanism as possible .. from previous bad experiences. Try testing on Linux as you can run your program in graphics mode ( if that is what it does) while viewing events by writing write() messages to a terminal. This occurs if you launch your program from a terminal , then all writeln() messages go to the text terminal. -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] USB Human Interface Devices
Try the libusb library Free Pascal interface .. but be aware of his license requirements. It works well. http://johann-glaser.blogspot.com/2012/07/libusb-for-pascal.html -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] USB Human Interface Devices
If you can find a controller with an Ethernet input then Synapse is simple and works well. I have used it for RS-232 and Ethernet , but it claims to work with USB http://www.ararat.cz/synapse/doku.php/start -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] USB Human Interface Devices
If you can find a controller with an Ethernet input , the Synapse is simple to use and works well. http://www.ararat.cz/synapse/doku.php/start It also works well for RS-232. It also claims to work with USB but I haven't tried it on USB. -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Realtime and freepascal???
The brief description of your project suggests that it may not need "hard real-time" , since you are planning to write to flash memory or send the data over an RF link. Hard real-time usually implies receiving input data and responding with an output control in a timely and predictable manner. Your application seems more like data logging where you don't want to lose any data , and in that case Linux will suffice if you use a 1Gbps Ethernet link which I have tested using Synapse and handles data at roughly 800Mbps using Free Pascal. If you have access to hardware such as FPGA , or some special hardware , then preconditioning the data using buffers removes the need for hard real-time and Free Pascal running under vanilla Linux will more than suffice. Brian -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Linux getifaddrs
Thanks for all the suggestions but , I found and example which I have modified for my needs. Currently using Synapse but it only returns the loopback IP address since in my case the ports eth0 and eth1 are both static IP's. https://www.mail-archive.com/synalist-public@lists.sourceforge.net/msg03470/getlocalips.lpr It is a bit odd that something like this isn't incorporated into Free Pascal sockets. Thanks Brian -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Linux getifaddrs
Do you know of any kernel functions that would return the current IP address ? Thanks Brian -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Linux getifaddrs
Has anyone translated* getifaddrs* function to Free Pascal ? http://man7.org/linux/man-pages/man3/getifaddrs.3.html Thanks Brian -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FORTRAN from FreePascal
On 11/13/2017 10:20 AM, Adriaan van Os wrote: > brian wrote: >> Anyone with any past experience here? It seems I have two choices, to >> try to call the FORTRAN subroutines from FreePascal or to port the >> FORTRAN code to Pascal, I'm looking for advice... > > It is no problem calling FORTRAN from either C or FreePascal (or at > least not on UNIX-like platforms like Mac OS X, havn't tried for > Windows). The LAPACK package <http://www.netlib.org/lapack/> for > example (also installed in the Mac system software) is written in > Fortran. Some key points: > > 1. Lapack Fortran arrays are column-major (where column elements are > contiguous in memory) > 2. Lapack Fortran arrays are 1-base indexed > 3. Lapack Fortran parameters are always passed by reference, even if > they are value parameters > > So, for example, DGETRF > > = > SUBROUTINE DGETRF( M, N, A, LDA, IPIV, INFO ) > * > * -- LAPACK computational routine (version 3.X) -- > * -- LAPACK is a software package provided by Univ. of Tennessee, -- > * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG > Ltd..-- > * November 2011 > * > * .. Scalar Arguments .. > INTEGER INFO, LDA, M, N > * .. > * .. Array Arguments .. > INTEGER IPIV( * ) > DOUBLE PRECISION A( LDA, * ) > * .. > > > function dgetrf_ > ( constref theNumRows : LapackInt; > constref theNumColumns : LapackInt; > theMatrixPtr : LapackArrayOfDoublePtr; > constref theLeadingDimension : LapackInt; > thePivotIndicesPtr : LapackArrayOfIntPtr; > var theInfo : LapackInt): LapackResult; > cdecl; external; > > where (it's just an example) > > LapackInt = Int32; > LapackLongBool = Int32; > LapackResult = Int32; > LapackDouble = double; > LapackArrayOfIntPtr = ^Int32; > LapackArrayOfLongBoolPtr = ^Int32; > LapackArrayOfDoublePtr = ^double; > > The "constref" for value parameters makes sure they are passed by > reference, which is what Fortram requires. > Thanks, Adriaan, that's exactly what I needed. :) I'm going to be writing for a Debian platform (I should have mentioned that, the original code is from a Unix minicomputer) so there hopefully shouldn't be a problem. If I can just chunk up some of the FORTRAN code and re-use the calculation routines (which I don't understand anyway, the statistics are at a level that's over my head) then it will make life a lot easier. Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] FORTRAN from FreePascal
I need to try to put a user-friendly GUI and some graphical output onto an old command-line FORTRAN number cruncher, and have been provided with around 130 KB of FORTRAN source code. A quick scan of documentation seems to suggest that this is possible using gfortran and the C calling conventions (if someone knows differently, please say so right now!) :) My knowledge of FORTRAN-77 is sound, if rather rusty, but I know almost nothing about C programming, having been brought up as a chemist before I was dragged across to programming (I learned to program on Algol-60, BASIC and FORTRAN-IV, yes, that long ago ): ). Anyone with any past experience here? It seems I have two choices, to try to call the FORTRAN subroutines from FreePascal or to port the FORTRAN code to Pascal, I'm looking for advice... Thanks, Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] BlockWrite() version 2.6.4
Ok. Many thanks guys. Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/BlockWrite-version-2-6-4-tp5729418p5729456.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] BlockWrite() version 2.6.4
Thanks Charlie. I notice the Do_Write() uses repeat .. until where fpWrite() does a direct call. What was the reasoning for the repeat..until in Do_Write() ? Thanks Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/BlockWrite-version-2-6-4-tp5729418p5729451.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] BlockWrite() version 2.6.4
Can anyone familiar with FPC 2.6.4 comment on the specifics of how BlockWrite() functions under Linux. Specifically does BlockWrite() call the Linux kernel or call fWrite()? Does BlockWrite() call fFlush or does it rely on the kernel when to flush and actually write to the disk? In which file can the source code specific to BlockWrite() version 2.6.4 be found ? Thanks Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/BlockWrite-version-2-6-4-tp5729418.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Syncobjs Event and BlockWrite() question
When using WaitFor() , ResetEvent and SetEvent as a semaphore , if a thread is using BlockWrite() and the execution of BlockWrite() is conditional on WaitFor() , will BlockWrite() continue to function after it is called once MySemaphore.ResetEvent is called ? A pseudo code example below -main loop-- MySemaphore.ResetEvent; doing something MySemaphore.SetEvent - Thread MySemaphore.WaitFor(10); BlockWrite() - Thanks Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Syncobjs-Event-and-BlockWrite-question-tp5729411.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FPC for AVR
mikroPascal (not free) supports AVR and many other chips. https://shop.mikroe.com/compilers/mikropascal/avr-electronic-license Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/FPC-for-AVR-tp5729005p5729056.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FPC Graphics options?
Ryan Joseph wrote >> On May 18, 2017, at 9:19 PM, Reimar Grabowski > reimgrab@ > wrote: >> >> By getting the source of Graemes test, using a profiler on it and having >> a look at the results? > > I tried (had to change the code to support SDL 2 even) but gave up after > it crashed on one line. Graeme suggested a staggering difference in > performance and I was extremely curious to see if those calls to Floor() > were causing it. Hopefully this was a red herring and FPC isn’t as bad as > the test suggests. > > Regards, > Ryan Joseph > > ___ > fpc-pascal maillist - > fpc-pascal@.freepascal > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal You must treat SDL2.0 as a single threaded library. You can open a window in any thread , but whichever thread in which you create the window , all subsequent function calls to SDL2.0 must be made from within that thread , including events otherwise strange behavior or crashes will ensue. Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/FPC-Graphics-options-tp5728513p5728697.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FPC Graphics options?
Forgot to mention. SDL2.0 is multi platform and uses accelerated graphics. https://www.libsdl.org/ The best speed is achieved with NVidia graphics cards and proprietary NVidia drivers rather than the default Linux X.org drivers. http://www.freepascal-meets-sdl.net/chapter-1-introduction/ Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/FPC-Graphics-options-tp5728513p5728519.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FPC Graphics options?
I have an older project (Virtual Pascal) using DPMI32 and writing to the graphics card , and had the same issue as you when deciding which graphics library to use for Linux. In my case , part of the application is GUI and part is very fast 2D pixel graphics (points lines , polygons etc.) The first approach in porting to Linux was to write directly to the Linux graphics frame buffer and bypassing X11 entirely. This is very fast but that leaves you without many of the benefits of Linux. The second approach was to write directly to X11 , but writing a lot of pixel data to the X11 server will cause the X11 server to bog down and even crash. X11 is a server so that approach was ruled out. The chosen approach is to use SDL2.0+. If you are coming from pixel based BGI graphics where everything is pixel based , SDL takes a bit of getting used to , as everything (SDL 2.0) is based on textures. You write to a texture and render it to the graphics card as and when or periodically. In your case if you have a lot of pixel writing , SDL 2.0 has a very clever mechanism where you can render to a software (CPU memory) frame buffer at whatever rate you want and render (copy) that frame buffer to the graphics card at say 60Hz frame rate which make things appear faster than the eye can perceive. Here is basically how to do it. http://gigi.nullneuron.net/gigilabs/sdl2-pixel-drawing/ There is a nice Image and TTF library with SDL 2.0 Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/FPC-Graphics-options-tp5728513p5728518.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Threading vs Parallelism ?
I should have said "streaming" rather than "serial". True Parallelism is a long way off in the future , but a form of parallelism can be had using multiple CPU cores and hard affinity as described in the excellent article. http://www.ibm.com/developerworks/linux/library/l-affinity/index.html#download Consider the case of a special purpose custom design PCIe card and Linux. The classical way to interface with the card is to write an interrupt handler and accept the fact that doing so opens all your proprietary code due to the GPL. It also must wrestle with the black magic mess of BIOS PCI IRQ assignment and conflicts with other hardware. Another approach is to memory map the PCIe card in user space, use hard affinity and dedicate one CPU core to poll the card memory in user space. In this case the GPL does not apply and the issue of IRQ assignment is not an issue. Another approach is to abandon the add-in (PCIe) card approach and use gigabit Ethernet with a dedicated CPU core as the I/O. This what was done on the current project. Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Threading-vs-Parallelism-tp5728018p5728501.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Threading vs Parallelism ?
The information about using affinity with Linux was only posted so anyone who was interested could use it , and was not intended as an addition to Free Pascal. Regrading the previous comment about the hardware buffering the data , one still must do something with the data in user space. The choice there is to let the OS / CPU decide which core to use or dedicate a CPU core to the thread. Your choice. Here is the code and the Linux library you must link to in order to use the functions. {$LINKLIB libc.so} ... function sched_getaffinity(pid : Ptruint; cpusetsize : longint; cpuset : pointer) : longint; cdecl; external; function sched_setaffinity(pid : Ptruint; cpusetsize : longint; cpuset : pointer) : longint; cdecl; external; function pthread_setaffinity_np(pid : Ptruint; cpusetsize : longint; cpuset : pointer) : longint; cdecl; external; function pthread_getaffinity_np(pid : Ptruint; cpusetsize : longint; cpuset : pointer) : longint; cdecl; external; Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Threading-vs-Parallelism-tp5728018p5728443.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Threading vs Parallelism ?
Affinity If a thread is dedicated to say , polling a serial or Ethernet port which has a high input data rate , then dedicating one CPU to that task/thread is useful. (Hard Affinity) with multi-core CPU's is to dedicate a specific core to a task (thread) and just poll the input memory mapped source. This works very well. http://www.ibm.com/developerworks/linux/library/l-affinity/index.html#download These Linux API functions set the affinity for processes : sched_set_affinity() (for altering the bitmask) sched_get_affinity() (for viewing the current bitmask) These functions set the affinity for threads : pthread_setaffinity_np (pthread_t thread, size_t cpusetsize, const cpu_set_t *cpuset); pthread_getaffinity_np (pthread_t thread, size_t cpusetsize, cpu_set_t *cpuset); They are very simple to translate into Free Pascal Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Threading-vs-Parallelism-tp5728018p5728437.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Warning for anybody else using Linux Mint Debian ('Betsy')
On 03/07/2017 07:10 PM, Mattias Gaertner wrote: > >> brian <br...@meadows.pair.com> hat am 8. März 2017 um 00:16 geschrieben: >> [...] >>> /usr/bin/ld: /usr/lib/fpc/3.0.2/units/x86_64-linux/rtl/cprt0.o: >>> unrecognized relocation (0x2a) in section `.text' >>> /usr/bin/ld: final link failed: Bad value >> [...] >> Trying to build a simple 'Hello, World' from the 3.0.2 FP IDE also >> failed with a linker error. >> >> There are reports of this error "unrecognized relocation (0x2a) in >> section `.text'" with the *testing* version of plain Debian, but Betsy >> is based on Jessie (stable), NOT testing, and the library versions on >> this system *are* the ones from stable, I checked the versions. >> >> Downgrading to FPC 3.0.0 and Lazarus 1.6.2-1 means that everything >> works again as expected. >> >> I don't pretend to understand what has happened to cause this error on >> a system based on stable rather than testing, but as far as users with >> my configuration are concerned, there appears to be a barrier to >> upgrading, at least at the moment. > > You are not alone: > http://bugs.freepascal.org/view.php?id=31490 > Thank you for the pointer to the confirmation. I'd not thought it necessary to check whether the FPC .debs which came with Lazarus 1.6.4 were official ones or not. From what is said in the comments to that bug, that was obviously my mistake. Lesson learned! Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Warning for anybody else using Linux Mint Debian ('Betsy')
Upgrading to Lazarus 1.6.4 and FPC 3.0.2 as obtained from SourceForge breaks things irretrievably on Linux Mint Debian 64-bit running on an AMD Phenom x2 system. I first noticed this when trying to rebuild the Lazarus IDE generated the following error > /usr/bin/ld: /usr/lib/fpc/3.0.2/units/x86_64-linux/rtl/cprt0.o: unrecognized > relocation (0x2a) in section `.text' > /usr/bin/ld: final link failed: Bad value > /usr/share/lazarus/1.6.4/ide/lazarus.pp(154,1) Error: (9013) Error while > linking > /usr/share/lazarus/1.6.4/ide/lazarus.pp(154,1) Fatal: (10026) There were 1 > errors compiling module, stopping > Fatal: (1018) Compilation aborted > make[2]: *** [lazarus] Error 1 > make[1]: *** [idepkg] Error 2 > make: *** [idepkg] Error 2 Trying to build a simple 'Hello, World' from the 3.0.2 FP IDE also failed with a linker error. There are reports of this error "unrecognized relocation (0x2a) in section `.text'" with the *testing* version of plain Debian, but Betsy is based on Jessie (stable), NOT testing, and the library versions on this system *are* the ones from stable, I checked the versions. Downgrading to FPC 3.0.0 and Lazarus 1.6.2-1 means that everything works again as expected. I don't pretend to understand what has happened to cause this error on a system based on stable rather than testing, but as far as users with my configuration are concerned, there appears to be a barrier to upgrading, at least at the moment. Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] changes to include file do not trigger recompilation of unit
Yes. Version 2.6.4 which I have been using has this problem. Two work arounds : 1) Attempt to compile the include file which will fail , but the compiler appears to then recognize the file has changed when the main program / unit is later compiled. 2) save the file after the change , the recompile whatever you are working on. Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/changes-to-include-file-do-not-trigger-recompilation-of-unit-tp5726310p5726323.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Free Delphi 10.1 Berlin Starter Edition
On Wed, 24 Aug 2016 05:12:54 -0700, you wrote: >On 8/24/2016 1:04 AM, brian wrote: >> On Tue, 23 Aug 2016 23:40:06 +0800, you wrote: >> >> It should maybe be noted that this download apparently requires that >> you have Windows 10? >Negative. I downloaded and installed it just fine on Windows 8.1/64... > Interesting. When you enter your details and get the download link, it very clearly says that it needs the .NET from Windows 10 to run. You downloaded and installed it, have you actually done anything with it? Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Free Delphi 10.1 Berlin Starter Edition
On Tue, 23 Aug 2016 23:40:06 +0800, you wrote: It should maybe be noted that this download apparently requires that you have Windows 10? Brian. > > >Maciej Izak wrote: >> Hi, >> >> finally we have simple way to test new syntax to improve FPC quality / >> $MODE DELPHI without spending $ on Delphi :) >> >> Probably limited time offer: >> >> https://www.embarcadero.com/products/delphi/starter/promotional-download >> >> -- >> Best regards, >> Maciej Izak >> >Thanks a lot. >I wonder if there is any catch. >Anyway, I gave up Delphi after Delphi 5 and stick to FPC since then. >However, from time to time, I miss its lightning fast compiler and good >debugger. > >Dennis >___ >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] Ararat Synapse UDP Rx Speed (Mbps)
A test with two Linux (Ubuntu 14.04) PC's each with a 1Gbps NIC , with one PC sending 300byte packets directly to the other PC (no switch involved) . Each PC had a simple test program using Synapse : one PC sends UDP packets , the other PC receives UDP packets . The throughput rate was 880Mbps with no errors or lost data. Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Ararat-Synapse-UDP-Rx-Speed-Mbps-tp5723972p5723992.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Ararat Synapse UDP Rx Speed (Mbps)
Forgot to mention : Running on Linux / Ubuntu -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Ararat-Synapse-UDP-Rx-Speed-Mbps-tp5723972p5723973.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Ararat Synapse UDP Rx Speed (Mbps)
Does anyone have any benchmark speed tests using Synapse to receive UDP data ? (ie Mbps transfer). Thanks -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Ararat-Synapse-UDP-Rx-Speed-Mbps-tp5723972.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Question C to Pascal translation ....Re: Wraper for libpciaccess ?
Ref libpciaccess.h Any suggestions on the conversions below ? Thanks in advance. Brian C Union --- 00043 struct pci_device_iterator { unsigned next_index; enum { match_any, match_slot, match_id } mode; union { struct pci_slot_match slot; struct pci_id_match id; } match; }; ... is this conversion correct ? pci_device_iterator = packed record next_index : longword; // ??? Mode : (match_any, match_slot, match_id); match : packed record case integer of // union 0 : ( slot: pci_slot_match; ); 1 : ( id : pci_id_match; ); end; end; -- H2PAS converts this to ... 00245 struct pci_mem_region { /** * When the region is mapped, this is the pointer to the memory. * * This field is \b only set when the deprecated \c pci_device_map_region * interface is used. Use \c pci_device_map_range instead. * * \deprecated */ 00254 void *memory; /** * Base physical address of the region within its bus / domain. * * \warning * This address is really only useful to other devices in the same * domain. It's probably \b not the address applications will ever * use. * * \warning * Most (all?) platform back-ends leave this field unset. */ 00268 pciaddr_t bus_addr; /** * Base physical address of the region from the CPU's point of view. * * This address is typically passed to \c pci_device_map_range to create * a mapping of the region to the CPU's virtual address space. */ 00277 pciaddr_t base_addr; /** * Size, in bytes, of the region. */ 00283 pciaddr_t size; /** * Is the region I/O ports or memory? */ 00289 unsigned is_IO:1; /** * Is the memory region prefetchable? * * \note * This can only be set if \c is_IO is not set. */ 00297 unsigned is_prefetchable:1; /** * Is the memory at a 64-bit address? * * \note * This can only be set if \c is_IO is not set. */ 00306 unsigned is_64:1; }; Not certain if I believe this . pci_mem_region = record memory : pointer; bus_addr : pciaddr_t; base_addr : pciaddr_t; size : pciaddr_t; flag0 : word; end; const bm_pci_mem_region_is_IO = $1; bp_pci_mem_region_is_IO = 0; bm_pci_mem_region_is_prefetchable = $2; bp_pci_mem_region_is_prefetchable = 1; bm_pci_mem_region_is_64 = $4; bp_pci_mem_region_is_64 = 2; function is_IO(var a : pci_mem_region) : dword; procedure set_is_IO(var a : pci_mem_region; __is_IO : dword); function is_prefetchable(var a : pci_mem_region) : dword; procedure set_is_prefetchable(var a : pci_mem_region; __is_prefetchable : dword); function is_64(var a : pci_mem_region) : dword; procedure set_is_64(var a : pci_mem_region; __is_64 : dword); -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Wraper-for-libpciaccess-tp5720127p5720944.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] SDL 2.xx
Threading SDL 2.03 is not particularly difficult if you observe the rules that a texture/renderer must reside in the same thread that created the window and (it appears) there is only one event (which as you mentioned makes sense) , and in my case the event handler is in a thread. SDL 2.03 has some very nice features which were not available in SDL 1.xx such as TEXTURE. I noticed quite a few posts on different forums asking how to do animation , and several posts mentioned that an early version of Doom had used SDL 1.xx to blit multiple surfaces to create the animation effects. One method of extremely fast animation is to use the example here as the basis. Although the example is not animation the underlying use of CPU memory and textures is 100% applicable to animation. http://www.programmersranch.com/2014/02/sdl2-pixel-drawing.html -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/SDL-2-xx-tp5720887p5720920.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] SDL 2.xx
It appears (though I can't find any documentation / forums that actually states this) that SDL 2.03 only allows one event handler. When the event handler (only one handler) is put in a thread , the event can be detected from different windows , those created in the thread and those created in the main thread (program) , by using SDL_GetWindowID() to get the identify of a window (WindowID) and later use it to recognize which window generated the event. Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/SDL-2-xx-tp5720887p5720900.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] SDL 2.xx
I currently have an application running under Ubuntu 14.04 using SDL 2.03 and have a few questions . Currently the window / rendering / event handler are running in a thread , not the main program. This works fine as long as the window is initiated (created) in the thread , and the rendering / event handling is also done in the thread , which is what the SDL documentation also states. My question is if there is one window / rendering / event handler in a thread , and another window / renderer / event handler is created in the main program can two event handlers function properly. I can easily create another window / renderer / handler in the main program for the new window , but the question is can there be two event handlers in SDL 2.xx ? Thanks in advance Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/SDL-2-xx-tp5720887.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Cross-compile vs native
A question to those who must maintain a Linux version and a Windows versions application. Do you tend to cross-compile from Linux or do you compile native (with separate projects) on each OS (Linux and Windows)? Thanks Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Cross-compile-vs-native-tp5720834.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] SDL_Net vs Synapse
SDL2 Headers also available here ... http://sourceforge.net/projects/sdl2fpc/ -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/SDL-Net-vs-Synapse-tp5720715p5720720.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] SDL_Net vs Synapse
Any opinions/experience pro/con using SDL2 (SDL_Net) vs Synapse (http://synapse.ararat.cz/doku.php) ? Thanks Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/SDL-Net-vs-Synapse-tp5720715.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] FPC Heap Management : sub-allocation ?
Does FPC implement sub-allocation , in which the user program allocates a block of memory from the heap , and only plays in that sub-allocated block , such that if the user program has a serious memory leak , the user program may crash but it cannot exhaust the OS memory and cause the OS to crash? ... sorry for the long winded sentence. Thanks in advance Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/FPC-Heap-Management-sub-allocation-tp5720419.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FPC Heap Management : sub-allocation ?
Thanks Sven. Do you know how it behaves when running under Linux? -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/FPC-Heap-Management-sub-allocation-tp5720419p5720423.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FPC Heap Management : sub-allocation ?
Frederic Da Vitoria wrote I think that Brian is asking if a memory leak could eat the system's memory irreversibly. IIUC in Windows, when the program is stopped, all it's memory is freed, even if the program leaked memory. I don't know about Linux, but I'd be surprised if it weren't the same. -- Frederic Da Vitoria (davitof) Membre de l'April - « promouvoir et défendre le logiciel libre » - http://www.april.org ___ fpc-pascal maillist - fpc-pascal@.freepascal http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal Yes that is exactly what I was asking. For a high reliable system running 24/7 my fear using Object Oriented code vs procedural code is exactly what you mentioned . If there is a serious leak , or even a small one for an extended period of time , it can take down the OS. I have seen this happen with Sun OS and a 3rd party driver that leaked and caused the OS to crash after an extended period of time. -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/FPC-Heap-Management-sub-allocation-tp5720419p5720428.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] fpGUI Thread-safe
Is fpGUI running under X11 thread-safe? Thanks Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/fpGUI-Thread-safe-tp5720361.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpGUI Thread-safe
Sorry , I meant fpGUI created applications , not the toolkit. Thanks Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/fpGUI-Thread-safe-tp5720361p5720365.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Free Pascal Directories
Thanks for all the commandline suggestions , but my question is about using Geany as the IDE , not running the compiler from the commandline. BTW : I only use fpGUI as an example to illustrate the issue. Using Geany as the IDE : The FPC documentation is not correct : 1.3.38 $UNITPATH : Specify unit path. http://www.freepascal.org/docs-html/prog/progsu121.html#x129-131.3.38 If the directive is added (below) to the main program FPC will fail to find the unit directory i386-linux. {$UNITPATH .../fpgui/fpgui-1.2/src/units/i386-linux} To make it work you must include the absolute directory path such as : {$UNITPATH /home/mydir/fpgui/fpgui-1.2/src/units/i386-linux} and then it only finds the first unit in the uses list and cannot find the rest of the units in i386-linux. Why doesn't FPC continue to look for units in the directory specified by $UNITPATH ? Regards Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Free-Pascal-Directories-tp5720212p5720248.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Free Pascal Directories
Thanks Michael. Jonas tip allows me to see what is happening when using Geany. In the case of fpGUI , the fpmake creates all the .ppu and .o files and places them in directory ../i386-linux. Using either the wildcard * or absolute name of the directory is ok . The compiler finds (in this example) fpg_base but then wants to get the next unit (fpg_impl) called in fpg_base , but seems to expect the .pas file rather than just using the .ppu and .o files that have already been compiled. It is as if the compiler is trying to build rather than just linking the existing compiled .ppu and .o files. Searching file /usr/lib/fpc/2.6.4/fpg_impl.pas... not found Fatal: Can't find unit fpg_impl used by fpg_base Is there any way to tell the compiler to just link existing .ppu and .o files ? Thanks Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Free-Pascal-Directories-tp5720212p5720258.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Free Pascal Directories
Marco , The fpGUI units were recompiled with directive -Ur When the helloworld.pas file is compiled using Geany (with -Ur and -Va) for some reason FPC can't find the unit (fpg_impl.ppu) called by fp_base , even though it is present in the folder with fpb_base. [0.058] Load from FPG_BASE (interface) unit FPG_IMPL [0.058] Loading unit FPG_IMPL [0.058] Unitsearch: fpg_impl.ppu [0.058] Searching file fpg_impl.ppu... not found ... FPC then begins searching for the source file fpg_impl.pas which is not in the directory and eventually fails. Any suggestions ? Thanks Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Free-Pascal-Directories-tp5720212p5720260.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Free Pascal Directories
The compiler accepts the directory and loads the first unit fpg_base , but then fails to load the next unit that is called by fpg_base which is fpg_impl . Then it fails. Regards Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Free-Pascal-Directories-tp5720212p5720264.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Free Pascal Directories
My mistake ... Using directive -Va I can see that PFC cannot find fpg_base also. Question : Does the directive $UNITPATH acvtually work ? Regards Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Free-Pascal-Directories-tp5720212p5720266.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Free Pascal Directories
Conclusion : Using {$UNITPATH /home/some/*} in the main program DOES NOT WORK ! When using Geany if the directive is added in Set Build Command , COMPILE line as -Fu/home/some/* it works properly. Much better than dumping everything into one pot. Regards Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Free-Pascal-Directories-tp5720212p5720268.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Free Pascal Directories
Sorry , I wasn't specific about my problem. Using the example in the fpGUI distribution (but the following comments are not specific to fpGUI). I want to use Geany as the IDE without using .CFG files and compiling from the commandline. If UNITPATH is set in the main program (the fpGUI is a good example) , it will fail to find fpg_base helloworld.pas(27,3) Fatal: Can't find unit fpg_base used by HelloWorld program HelloWorld; {$mode objfpc}{$H+} {$UNITPATH .../fpgui/fpgui-1.2/src/units/i386-linux} if the absolute directory location is specified in the UNITPATH directive , the complier will find fpg_base but then fail to find the next unit called by fpg_base ... Fatal: Can't find unit fpg_impl used by fpg_base What am I missing? Thanks in Advance Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Free-Pascal-Directories-tp5720212p5720236.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Free Pascal Directories
Mattias Gaertner wrote On Wed, 1 Oct 2014 13:39:39 -0700 (PDT) Brian lt; vmst@ gt; wrote: Sorry , I wasn't specific about my problem. Using the example in the fpGUI distribution (but the following comments are not specific to fpGUI). I want to use Geany as the IDE without using .CFG files and compiling from the commandline. If UNITPATH is set in the main program (the fpGUI is a good example) , it will fail to find fpg_base helloworld.pas(27,3) Fatal: Can't find unit fpg_base used by HelloWorld program HelloWorld; {$mode objfpc}{$H+} {$UNITPATH .../fpgui/fpgui-1.2/src/units/i386-linux} You can give this directive multiple times to add all needed paths. Or you can pass the unit paths via -Fu in Geany. Mattias Thanks Mattias , I understand how to add the directive multiple times . Do you have an example of how you can pass the unit paths via -Fu in Geany ? Thanks in advance Brian ___ fpc-pascal maillist - fpc-pascal@.freepascal http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Free-Pascal-Directories-tp5720212p5720238.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Free Pascal Directories
Having ported a large real-time graphical application from Virtual Pascal (DPMI) to Free Pascal Linux , there is one aspect I haven't managed to overcome. For a number of reasons Lazarus was not used , and Geany is used as the IDE , which works well. Unlike Virtual Pascal which allowed me to put different code in separate directories , Free Pascal seems to want ALL unit files in one huge directory which makes it difficult to keep proper revision control. For example if I decide to use fpGUI , I would like to put all the fpGUI source code into one directory and the actual application (my code) in a separate directory. Any suggestions ? Thanks in advance Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Free-Pascal-Directories-tp5720212.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Wraper for libpciaccess ?
Does anyone know of an FPC wrapper for the library libpciaccess ? Thanks in advance Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Wraper-for-libpciaccess-tp5720127.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Xlib Threads
Yes , Xlib has many impressive features , but it is lacking in a simple (and fast) way to independently write to specific bit planes without altering the other bit planes for 2D animation. OpenGL can be used (I think) for 2D automation using the z-buffer , but it really is and end around to a deficiency in Xlib. -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Xlib-Threads-tp5719066p5719073.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Xlib Threads
An interesting discussion at this link on the subject. http://networkedblogs.com/axUUw *Effectively, the beginning of the main() function is the only really safe place to call XInitThreads(). * -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Xlib-Threads-tp5719066p5719079.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Xlib Threads
All the Xlib documentation seems to imply that threads can be used , however if I attempt to put XNextEvent() or XPending() in a thread , the rsult is a GP fault . The error message suggests using XInitThreads() but it still generates a GP fault. Tried using XlockDisplay() and XUnlockDisplay() in the thread but still get a GP fault. X Error of failed request: BadLength (poly request too large or internal Xlib length error) Major opcode of failed request: 100 (X_ChangeKeyboardMapping) Serial number of failed request: 20 Current serial number in output stream: 35 X11 code which causes the problem in the thread : NewEvent := Xpending(TheDisplay) 0 ; if NewEvent then begin XNextEvent(TheDisplay, @myevent); KeypressedX := myevent._type = keypress ; end; Any suggestions are welcomed. Thanks in advance. -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Xlib-Threads-tp5719066.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] SOLVED : Re: GetAffinity\SetAffinity
Problem solved ... ironically the solution was from a Windows guy. Faulty Code Core2Thread_ID := BeginThread(@Core2_Thread_Test); InitCriticalSection(CriticalSection_Core2); Set_Thread_CPU_Core(Core2Thread_ID,$01); writeln('Core2 ok'); Core22Thread_ID := BeginThread(@Core22_Thread_Test); InitCriticalSection(CriticalSection_Core22); Set_Thread_CPU_Core(Core22Thread_ID,$02); = Corrected Code : InitCriticalSection() BEFORE BeginThread() InitCriticalSection(CriticalSection_Core2); Core2Thread_ID := BeginThread(@Core2_Thread_Test); Set_Thread_CPU_Core(Core2Thread_ID,$01); writeln('Core2 ok'); InitCriticalSection(CriticalSection_Core22); Core22Thread_ID := BeginThread(@Core22_Thread_Test); Set_Thread_CPU_Core(Core22Thread_ID,$02); -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/GetAffinity-SetAffinity-tp3351231p5717575.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: GetAffinity\SetAffinity
Mark ... sorry for the mixup. The program and unit should now be stand alone. The unit links libc (rev6). Regards Brian coret.pas http://free-pascal-general.1045716.n5.nabble.com/file/n5717549/coret.pas test_threads.pas http://free-pascal-general.1045716.n5.nabble.com/file/n5717549/test_threads.pas -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/GetAffinity-SetAffinity-tp3351231p5717549.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: GetAffinity\SetAffinity
Attached binary executables which run on Ubuntu 12.04lts , but should be portable. coret_ok sets the process and two threads to core1 coret_fail sets to process to cores1 and 2 , one thread to core 1 and one thread to core 2. It soemtimes runs ok , but usually fails with a GP fault. coret_ok http://free-pascal-general.1045716.n5.nabble.com/file/n5717550/coret_ok coret_fail http://free-pascal-general.1045716.n5.nabble.com/file/n5717550/coret_fail -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/GetAffinity-SetAffinity-tp3351231p5717550.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: GetAffinity\SetAffinity
... The critical sections you are using only protect each thread against itself, meaning they basically do nothing. Being inside a critical section is not a guarantee that you won't get preempted, but just that no other threads can enter the same section. ... The two threads do not share and variables and do not interact with one another. The question is ... as Mark has previously pointed out ... does Linux x86 allow setting hard affinity with threads where the program (process) runs on one CPU core and one or more threads run on another core? It looks like all the threads must run on the same core as the block diagram at this link seems to imply. https://computing.llnl.gov/linux/slurm/mc_support.html Mark : I found that sometimes coret_fail would run several times correctly , and then when launched on launch N+1 would fail. It may just be luck of the draw that everything was running on one core when it ran correctly. -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/GetAffinity-SetAffinity-tp3351231p5717555.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: GetAffinity\SetAffinity
Mark ... many thanks. Your last comment prompted me to avoid using Write/Writeln to monitor what was happening. By removing Write/Writeln from the threads , ... everything works correctly with two threads , one running on core1 and the other thread running on core2. I think this boils down to the original issue that I found writing directly to the graphics card frame buffer , which is the same as Write/Writeln , in that there is only one physical display device which is not easily shared. Regards Vern -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/GetAffinity-SetAffinity-tp3351231p5717557.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: GetAffinity\SetAffinity
Mark , Thanks for the tips and info. There are two reasons for running threads on specific cores : 1) The possible need for a tight loop for receiving serial data. 2) The program is serial in nature receiving data, does not use X11 , controls the mouse and keyboard using libusb , and writes directly to the graphics card frame buffer (very fast). I have found that when multicore is enabled in the BIOS , or if I set the process to use more than one core with sched_setaffinit() , it appears the Linux scheduler is causing a problem and somehow mucks up some of the graphics when the data load increases , as the scheduler then starts to try and spread the load between the two cores. If only one core is used everything works fine. Regards Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/GetAffinity-SetAffinity-tp3351231p5717543.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: GetAffinity\SetAffinity
Attached is a simple test program with two threads. When the threads run , one displays '+' and the other displays '2'. If both threads run on the same core , the threads work , but if the threads are set to different cores , it generates a GP fault. If anyone is interested , download the code . It was tested on Ubuntu 12.04lts , but should be portable . Would be interested hear any results to confirm it is not a hardware issue on this PC. coret.pas http://free-pascal-general.1045716.n5.nabble.com/file/n5717544/coret.pas test_threads.pas http://free-pascal-general.1045716.n5.nabble.com/file/n5717544/test_threads.pas Regards Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/GetAffinity-SetAffinity-tp3351231p5717544.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: GetAffinity\SetAffinity
Mark, All the documentation seems to indicate that processes and threads are treated alike in Linux , however , even having established that I can apparently select a core to run a thread , I haven't yet been able to make it work. I explain the findings from a dual core Intel CPU. Using the sched_setaffinity() I can run a program on either core1 or core2 as long as all threads are set to the same core. If the main process (program) is set to core2 and all the threads are set to core2 everything is fine and dandy. However if the main process (program) is set to Core1 and any thread is set to Core2 using pthread_setaffinity_np() , when the Core2 thread starts to run it generates an immediate GP fault. The intent is to be able to run a thread which polls a serial or Ethernet port , rather like one would do with an ISR , but using a separate core for the task , while the main program runs on a different core. At this point I am not certain if there is something I am missing. -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/GetAffinity-SetAffinity-tp3351231p5717541.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: GetAffinity\SetAffinity
After a bit of research , the issue of setting the cpu affinity has been solved , which may be of use to other folks. A bit of info here concerning the data type cpu_set_t , which as far as I can determine (no help from the mess that is the c library source) is essentially an array of DWORD. For my purposes running on an x86 CPU , allowance for 32 cores is sufficient , using cpu_set_1 as one unsigned long word. http://www.cyberciti.biz/tips/setting-processor-affinity-certain-task-or-process.html Here are some code fragments which may be of help. The function do_SysCall(0) basically doesn't work for setting the CPU core. Although the Linux documentation claims sched_setaffinity() amd sched_getaffinity() work for threads , it only works for processes. pthread_getaffinity_np() and pthread_setaffinity_np() work properly for threads. FPC has some sloppy code as there is a note not to use PtrInt , instead use Ptruint , but the function BeginThread() returns PtrInt , but as long as you are not aritmetically manipulating the pointer it works ok. With a dual core Intel CPU with all cores enabled in the BIOS , sched_getaffinity() returns $03 (0011) and if you set process 0 to use only 1 core , sched_getaffinity returns $01 correctly. Same for thread_getaffinity_np() and pthread_setaffinity_np() , although if you set the CPU process 0 (current process) to one core , all the threads run on that core. // --- external functions from c-library libc (not the UNIT libc ! ) function sched_getaffinity(pid : Ptruint; cpusetsize : longint; cpuset : pointer) : longint; cdecl; external; function sched_setaffinity(pid : Ptruint; cpusetsize : longint; cpuset : pointer) : longint; cdecl; external; function pthread_setaffinity_np(pid : Ptruint; cpusetsize : longint; cpuset : pointer) : longint; cdecl; external; function pthread_getaffinity_np(pid : Ptruint; cpusetsize : longint; cpuset : pointer) : longint; cdecl; external; //--- procedure Set_Thread_CPU_Core(ThreadID : PtrInt; CPU_Core : longword); const cpu_SetSize = 4; // 32 cores max var cpu_Mask : longword; cpu_set : longword; //cpu_set_type sufficient for 32 core CPU ResultX : longint; begin ResultX := pthread_getaffinity_np(ThreadID,cpu_SetSize,@cpu_set); writeln('Result ',ResultX,' '); writeln('Mask ',Hexl(cpu_set)); cpu_set := $01; // CPU 0 ResultX := pthread_setaffinity_np(ThreadID,cpu_SetSize,@cpu_set) ; cpu_set := 0; // clear it in case pthread_setAffiniti_np() above = -1 (fail) ResultX := pthread_getaffinity_np(ThreadID,cpu_SetSize,@cpu_set) ; writeln('Result ',ResultX,' '); writeln('Mask ',Hexl(cpu_set)); end; procedure Set_Process_CPU_Core(ProcessID : PtrInt; CPU_Core : longword); const cpu_SetSize = 4; // 32 cores max var cpu_Mask : longword; cpu_set : longword; //cpu_set_type sufficient for 32 core CPU ResultX : longint; begin writeln('-- Process ---'); ResultX := sched_getaffinity(ProcessID,cpu_SetSize,@cpu_set); writeln('Result ',ResultX,' '); writeln('Mask ',Hexl(cpu_set)); cpu_set := CPU_Core; ResultX := sched_setaffinity(ProcessID,cpu_SetSize,@cpu_set) ; cpu_set := 0; // clear it in case sched_setAffinity() above = -1 (fail) ResultX := sched_getaffinity(ProcessID,cpu_SetSize,@cpu_set) ; writeln('Result ',ResultX,' '); writeln('Mask ',Hexl(cpu_set)); writeln('-'); end; -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/GetAffinity-SetAffinity-tp3351231p5717539.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: GetAffinity\SetAffinity
Alexey Voytsehovich wrote Just a huge thank you:) 2011/1/21 lt; michael.vancanneyt@ gt;: See man sched_setaffinity for the call to do this. Free Pascal does not have this call predefined, but you can make this call. Using the do_syscall you should be able to set up the call to the kernel. Something like: do_Syscall(syscall_nr_sched_setaffinity,fpgetpid,setsize,@cpu_set); Michael. On Fri, 21 Jan 2011, Alexey Voychehovich wrote: Good day. There is a need to establish some process affinity using free pascal and ubuntu. Do not tell that on this occasion you can read? Thanks in advance ___ fpc-pascal maillist - fpc-pascal@.freepascal http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@.freepascal http://lists.freepascal.org/mailman/listinfo/fpc-pascal -- Don`t drink and drive, smoke and fly! ___ fpc-pascal maillist - fpc-pascal@.freepascal http://lists.freepascal.org/mailman/listinfo/fpc-pascal Request for additional info : do_Syscall(syscall_nr_sched_setaffinity,fpgetpid,setsize,@cpu_set); The above generalized suggestion is very helpful , but can someone provide or point me to a link which describes the type cpu_set_t which @cpu_set points to. sched.h doesn't really explain the type definition or how to use it. Many thanks in advance. Brian -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/GetAffinity-SetAffinity-tp3351231p5717501.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Linux - ExecuteProcess versus fpSystem
On 09/09/2011 04:02 AM, Felipe Monteiro de Carvalho wrote: The quotes are bash commands, they are not part of command line. I wrote on this topic not long ago, but for TProcess: http://wiki.lazarus.freepascal.org/Executing_External_Programs#Parameters_which_contain_spaces_.28Replacing_Shell_Quotes.29 OK, I've read your notes for TProcess, I'll give that a try. Thanks. I have to say that when you have two overloaded declarations for ExecuteProcess, one with an array of parameters and one with a single parameter string, it's not clear to me why you then break the single string into individual parameters, but I'm sure there's some good reason for it. Maybe that single parameter string form of the command should be deprecated. I certainly think that the documentation is directly misleading :- paste In case ComLine is a single string, it will be split out in an array of strings, taking into account common whitespace and quote rules. /paste At least IMHO, having to quote the entire parameter string, not just the value, is anything but common whitespace and quote rules. However, thanks again for the assistance, folks. You can be sure this one has been carefully noted - the idea of needing to wrap parameter AND value in quotes wouldn't have occurred to me in a month of Sundays. Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Linux - ExecuteProcess versus fpSystem
On 09/08/2011 02:20 AM, Graeme Geldenhuys wrote: I can't really answer you regarding why ExecuteProcess doesn't work. But just wanted to ask: Have you thought of trying TProcess instead? I normally execute any external programs via TProcess with good results - no matter the platform. Nope. I'll give TProcess a whirl. Thanks for the suggestion. Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Linux - ExecuteProcess versus fpSystem
On 09/08/2011 01:07 PM, Marco van de Voort wrote: In our previous episode, Anton Shepelev said: In the case of ExecuteProcess() parameter separation takes place on FPC side, while with fpSystem() the shell is responsible for it. Executeprocess has two forms. One does parameter separation, and one not, and directly passes the separated parameters to fpexec. This was actually the reason for executeprocess. Could a problem with FPC's parameter separation algorithm be causing this? Maybe, but only when you use the wrong variant. Can you post both the commands you are executing? Yes, that would be the best. When I was learing processes, I wrote a unit to exe- cute a command using fpExecv -- just as ExecuteProcess() does. I'll dig it out and we'll see how (and whether) it works with your examples. There should be no need for that. OK, sorry for the delay in catching up with all the responses. I'll roll everything into one message. Why am I using a subprocess rather than writing a batch file? There's a bunch of other processing going on, but none of it involves manipulating the files other than a possible rename. It's selection of which files to convert according to various criteria, elimination of some duplicates, that sort of thing. It just seemed tidier to me to do the whole lot in the program rather than doing most of the work then write a batch file for the actual conversions. What are the commands? mpg321 -q -w tempfile.wav inputfile.mp3 oggenc -Q --output=outputfile.ogg tempfile.wav It makes no difference whether or not I use a full pathname for mpg321 and oggenc, and all the other files are in the current working directory. Yes, there really are quotes round the filenames, the vast majority of the real names have embedded spaces. As regards oggenc being faulty and not working unless called from the shell, no, that one hadn't occurred to me, not sure how to test it. Running with strace. Eek! 6.5 MB of trace output. :) I think it's found the problem, though. I get a bunch of ERROR: Multiple files specified when using stdin messages. It's difficult to see why this should be the case. I have the program name and the parameters set up as strings within my program. To switch between the ExecuteProcess and fpSystem calls, I just commented out the one I wasn't trying. The two lines of code are Status := ExecuteProcess(CommandString, ParamString); and Status := fpSystem(CommandString+' '+ParamString); CommandString just contains mog321 or oggenc (with or without the full path) and ParamString is the rest of the commands I gave above. Do I need to add a separator to the front of ParamString when using ExecuteProcess? It wouldn't seem sensible to require it, since there are the two parameters to ExecuteProcess versus the one for fpSystem, but maybe that's it. Thanks for the assistance so far, everyone. Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Linux - ExecuteProcess versus fpSystem
Reinforcing the subject, this is using Linux - to be specific, FPC 2.4.2-0 under 64 bit Mint 9. I'm trying to convert a large number of MP3 files to Ogg Vorbis. This is a two step process, first I run mpg321 to switch them to a .wav file, then oggenc to convert to a .ogg What's driving me crazy is that running the two commands via ExecuteProcess does the first step OK, but oggenc fails with an exit code of 1, operation not permitted. If I replace the ExecuteProcess with a call to fpSystem, concatenating the CommandString and ParamString with a space as separator and passing that as the command, both steps work just fine. I've tried putting a Delay(5000) between the two commands using ExecuteProcess, just in case there was some type of problem with data still being written from a cache. No difference whatever. This is reproducible on a whole batch of files, and yes, I've checked all the file permissions. It's got to be something obvious, or some quirk of Linux programming that I haven't met up with yet (I'm still a novice with FreePascal and Linux, though I've many years experience with Delphi and Windows). What am I missing? Thanks, Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Handling recursive symlinks in Linux
I'm trying to convert a Delphi console-mode program which needs to walk directory trees to FP **and Linux** - is there a standard way to detect and handle recursive symlinks, if the user has been daft enough to create them? Thanks, Brian. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Javascript in Desktop Applications
On Mon, Feb 7, 2011 at 6:27 AM, michael.vancann...@wisa.be wrote: On Mon, 7 Feb 2011, Andrew Brunner wrote: On Mon, Feb 7, 2011 at 7:35 AM, michael.vancann...@wisa.be wrote: A cross-platform solution is to use one of libsee or BESEN. The latter is implemented in 100% native Object Pascal. Michael. BESEN is very, very, very well written but I can't seem to get any indication how to use it in my project. I would love FPC to include a JIT system for JS or Pascal. IMO, FPC absolutely needs a scripting FCL going forward. BESEN seems like the right guy for the job, but I suspect he's burned out :-( I think he had memory concerns too. Does anyone have any BESEN examples that integrated actual FPC units? It seems like all the samle js units are self contained with no interface to system or GUI units. Including JS support on my project would enable people to leverage exiting proven technologies which would make for easier/allowable for adoption in working groups / houses where selection of language is restricted to language of the day :-) Taking this statment and applying this across the board, it would be an easier sell for adoption of FPC/Lazarus with JIT support. Personally, I'm thinking along the lines of Web RAD down the road... Well, if you can't get BESEN to work, libsee definitely does. I even have an article on how to do it. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal I have some interest in exploring javascript implementations for fpc. http://code.google.com/p/fpcjs/ -- Is this comparable to what you have noted? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Win32 Application Query.
On Sun, Jan 23, 2011 at 2:25 AM, Justin Smyth delph...@smythconsulting.net wrote: Hi guys I've been working on a application to application communications protocol via named pipes. the basic idea would be for Application A to change a Component Property on Applications B ( ie the visible property) or a text or caption or width / height of a component. ( and also for Application to cause and event to fire on application b only , ie a screen refresh or data change event ie reset a label to its primary state ) I'm also going to allow application A to change Applications B event handlers ie onClick onEnter OnKeyPress etc so that Application A can redirect an event handler so that when an event is triggered on Application B My Question is does any components out there like fpGUI do this ? once i am done and its working i'd be happy to share the code , at present i can change component values and read them from the remote end. Kind Regards Justin Smyth ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal I think you may find what you're looking for in MSE project's IFI? components. Google MSEGUI to find it. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] JSON - RTTI streaming.
On Wed, Jan 5, 2011 at 3:12 PM, Michael Van Canneyt mich...@freepascal.org wrote: Hello, For those of you that need JSON support: I have committed support for streaming published properties (properties for which RTTI is generated) from objects to JSON and vice versa, in a unit fpjsonrtti. Not the full streaming as implemented in the classes system is supported: - No DefineProperties. - No methods. Although it should not be difficult to add support for this. In contrast, it can stream simple collections and stringlists (with ojects attached) in various ways. There are various events to influence the streaming process. This should be more than enough to stream objects to and from a web-browser. I have committed an example and a testsuite. All this is in packages/fcl-json. Despite the fact that the testsuite runs OK , I'd like to ask those for whom it might be useful to test the code and report any errors you find to me. Suggestions for improvements are also welcome. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal Nice, this was on my to do list. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Cannot get TFPTimer to work
See .../fpcsrc/packages/fcl-base/examples/testtimer.pp for example usage. On Thu, Dec 2, 2010 at 10:39 AM, Darius Blaszyk dhkblas...@zeelandnet.nl wrote: Whatever I tried, I cannot get TFPTimer to work. Can someone help? For some reason the OnTimer even is never fired. Tried on Windows and Linux. Here's a snippet I used as test. Regards, Darius program fptimertest; {$mode objfpc}{$H+} uses {$IFDEF UNIX} cthreads, {$ENDIF} SysUtils, fpTimer; type { TBaseObj } TBaseObj = class(TObject) tmr: TFPTimer; public constructor Create; constructor Destroy; procedure OnTimerExec(Sender: TObject); end; { TBaseObj } constructor TBaseObj.Create; begin tmr := TFPTimer.Create(nil); tmr.Interval := 1; tmr.OnTimer:=...@ontimerexec; tmr.StartTimer; end; constructor TBaseObj.Destroy; begin tmr.StopTimer; tmr.Free; end; procedure TBaseObj.OnTimerExec(Sender: TObject); begin writeln('Timer executed'); end; var test: TBaseObj; i: integer; begin test := TBaseObj.Create; for i := 1 to 1000 do sleep(10); writeln('done'); readln; end. ___ fpc-pascal maillist - fpc-pas...@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] make fpc
On Mon, Nov 22, 2010 at 1:48 AM, Jonas Maebe jonas.ma...@elis.ugent.be wrote: On 21 Nov 2010, at 19:03, Brian Winfrey wrote: What version should fpc display (Revision: 16393). When I get latest and make /usr/bin/fpc is at version 2.4.2. fpc -vut dummy.pas ... Compiler: /usr/lib/fpc/2.4.2/ppc386 Using executable path: /usr/lib/fpc/2.4.2/ Using unit path: /usr/lib/fpc/2.4.2/units/i386-linux/rtl/ ... The output indicates that 2.4.3 directories are created and 2.4.3 compiler is used. I run make clean build make install INSTALL_PREFIX=/usr There are two separate things: the installed FPC versions, and the default FPC version. The default FPC version is determined by the symbolic links /usr/bin/ppc386, /usr/bin/ppcx64 etc (or /usr/local/bin/ppc386 etc on non-Linux). A make install will add a new FPC version, but it does not make it the default. If you want to do that, change the symlinks to point to the new compiler version. The fpc utility is only a wrapper that calls through to ppc386/ppcx64/... and has no version itself. Jonas ___ fpc-pascal maillist - fpc-pas...@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal I thought there was a sym link involved, but I mis-remembered it being fpc. That clears it up thanks. Brian ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Re: make fpc
I also tried make cycle as outlined in programmers guide, but results are the same. On Sun, Nov 21, 2010 at 10:03 AM, Brian Winfrey bwcod...@gmail.com wrote: What version should fpc display (Revision: 16393). When I get latest and make /usr/bin/fpc is at version 2.4.2. fpc -vut dummy.pas ... Compiler: /usr/lib/fpc/2.4.2/ppc386 Using executable path: /usr/lib/fpc/2.4.2/ Using unit path: /usr/lib/fpc/2.4.2/units/i386-linux/rtl/ ... The output indicates that 2.4.3 directories are created and 2.4.3 compiler is used. I run make clean build make install INSTALL_PREFIX=/usr I also tried make clean FPC=/usr/lib/fpc/2.4.3/ppc386 build. The output of make install is attached. Is this wrong? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TReader.ReadProperty
See post from about two weeks ago. Building FPC with debug information On Wed, Nov 3, 2010 at 3:39 AM, Roland Turčan - RoTurSoft i...@rotursoft.sk wrote: On Wed, Nov 3, 2010 at 9:17 AM, Michael Van Canneyt mich...@freepascal.org wrote: PS: How can I debug TReader class, because debuger steps over my calls from TReader. You must recompile the RTL with debug information, and then recompile your project. Thanks for answer, but please could you assist me how to build RTL with debug infos. Thanks. -- Best regards, TRoland http://www.rotursoft.sk ___ fpc-pascal maillist - fpc-pas...@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] MSEide+MSEgui rev.2.4
The fixes_2_4 is already at version 2.4.3 and contains everything from 2.4.2 and more... Thank you. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] MSEide+MSEgui rev.2.4
Which address should I be using? It looks like the UUID and revision are the same while Last changed revision and path are different. svn info http://svn.freepascal.org/svn/fpc/tags/release_2_4_2 Path: release_2_4_2 URL: http://svn.freepascal.org/svn/fpc/tags/release_2_4_2 Repository Root: http://svn.freepascal.org/svn/fpc Repository UUID: 3ad0048d-3df7-0310-abae-a5850022a9f2 Revision: 16285 Node Kind: directory Last Changed Author: marco Last Changed Rev: 16278 Last Changed Date: 2010-10-31 10:08:18 -0700 (Sun, 31 Oct 2010) svn info http://svn.freepascal.org/svn/fpc/branches/fixes_2_4 Path: fixes_2_4 URL: http://svn.freepascal.org/svn/fpc/branches/fixes_2_4 Repository Root: http://svn.freepascal.org/svn/fpc Repository UUID: 3ad0048d-3df7-0310-abae-a5850022a9f2 Revision: 16285 Node Kind: directory Last Changed Author: marco Last Changed Rev: 16277 Last Changed Date: 2010-10-31 10:01:50 -0700 (Sun, 31 Oct 2010) On Mon, Nov 1, 2010 at 7:14 AM, Graeme Geldenhuys graemeg.li...@gmail.com wrote: Op 2010-11-01 15:48, Marcos Douglas het geskryf: If you use the FPC from http://svn.freepascal.org/svn/fpc/branches/fixes_2_4 then the version is 2.4.3, right? Yes, and that works with MSEide too. Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net:8080/fpgui/ ___ fpc-pascal maillist - fpc-pas...@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] Re: Re: TPLY
Well, seems like you all have given some material to get me started. As nobody suggested sticking with TPLY or plex/bison I will back-burner that and proceed with crenshaw/oberon. Thanks to everyone. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TPLY
Thanks, I'll look into this as well. On Fri, Oct 29, 2010 at 2:19 AM, Thierry Coq t...@free.fr wrote: Brian, thanks for the diff, I'll take it into account and publish an update. On 28/10/2010 18:50, Brian Winfrey wrote: ... The changes I made in this diff were simply to get it to compile. Subsequently I renamed all files and folders to lowercase, converted spaces to underscores and added a prefix to eliminate duplicate file names where needed. ... Another approach would be to look at (and reverse engineer) the byte code. If it's not obfuscated, it might even be easier to parse and port than the native Java. How would you suggest I proceed in that. Using the class file format (for example here: http://en.wikipedia.org/wiki/Class_%28file_format%29), it would be easy to parse through the tables, identify the class name, its super class name, the interfaces it's implementing, and even the public and private methods. The java compiler has done all the work into translating the java code into nice tables. ;-) I remember I did the exercise once. I've destroyed the code, but I could do it again. I remember one of the more difficult parts was understanding how java coded strings ;-) This was before anonymous classes and methods, so this could be another difficulty. I don't know how these are converted to byte code. Once you have the structure, you can generate the pascal code. I would recommend against generating one class per unit as Java does: since pascal dependency rules are strict (no cycles), this would most certainly result in uncompilable code. What I do when I translate Java is to pre-declare all classes and interfaces at the top of the unit(s) and then generate the full class interface further down. Translating the statements inside the bytecode I haven't tried, since my efforts were mostly for analyzing java code and measuring it. I hope this helps, Thierry ___ fpc-pascal maillist - fpc-pas...@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] Re: TPLY
Thank you, What techiniques have you used in the past that you could share to get me started? On Wed, Oct 27, 2010 at 8:04 PM, leledumbo leledumbo_c...@yahoo.co.id wrote: Learn compilation technique, a recursive descent parser should be easy to understand and code instead of learning automatic lexer and parser generator. Plus, structurally, Java is a very simple language, so AST transformation should be easy. With FPC 2.5.1, almost all Java constructs can be directly translated to FPC dialect, minus anonymous inner class only AFAIK. -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/TPLY-tp3235828p3239905.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pas...@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] TPLY
I recently saw a semi working example of a Java to Delphi converter that was done with javacc. Unfortunately it would only convert simple java (v 1.4 maybe). Can anyone recommend a good place to start reading or offer any advise to accomplish this with TPLY. I am looking into porting some Java libraries to FPC 2.5.x, and am unfamiliar with the TPLY tools. Thanks, Brian ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Building FPC with debug information
make OPT=-O- DEBUG=1 all When I ran this I see that both -dDEBUG and -dRELEASE are passed on the fpc command line. Is that correct? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] IntList
Take a look at http://code.google.com/p/fprb/. I have just perused it, but it looks pretty good. Brian. Currently, the FPC team is looking at an implementation of Vlado Boza us...@ksp.sk for a standard template library for inclusion in FPC. The code is on http://code.google.com/p/stlpascal Please have a look and comment on it. I'm not a generics expert and am not in the position to judge whether this library is good or not. Michael. ___ fpc-pascal maillist - fpc-pas...@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] What are the issues involved in threads sharing variables?
Polling where the list size is highly dynamic you will need protect it. I think FPC has thread safe list objects too. Yes it does, Classes.TThreadList I think. I thought it was a conatiner for threads, but it is a safe list. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] lNet getting the local IP
I didn't try it, but I see that it tries to connect to google's dns serve= r, so it'd fail miserably if the computer has no internet access. Bye -- Luca I tested, without web access does not work. :o A hard coded address will of course fail if it cannot be reached. The code was an example, you should use it as such. I substituted my router's ip for google's and it works.;) Choose a different address that would not fail in a specific situation. As another example, one could read their /etc/resolve file to get the dns server that is assigned. Brian Winfrey ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] lNet getting the local IP
On 06/10/10 14:27, Felipe Monteiro de Carvalho wrote: Ok, thanks everyone, it seams that I managed to extract a function from Silvio's code which doesn't use Synapse. I only tested in Windows so far: unit chesstcputils; {$mode objfpc}{$H+} interface uses {$IFDEF MSWINDOWS} Winsock, {$ENDIF} Classes, SysUtils; function ChessGetLocalIP(): string; implementation const CFormatIPMask = '%d.%d.%d.%d'; function ChessGetLocalIP(): string; var I, VAttempt: Integer; VStrTemp, VSitesToTry: TStringList; {$IFDEF UNIX} VProcess: TProcess; {$ENDIF} {$IFDEF MSWINDOWS} var VWSAData: TWSAData; VHostEnt: PHostEnt; VName: string; {$ENDIF} begin Result := ''; {$IFDEF UNIX} VStrTemp := TStringList.Create; VProcess := TProcess.Create(nil); try VProcess.CommandLine := 'sh -c ifconfig eth0 | awk ''/inet end/ {print $3}'''; Yuck. This doesn't work on my system (debian). If you really want the least effort, you may have more luck with simply parsing `hostname -I` somehow. The right way to do this is with an ioctl, I believe (SIOCGIFCONF). Look here: http://www.kernel.org/doc/man-pages/online/pages/man7/netdevice.7.html I'm sure there's some code floating around, but it probably means that you have to translate some headers :(. Henry Re: [fpc-pascal] lNet getting the local IP I found an example for linux on stack overflow that was in c http://stackoverflow.com/questions/212528/linux-c-get-the-ip-address-of-local-computer - here is a rough translation: program GetPrimaryIpAddress; {$mode objfpc} uses baseunix, unixtype, sockets, SysUtils; procedure Get(var buf: array of char; const len: longint); const CN_GDNS_ADDR = '8.8.8.8'; CN_GDNS_PORT = 53; var s: string; sock: longint; err: longint; HostAddr: TSockAddr; l: Integer; UnixAddr: TInetSockAddr; begin err := 0; Assert(len = 16); sock := fpsocket(AF_INET, SOCK_DGRAM, 0); assert(sock -1); UnixAddr.family := AF_INET; UnixAddr.port := htons(CN_GDNS_PORT); UnixAddr.addr := StrToHostAddr(CN_GDNS_ADDR).s_addr; if (fpConnect(sock,@UnixAddr,SizeOf(UnixAddr)) = 0) then begin try l := SizeOf(HostAddr); if (fpgetsockname(sock, @HostAddr, @l) = 0) then begin s := NetAddrToStr(HostAddr.sin_addr); StrPCopy(PChar(Buf), s); end else begin err:=socketError; end; finally if (fpclose(sock) 0) then begin err := socketError; end; end; end else begin err:=socketError; end; if (err 0) then begin // report error end; end; var ipbuf: array[0..255] of char; begin system.FillChar(ipbuf, sizeOf(ipBuf), #0); Get(ipbuf, system.SizeOf(ipbuf)); WriteLn(StrPas(ipbuf)); end. BrianW I have tried this code with multiple scenarios. if interfaces are down, no ip address is returned. I would say that is expected as there is no network. ifconfig will return same. only lo has an address 127.0.0.1. Otherwise I get the primary ip address as long as routing is used. if connecting to 0.0.0.0, 127.0.0.1 is returned Use 127.0.0.1 and the primary is returned. Run some tests and let me know what you find. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] lNet getting the local IP
I think you want to use 127.0.0.1 to return the actual address. In my case I would const CN_GDNS_ADDR = '127.0.0.1'; run the progarm and the output would be 192.168.1.5 as long as there is an active interface. On Thu, Oct 7, 2010 at 3:34 PM, silvioprog silviop...@gmail.com wrote: Hi Brian, I tested again, and discovered that's not is necessary a connection to a web. I changed to 0.0.0.0 and returned 127.0.0.1, perfect! :) I will use this function. Thanks very much again. :) 2010/10/7 Brian Winfrey bwcod...@gmail.com On 06/10/10 14:27, Felipe Monteiro de Carvalho wrote: Ok, thanks everyone, it seams that I managed to extract a function from Silvio's code which doesn't use Synapse. I only tested in Windows so far: unit chesstcputils; {$mode objfpc}{$H+} interface uses {$IFDEF MSWINDOWS} Winsock, {$ENDIF} Classes, SysUtils; function ChessGetLocalIP(): string; implementation const CFormatIPMask = '%d.%d.%d.%d'; function ChessGetLocalIP(): string; var I, VAttempt: Integer; VStrTemp, VSitesToTry: TStringList; {$IFDEF UNIX} VProcess: TProcess; {$ENDIF} {$IFDEF MSWINDOWS} var VWSAData: TWSAData; VHostEnt: PHostEnt; VName: string; {$ENDIF} begin Result := ''; {$IFDEF UNIX} VStrTemp := TStringList.Create; VProcess := TProcess.Create(nil); try VProcess.CommandLine := 'sh -c ifconfig eth0 | awk ''/inet end/ {print $3}'''; Yuck. This doesn't work on my system (debian). If you really want the least effort, you may have more luck with simply parsing `hostname -I` somehow. The right way to do this is with an ioctl, I believe (SIOCGIFCONF). Look here: http://www.kernel.org/doc/man-pages/online/pages/man7/netdevice.7.html I'm sure there's some code floating around, but it probably means that you have to translate some headers :(. Henry Re: [fpc-pascal] lNet getting the local IP I found an example for linux on stack overflow that was in c http://stackoverflow.com/questions/212528/linux-c-get-the-ip-address-of-local-computer - here is a rough translation: program GetPrimaryIpAddress; {$mode objfpc} uses baseunix, unixtype, sockets, SysUtils; procedure Get(var buf: array of char; const len: longint); const CN_GDNS_ADDR = '8.8.8.8'; CN_GDNS_PORT = 53; var s: string; sock: longint; err: longint; HostAddr: TSockAddr; l: Integer; UnixAddr: TInetSockAddr; begin err := 0; Assert(len = 16); sock := fpsocket(AF_INET, SOCK_DGRAM, 0); assert(sock -1); UnixAddr.family := AF_INET; UnixAddr.port := htons(CN_GDNS_PORT); UnixAddr.addr := StrToHostAddr(CN_GDNS_ADDR).s_addr; if (fpConnect(sock,@UnixAddr,SizeOf(UnixAddr)) = 0) then begin try l := SizeOf(HostAddr); if (fpgetsockname(sock, @HostAddr, @l) = 0) then begin s := NetAddrToStr(HostAddr.sin_addr); StrPCopy(PChar(Buf), s); end else begin err:=socketError; end; finally if (fpclose(sock) 0) then begin err := socketError; end; end; end else begin err:=socketError; end; if (err 0) then begin // report error end; end; var ipbuf: array[0..255] of char; begin system.FillChar(ipbuf, sizeOf(ipBuf), #0); Get(ipbuf, system.SizeOf(ipbuf)); WriteLn(StrPas(ipbuf)); end. BrianW I have tried this code with multiple scenarios. if interfaces are down, no ip address is returned. I would say that is expected as there is no network. ifconfig will return same. only lo has an address 127.0.0.1. Otherwise I get the primary ip address as long as routing is used. if connecting to 0.0.0.0, 127.0.0.1 is returned Use 127.0.0.1 and the primary is returned. Run some tests and let me know what you find. -- Silvio Clécio, programmer ObjectPascal ___ fpc-pascal maillist - fpc-pas...@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] lNet getting the local IP
I don't know if you noticed, but it appears that code has some depracated properties that should be changed. Here are the modifications I made in exploring this issue: program GetPrimaryIpAddress; {$mode objfpc} uses baseunix, unixtype, sockets, SysUtils; procedure Get(out AddrOut: string); const CN_GDNS_ADDR = '127.0.0.1'; CN_GDNS_PORT = 53; var sock: longint; err: longint; UnixAddr: TInetSockAddr; HostAddr: TSockAddr; len: Integer; begin err := 0; sock := fpsocket(AF_INET, SOCK_DGRAM, 0); assert(sock -1); // changed because previous properties were deprecated UnixAddr.sin_family := AF_INET; UnixAddr.sin_port := htons(CN_GDNS_PORT); UnixAddr.sin_addr := StrToHostAddr(CN_GDNS_ADDR); if (fpConnect(sock, @UnixAddr, SizeOf(UnixAddr)) = 0) then begin try len := SizeOf(HostAddr); if (fpgetsockname(sock, @HostAddr, @len) = 0) then begin AddrOut := NetAddrToStr(HostAddr.sin_addr); end else begin err:=socketError; end; finally if (fpclose(sock) 0) then begin err := socketError; end; end; end else begin err:=socketError; end; if (err 0) then begin // report error end; end; var strAddr: string; begin Get(strAddr); WriteLn('ip : ',strAddr); end. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal