Re: [fpc-pascal] Debug information

2012-09-12 Thread Rainer Stratmann
Am Tuesday 11 September 2012 19:30:55 schrieb Mark Morgan Lloyd:
> Rainer Stratmann wrote:
> > Am Tuesday 11 September 2012 18:14:57 schrieb Mark Morgan Lloyd:
> >> Martin wrote:
> >>> On 11/09/2012 10:28, Rainer Stratmann wrote:
>  I found out that there is no line information shown (-gl) if an error
>  occurs
>  (more or less shortly) after the program loads a dynamic library.
> 
>  This same behaviour happens with fpc version 2.4.2-0 and 2.6.0.
> 
>  If no library is loaded line information is shown.
>  The error adresses are the same in both cases.
> >>
> >> How is the library being loaded: using FPC's dynlibs unit?
> >
> > Yes.
> >
> >> If using dynlibs, is the problem immediately after loading the library
> >> (.so) or is it on a call of an entry point in the library?
> >
> > Immediately after loading the library.
>
> In which case I presume that you could comment out the calls to the
> entry points in the library and duplicate the problem (have you tried
> this?). Does the recently-added GetLoadError() function tell you
> anything useful?

The error is produced immediately after loading (not executing) the library 
(writing to a random memory adress).

I did not find information of the GetLoadError() function.

> >> Is the DLL successfully called, does it exit predictably, and does the
> >> stack recover to the state it was on entry (i.e. without an extra or
> >> missing word)?
> >
> > The program restarts some times and there is no error.
>
> If it's specifically something that happens at load time then below
> probably isn't relevant.

> > Stack recovery I don't know. I think it will be ok. How can I see that?
>
> Inline assembler to dump esp and ebp.

?

> > I use loadlibrary and freelibrary.
> > There are only 3 functions/procedures calling from the program.
> > (init_proc, loop_proc, exit_proc).
> > The library calls back a procedure (add a key to a keybuffer) but in this
> > procedure there is no error.
> > I tried safeloadlibrary but the same thing.


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


[fpc-pascal] C Enum vs. Integer

2012-09-12 Thread Johann Glaser
Hi!

I'm working on a header translation for LibUSB and its fork libusbx.
They define several data types as C enums (for examples, see
http://libusbx.sourceforge.net/api-1.0/group__desc.html ).

They excessively use direct assignment of enum values, and even use one
value multiple times (e.g. LIBUSB_CLASS_PTP = 6, LIBUSB_CLASS_IMAGE =
6).

Can I translate this 1:1, i.e., define an Enum in Pascal and just ignore
the compiler warnings about reused values?

Or should I rather define all these types as Integer and define
constants for all values?

One more question: In some C structs and function parameters and return
values these enums are used too. How can I assure that the same memory
allocation is used?

Thanks
  Hansi


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


Re: [fpc-pascal] C Enum vs. Integer

2012-09-12 Thread Jonas Maebe

On 12 Sep 2012, at 19:11, Johann Glaser wrote:

> Can I translate this 1:1, i.e., define an Enum in Pascal and just ignore
> the compiler warnings about reused values?
> 
> Or should I rather define all these types as Integer and define
> constants for all values?

It depends on whether you need arithmetic or not. If you do, use integer 
constants, otherwise you can use an enum.

> One more question: In some C structs and function parameters and return
> values these enums are used too. How can I assure that the same memory
> allocation is used?

Include an appropriate {$packenum xxx} directive in your source code. There is 
no {$packenum c} (I'm not even sure whether the C standard says anything about 
the size of enums), so you'll have to check the size of those enumeration types 
in C yourself.


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


[fpc-pascal] Function for checking correct file name

2012-09-12 Thread Krzysztof
Hi,

Exists any multiplatform function which check if string contains not
allowed characters (like < > / \ on windows) for filename?

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


Re: [fpc-pascal] C Enum vs. Integer

2012-09-12 Thread Vinzent Höfler
On Wed, 12 Sep 2012 20:44:21 +0200, Jonas Maebe  
 wrote:


Include an appropriate {$packenum xxx} directive in your source code.  
There is no {$packenum c} (I'm not even sure whether the C standard says  
anything about the size of enums),


Yes, it does say something about it:

|Each enumerated type shall be compatible with char, a signed integer type,
|or an unsigned integer type. The choice of type is implementation-defined
|but shall be capable of representing the values of all the members of the
|enumeration.
  --  ISO/IEC 9899:1999, 6.7.2.2 (4)

It says it's implementation defined. :D


Vinzent.

--
The most likely way for the world to be destroyed, most experts agree,
is by accident. That's where we come in; we're computer professionals.
We cause accidents.
-- Nathaniel Borenstein
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] C Enum vs. Integer

2012-09-12 Thread patspiper

On 12/09/12 20:11, Johann Glaser wrote:

Hi!

I'm working on a header translation for LibUSB and its fork libusbx.
They define several data types as C enums (for examples, see
http://libusbx.sourceforge.net/api-1.0/group__desc.html ).

They excessively use direct assignment of enum values, and even use one
value multiple times (e.g. LIBUSB_CLASS_PTP = 6, LIBUSB_CLASS_IMAGE =
6).

Can I translate this 1:1, i.e., define an Enum in Pascal and just ignore
the compiler warnings about reused values?

Or should I rather define all these types as Integer and define
constants for all values?

One more question: In some C structs and function parameters and return
values these enums are used too. How can I assure that the same memory
allocation is used?
A translation of libusb 0.1.12 is available in the fpc contributed units 
(http://www.freepascal.org/contrib/contribs.html). Maybe you can use 
that as a reference.


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


[fpc-pascal] Incompleteness of current fix for #22860

2012-09-12 Thread JC Chu
Jonas,

Regarding bug #22860 on the inability to define enumeration members
using expressions containing previously defined members of the same
type, the current fix does not provide a complete solution.

The current fix won’t allow for valid declarations such as TYPE
TMyEnum = (meA, meB = 1 + meA) and TYPE TMyEnum = (meA, meB = meA xor
meA).

Forbidding all of those enumeration-related overloads, however, will
undo much of what the relaxation patch was intended for.

The compiler should expect an integer-typed constant expression after
‘=’, with a weakened type checking that takes as Ord(x) each
enumeration member x in the expression, where x must belong to the
enumeration type being declared, and must appear before the member
it’s used to define.

Since this weakening happens only within enumeration definitions, I
think it should be treated specifically.

-- 
Best regards,
JC Chu
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal