Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fix to eliminate iconv for android (and other unix-es)
#1
I had a serious problem with iconv encoding library on Android 10 application developed with LAMW and Indy.
I received SIGEGV Exception with backtrace:

...
01-28 16:05:24.303  2648  2648 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
01-28 16:05:24.303  2648  2648 F DEBUG   : Cause: null pointer dereference
01-28 16:05:24.303  2648  2648 F DEBUG   :     r0  e9595fb4  r1  00000000  r2  00000000  r3  00000000
01-28 16:05:24.303  2648  2648 F DEBUG   :     r4  e9595f80  r5  ecc07048  r6  ed0fb200  r7  ed0fb200
01-28 16:05:24.303  2648  2648 F DEBUG   :     r8  c4e2efe8  r9  ed0f3160  r10 c4e093bc  r11 c38b871c
01-28 16:05:24.303  2648  2648 F DEBUG   :     ip  c38b86bc  sp  c38b8600  lr  c4d8b850  pc  efe3a950
01-28 16:05:24.309  2648  2648 F DEBUG   : 
01-28 16:05:24.309  2648  2648 F DEBUG   : backtrace:
01-28 16:05:24.309  2648  2648 F DEBUG   :       #00 pc 00066950  /apex/com.android.runtime/lib/bionic/libc.so (iconv+36) (BuildId: dcf0e174e93e33d22f35a631ba9c0de5)
01-28 16:05:24.309  2648  2648 F DEBUG   :       #01 pc 0010284c  /data/app/org.teamlooktools.teamlookmobile-s_uRfmpjft4VcskmjhvlvQ==/lib/arm/libcontrols.so (BuildId: d24f8df194618599d7a0a2d459ad6f929a806d9b)


I recompile the libiconv.so library, but the problem still exists.
On Android 8-9 everything is OK.
So, I took a decision to try to eliminate  libiconv dependancy form indy code.

Please, find attached here the changes 

In short: I made a change in Idcompilerdefines with which in case of compilation for android under FPC I define USE_LCONVENC . In Idglobals.pas instead of iconv I use unit lconvencoding.

in a method 

Code:
unction DoIconvBytesToChars(const ACharset: string; const ABytes: PByte; AByteCount: Integer;
  AChars: PWideChar; ACharCount: Integer; AMaxCharSize: Integer; ACharsIsTemp: Boolean): Integer;   
I do conversion in new way using lconvencoding:

Code:
{$IFDEF USE_LCONVENC}
  AData :=  StrPas( pChar( ABytes ));
  OutP := UTF8Decode( ConvertEncodingToUTF8( AData, ACharSet, Done ) );
  Result := 0;
  if not Done then
     OutP := AData;
  fStr := Copy(OutP,1, ACharCount);
  Len := length( fStr );
  Move(fStr[1], AChars^, Len*sizeof(WideChar));
  Result := Length( OutP );
  {$ENDIF}        

the similar in other method
Code:
function DoIconvCharsToBytes(const ACharset: string; AChars: PIdWideChar; ACharCount: Integer;
  ABytes: PByte; AByteCount: Integer; ABytesIsTemp: Boolean): Integer;  


I use:

Code:
  {$IFDEF USE_LCONVENC}
  AData :=  AChars;

  OutP := ConvertEncodingFromUTF8( AData, ACharSet, Done );
  Result := 0;

  if Done then begin
    Result := Length( OutP );
    Move( Outp[ 1 ], ABytes^, AByteCount );
    end
  else
    begin
    Result := Length( AData );
    Move( AData[ 1 ], ABytes^, AByteCount );
    end;

  {$ENDIF}  

instead of iconv.

PLease, may I kindly ask you who wants to test if everything is OK?

Edit: Now it works fine for my application. I update the files attached.
The problem under Android 10 disappear.


Attached Files
.zip   FixedUnits.zip (Size: 73.86 KB / Downloads: 4)
Reply


Messages In This Thread
Fix to eliminate iconv for android (and other unix-es) - by ZGabrovski@gmail.com - 01-29-2021, 09:07 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)