View Issue Details

IDProjectCategoryView StatusLast Update
0036927LazarusIDEpublic2020-06-11 11:39
ReporterDimitrios Chr. Ioannidis Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformIntel Core 2 DuoOSWindows 10 Pro 64-bit 
Product Version2.1 (SVN) 
Summary0036927: Codetools WINAPI modifier
DescriptionLazarus doesn't accept the macro WINAPI ( i.e. as used in fpc's libusb package ) ,

[code=pascal start=99]
{$macro on}

{$ifdef MSWINDOWS}
 
const libusb1='libusb-1.0.dll';
{$define LIBUSB_CALL := WINAPI }
{$else}
const libusb1='libusb-1.0.so';
{$define LIBUSB_CALL := cdecl }
{$endif}
[/code]

and also as calling convention modifier in procedural types ,

i.e.

[code start=1043]
    libusb_transfer_cb_fn = procedure (transfer:plibusb_transfer);LIBUSB_CALL;
[/code]
  
Steps To ReproduceCreate an empty project in Lazarus and add the libusb unit to the uses clause.

[code=pascal]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
  libusb;

type
  TForm1 = class(TForm)
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

end.
[/code]

Then go to a TForm keyword and press Alt-Up.

Lazarus will go to this libusb's line, instead of TForm's one :

[code start=1043]
    libusb_transfer_cb_fn = procedure (transfer:plibusb_transfer);LIBUSB_CALL;
[/code]

and reports this Codetools error message :

[code]
libusb.pp(1043,81) Error: expected =, but ; found
[/code]

Additional InformationPlz, see the discussion in https://forum.lazarus.freepascal.org/index.php/topic,49371.0.html.
TagsNo tags attached.
Fixed in Revision
LazTarget
WidgetsetWin32/Win64
Attached Files

Relationships

related to 0036924 closedMichael Van Canneyt FPC modifier winapi not documented 

Activities

Dimitrios Chr. Ioannidis

2020-04-17 18:36

reporter   ~0122205

Apologies for the [code][/code] tags .

I didn't know that mantisbt BBCodePlus plugin isn't installed / enabled here, so to any manager / administrator plz feel free to remove them .

Anton Kavalenka

2020-04-17 18:43

reporter   ~0122206

Last edited: 2020-04-17 18:46

View 2 revisions

Btw libusb package is compiled in
{$IFDEF FPC}
{$mode objfpc}
{$PACKRECORDS C}
{$ENDIF}
which implies {$MACRO on}
otherwise the LIBUSB_CALL:=WINAPI just will not be defined.
Imo, the WINAPI macro is not defined at all, but under win64 there is only one calling convention, so there would be no harm.

Anton Kavalenka

2020-04-17 18:52

reporter  

libusb.diff (6,564 bytes)   
--- /projects/dcommon/libusb1.pas	2016-12-24 15:04:53.000000000 +0300
+++ /projects/fpc/packages/libusb/src/libusb.pp	2017-03-16 09:50:12.000000000 +0300
@@ -1,18 +1,19 @@
+unit libusb;
+
+{$IFDEF FPC}
+{$mode objfpc}
+{$PACKRECORDS C}
+{$ENDIF}
 
-unit libusb1;
 interface
 {$ifdef MSWINDOWS}
-uses windows,winsock;
+uses windows;
 {$else}
 uses ctypes,sockets,unixtype;
 {$endif}
 
 
 
