View Issue Details

IDProjectCategoryView StatusLast Update
0037551pas2jstranspilerpublic2020-08-12 22:31
Reporterhenrique Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformPas2JsOSWindows 
Fixed in Versiontrunk 
Summary0037551: Integration with dll
DescriptionAs the TUnitAliasCallBack callback is declared, you cannot modify the unit name to find the file correctly. With this adjustment, I can do that.
Steps To ReproduceYou have to use ps2jslib.dll to compile a project that you need to adjust the names of the units.
TagsNo tags attached.
Fixed in Revision46400
Attached Files

Activities

henrique

2020-08-11 22:24

reporter  

pas2jslibcompiler.patch (1,456 bytes)   
From 69eedb6da377902a103e6732fbcff518244b3b0d Mon Sep 17 00:00:00 2001
From: Henrique Gottardi Werlang <henriquewerlang@hotmail.com>
Date: Tue, 11 Aug 2020 17:20:59 -0300
Subject: [PATCH] =?UTF-8?q?Ajustado=20a=20declara=C3=A7=C3=A3o=20da=20DLL?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/pas2jslibcompiler.pp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/pas2jslibcompiler.pp b/src/pas2jslibcompiler.pp
index bc4f15c..51a10ca 100644
--- a/src/pas2jslibcompiler.pp
+++ b/src/pas2jslibcompiler.pp
@@ -48,7 +48,7 @@ Type
   TReadDirCallBack = Function (Data : Pointer;
     P : PDirectoryCache; ADirPath: PAnsiChar): boolean; {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
   TUnitAliasCallBack = Function (Data: Pointer;
-    AUnitName: PAnsiChar; AUnitNameMaxLen: Integer): boolean; {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
+    AUnitName: PAnsiChar; var AUnitNameMaxLen: Int32): boolean; {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 
   { TLibraryPas2JSCompiler }
 
@@ -212,8 +212,8 @@ begin
     UnitNameMaxLen:=Max(UnitNameLen,255);
     s:=UseUnitName;
     SetLength(s,UnitNameMaxLen);
-    if OnUnitAlias(OnUnitAliasData,Pointer(s),UnitNameMaxLen) then
-      UseUnitName:=LeftStr(s,UnitNameLen);
+    if OnUnitAlias(OnUnitAliasData, @(s[1]),UnitNameMaxLen) then
+      UseUnitName:=LeftStr(PChar(s),UnitNameLen);
     end;
 end;
 
-- 
2.28.0.windows.1

pas2jslibcompiler.patch (1,456 bytes)   

Michael Van Canneyt

2020-08-12 00:51

administrator   ~0124781

Your code is also wrong. It should be:

UseUnitName:=LeftStr(PChar(s),UnitNameMaxLen);

Because UnitNameMaxLen is what contains the new length.

But we cannot change the signature of this function just like that, this is a non-backwards compatible change.
The DLL is in use by TMS Software, the Alias function is there for them.
First I must inquire whether we can change the signature.

henrique

2020-08-12 13:26

reporter   ~0124792

Fixed the implementation.

From what I understand of the function is to check the name of the Unit, and if you need to change her name. Otherwise it's like this, how do they do it?
pas2jslibcompiler-2.patch (1,459 bytes)   
From 40954275628345a4ce59981ad82bde0d76124f15 Mon Sep 17 00:00:00 2001
From: Henrique Gottardi Werlang <henriquewerlang@hotmail.com>
Date: Wed, 12 Aug 2020 08:24:38 -0300
Subject: [PATCH] =?UTF-8?q?Ajustado=20a=20declara=C3=A7=C3=A3o=20da=20DLL?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/pas2jslibcompiler.pp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/pas2jslibcompiler.pp b/src/pas2jslibcompiler.pp
index bc4f15c..9b214bb 100644
--- a/src/pas2jslibcompiler.pp
+++ b/src/pas2jslibcompiler.pp
@@ -48,7 +48,7 @@ Type
   TReadDirCallBack = Function (Data : Pointer;
     P : PDirectoryCache; ADirPath: PAnsiChar): boolean; {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
   TUnitAliasCallBack = Function (Data: Pointer;
-    AUnitName: PAnsiChar; AUnitNameMaxLen: Integer): boolean; {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
+    AUnitName: PAnsiChar; var AUnitNameMaxLen: Int32): boolean; {$IFDEF UseCDecl}cdecl{$ELSE}stdcall{$ENDIF};
 
   { TLibraryPas2JSCompiler }
 
@@ -212,8 +212,8 @@ begin
     UnitNameMaxLen:=Max(UnitNameLen,255);
     s:=UseUnitName;
     SetLength(s,UnitNameMaxLen);
-    if OnUnitAlias(OnUnitAliasData,Pointer(s),UnitNameMaxLen) then
-      UseUnitName:=LeftStr(s,UnitNameLen);
+    if OnUnitAlias(OnUnitAliasData, @(s[1]),UnitNameMaxLen) then
+      UseUnitName:=LeftStr(PChar(s),UnitNameMaxLen);
     end;
 end;
 
-- 
2.28.0.windows.1

pas2jslibcompiler-2.patch (1,459 bytes)   

Michael Van Canneyt

2020-08-12 13:55

administrator   ~0124794

A good question, I asked myself the same question. I think it is a bug.

I asked, as soon as I know the answer I will apply the fix or report back...

Michael Van Canneyt

2020-08-12 22:31

administrator   ~0124811

Confirmed to be a bug. There was already a patch in a private repo. No need to change the signature.
Just make sure the returned name is zero-terminated.

Issue History

Date Modified Username Field Change
2020-08-11 22:24 henrique New Issue
2020-08-11 22:24 henrique File Added: pas2jslibcompiler.patch
2020-08-12 00:48 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-08-12 00:48 Michael Van Canneyt Status new => assigned
2020-08-12 00:51 Michael Van Canneyt Note Added: 0124781
2020-08-12 13:26 henrique Note Added: 0124792
2020-08-12 13:26 henrique File Added: pas2jslibcompiler-2.patch
2020-08-12 13:55 Michael Van Canneyt Note Added: 0124794
2020-08-12 22:31 Michael Van Canneyt Status assigned => resolved
2020-08-12 22:31 Michael Van Canneyt Resolution open => fixed
2020-08-12 22:31 Michael Van Canneyt Fixed in Version => trunk
2020-08-12 22:31 Michael Van Canneyt Fixed in Revision => 46400
2020-08-12 22:31 Michael Van Canneyt Note Added: 0124811