-{$IFDEF FPC}
-{$PACKRECORDS C}
-{$ENDIF}
-
 
   {
    * Public libusb header file
@@ -47,6 +48,7 @@
   type
     ssize_t = longint;
 {$endif  WIN64}
+    ptimeval = pointer;
 
 {$else}
   type
@@ -97,9 +99,9 @@
 {$macro on}
 
 {$ifdef MSWINDOWS}
-
+ 
 const libusb1='libusb-1.0.dll';
-{$define LIBUSB_CALL := stdcall }
+{$define LIBUSB_CALL := WINAPI }
 {$else}
 const libusb1='libusb-1.0.so';
 {$define LIBUSB_CALL := cdecl }
@@ -1898,13 +1900,13 @@
 function  libusb_control_transfer_get_data(
 	transfer:plibusb_transfer):puint8_t;inline;
 begin
-	result := pointer(transfer.buffer) + LIBUSB_CONTROL_SETUP_SIZE;
+	result := pointer(transfer^.buffer) + LIBUSB_CONTROL_SETUP_SIZE;
 end;
 
 function libusb_control_transfer_get_setup(
   transfer:plibusb_transfer):plibusb_control_setup;inline;
 begin
-  Result:= plibusb_control_setup(transfer.buffer);
+  Result:= plibusb_control_setup(transfer^.buffer);
 end;
 
 
@@ -1918,11 +1920,11 @@
 var setup:plibusb_control_setup;
 begin
   setup := plibusb_control_setup(buffer);
-  setup.bmRequestType := bmRequestType;
-  setup.bRequest := bRequest;
-  setup.wValue := libusb_cpu_to_le16(wValue);
-  setup.wIndex := libusb_cpu_to_le16(wIndex);
-  setup.wLength := libusb_cpu_to_le16(wLength);
+  setup^.bmRequestType := bmRequestType;
+  setup^.bRequest := bRequest;
+  setup^.wValue := libusb_cpu_to_le16(wValue);
+  setup^.wIndex := libusb_cpu_to_le16(wIndex);
+  setup^.wLength := libusb_cpu_to_le16(wLength);
 end;
 
 procedure libusb_fill_control_transfer(
@@ -1936,16 +1938,16 @@
   setup:plibusb_control_setup;
 begin
   setup := plibusb_control_setup(buffer);
-  transfer.dev_handle := dev_handle;
-  transfer.endpoint := 0;
-  transfer._type := byte(LIBUSB_TRANSFER_TYPE_CONTROL);
-  transfer.timeout := timeout;
-  transfer.buffer := buffer;
+  transfer^.dev_handle := dev_handle;
+  transfer^.endpoint := 0;
+  transfer^._type := byte(LIBUSB_TRANSFER_TYPE_CONTROL);
+  transfer^.timeout := timeout;
+  transfer^.buffer := buffer;
   if (setup<>nil) then
-  	transfer.length := (LIBUSB_CONTROL_SETUP_SIZE
-  		+ libusb_le16_to_cpu(setup.wLength));
-  transfer.user_data := user_data;
-  transfer.callback := callback;
+  	transfer^.length := (LIBUSB_CONTROL_SETUP_SIZE
+  		+ libusb_le16_to_cpu(setup^.wLength));
+  transfer^.user_data := user_data;
+  transfer^.callback := callback;
 end;
 
 procedure libusb_fill_bulk_transfer(
@@ -1958,14 +1960,14 @@
   user_data:pointer;
   timeout:cardinal);inline;
 begin
-  transfer.dev_handle := dev_handle;
-  transfer.endpoint := endpoint;
-  transfer._type := byte(LIBUSB_TRANSFER_TYPE_BULK);
-  transfer.timeout := timeout;
-  transfer.buffer := buffer;
-  transfer.length := length;
-  transfer.user_data := user_data;
-  transfer.callback := callback;
+  transfer^.dev_handle := dev_handle;
+  transfer^.endpoint := endpoint;
+  transfer^._type := byte(LIBUSB_TRANSFER_TYPE_BULK);
+  transfer^.timeout := timeout;
+  transfer^.buffer := buffer;
+  transfer^.length := length;
+  transfer^.user_data := user_data;
+  transfer^.callback := callback;
 end;
 
 procedure libusb_fill_bulk_stream_transfer(
@@ -1981,7 +1983,7 @@
 begin
   libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer,
   				length, callback, user_data, timeout);
-  transfer._type := byte(LIBUSB_TRANSFER_TYPE_BULK_STREAM);
+  transfer^._type := byte(LIBUSB_TRANSFER_TYPE_BULK_STREAM);
   libusb_transfer_set_stream_id(transfer, stream_id);
 end;
 
@@ -1995,14 +1997,14 @@
   user_data:pointer;
   timeout:cardinal);inline;
 begin
-  transfer.dev_handle := dev_handle;
-  transfer.endpoint := endpoint;
-  transfer._type := byte(LIBUSB_TRANSFER_TYPE_INTERRUPT);
-  transfer.timeout := timeout;
-  transfer.buffer := buffer;
-  transfer.length := length;
-  transfer.user_data := user_data;
-  transfer.callback := callback;
+  transfer^.dev_handle := dev_handle;
+  transfer^.endpoint := endpoint;
+  transfer^._type := byte(LIBUSB_TRANSFER_TYPE_INTERRUPT);
+  transfer^.timeout := timeout;
+  transfer^.buffer := buffer;
+  transfer^.length := length;
+  transfer^.user_data := user_data;
+  transfer^.callback := callback;
 end;
 
 procedure libusb_fill_iso_transfer(transfer:plibusb_transfer;
@@ -2015,15 +2017,15 @@
   user_data:pointer;
   timeout:cardinal);inline;
 begin
-  transfer.dev_handle := dev_handle;
-  transfer.endpoint := endpoint;
-  transfer._type := byte(LIBUSB_TRANSFER_TYPE_ISOCHRONOUS);
-  transfer.timeout := timeout;
-  transfer.buffer := buffer;
-  transfer.length := length;
-  transfer.num_iso_packets := num_iso_packets;
-  transfer.user_data := user_data;
-  transfer.callback := callback;
+  transfer^.dev_handle := dev_handle;
+  transfer^.endpoint := endpoint;
+  transfer^._type := byte(LIBUSB_TRANSFER_TYPE_ISOCHRONOUS);
+  transfer^.timeout := timeout;
+  transfer^.buffer := buffer;
+  transfer^.length := length;
+  transfer^.num_iso_packets := num_iso_packets;
+  transfer^.user_data := user_data;
+  transfer^.callback := callback;
 end;
 
 procedure libusb_set_iso_packet_lengths(
@@ -2032,8 +2034,8 @@
 var
   i:integer;
 begin
-  for i := 0 to transfer.num_iso_packets-1 do
-  	transfer.iso_packet_desc[i].length := length;
+  for i := 0 to transfer^.num_iso_packets-1 do
+  	transfer^.iso_packet_desc[i].length := length;
 end;
 
 function libusb_get_iso_packet_buffer(
@@ -2055,16 +2057,16 @@
 
   _packet := integer(packet);
 
-  if (_packet >= transfer.num_iso_packets) then
+  if (_packet >= transfer^.num_iso_packets) then
   begin
     Result:=nil;
   	exit;;
   end;
 
   for i := 0 to _packet-1 do
-  	offset := offset + transfer.iso_packet_desc[i].length;
+  	offset := offset + transfer^.iso_packet_desc[i].length;
 
-  Result := pointer(transfer.buffer) + offset;
+  Result := pointer(transfer^.buffer) + offset;
 end;
 
 
@@ -2085,13 +2087,13 @@
 
   _packet := integer(packet);
 
-  if (_packet >= transfer.num_iso_packets) then
+  if (_packet >= transfer^.num_iso_packets) then
   begin
     Result:=nil;
   	exit;;
   end;
 
-  Result := pointer(transfer.buffer) + integer(transfer.iso_packet_desc[0].length * _packet);
+  Result := pointer(transfer^.buffer) + integer(transfer^.iso_packet_desc[0].length * _packet);
 end;
 
 
libusb.diff (6,564 bytes)   

Anton Kavalenka

2020-04-17 18:58

reporter   ~0122208

Please disregard the diff, it is useless.

In FPC case the WINAPI macro probably wrong.

Marco van de Voort

2020-04-17 20:15

manager   ~0122211

FPC supports winapi, see related case. It was a surprise for me too.

Sven Barth

2020-04-18 11:55

manager   ~0122219

>Btw libusb package is compiled in
>{$IFDEF FPC}
>{$mode objfpc}
>{$PACKRECORDS C}
>{$ENDIF}
>which implies {$MACRO on}

No. No mode enables macros by default.

There is a {$macro on} a bit further down above the declaration of LIBUSB_CALL.

>FPC supports winapi, see related case. It was a surprise for me too.

For around five years already. Though it seems that Florian had forgotten to add it to New Features Trunk back then... Hopefully I'll remember to put it to New Features 3.2.0 then. :D

Dimitrios Chr. Ioannidis

2020-06-11 11:39

reporter   ~0123392

Any news regarding this ?

Issue History

Date Modified Username Field Change
2020-04-17 18:30 Dimitrios Chr. Ioannidis New Issue
2020-04-17 18:36 Dimitrios Chr. Ioannidis Note Added: 0122205
2020-04-17 18:43 Anton Kavalenka Note Added: 0122206
2020-04-17 18:46 Anton Kavalenka Note Edited: 0122206 View Revisions
2020-04-17 18:52 Anton Kavalenka File Added: libusb.diff
2020-04-17 18:58 Anton Kavalenka Note Added: 0122208
2020-04-17 20:14 Marco van de Voort Relationship added related to 0036924
2020-04-17 20:15 Marco van de Voort Note Added: 0122211
2020-04-18 11:55 Sven Barth Note Added: 0122219
2020-06-11 11:39 Dimitrios Chr. Ioannidis Note Added: 0123392