Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fix to eliminate iconv for android (and other unix-es)
#9
(02-01-2021, 07:50 AM)ZGabrovski@gmail.com Wrote:
Code:
function Iconvert(S: string; var Res: string; const FromEncoding, ToEncoding: string): cint;
from iconvenc unit on button click.

Note that the function is using String parameters, even for the output data. Are you compiling with {$ModeSwitch UnicodeStrings} or {$Mode DelphiUnicode} enabled to make String=UnicodeString? I ask because...

(02-01-2021, 07:50 AM)ZGabrovski@gmail.com Wrote:
Code:
uses iconvenc;
procedure testme;
var S : UnicodeString;
begin
Iconvert('dfsfsdf',S,'UTF8','UTF16')
end;

You are passing a UnicodeString variable to a var String parameter, which I would not expect to compile when String=AnsiString.

Yes, UnicodeString uses UTF-16, but I would have expected the 1st and 2nd parameters of Iconvert() to be untyped to allow different kinds of strings depending on the values of the FromEncoding and ToEncoding parameter.

But, in any case, Indy doesn't use Iconvert() at all, it uses iconv() directly. And appears to be using iconv() slightly differently than Iconvert() does (I think Indy's way is correct).

(02-01-2021, 07:50 AM)ZGabrovski@gmail.com Wrote: it is failed somewhere in        iconv(H, nil, nil, @Dst, @Outlen);

That looks like a perfectly valid call to iconv() to me, per the iconv documentation:

Quote:The main case is when inbuf is not NULL and *inbuf is not NULL... (doesn't apply here)

...

A different case is when inbuf is NULL or *inbuf is NULL, but outbuf is not NULL and *outbuf is not NULL. In this case, the iconv function attempts to set cd’s conversion state to the initial state and store a corresponding shift sequence at *outbuf. At most *outbytesleft bytes, starting at *outbuf, will be written. If the output buffer has no more room for this reset sequence, it sets errno to E2BIG and returns (size_t)(−1). Otherwise it increments *outbuf and decrements *outbytesleft by the number of bytes written.

A third case is when inbuf is NULL or *inbuf is NULL, and outbuf is NULL or *outbuf is NULL... (shouldn't apply here)

Though, that does beg the question, where is @Dst pointing to exactly, and is it valid? Looks like it is pointing at the internal character buffer of your output UnicodeString, but Iconvert() treats that parameter as a String and attempts to resize it before calling into iconv(). Maybe that is resulting in bad memory in your case?

I do question why Iconvert() is making that particular call to iconv(), since it is being used to reset iconv's conversation state AFTER a conversion has been performed, which seems wrong or at least redundant to me.

(02-01-2021, 07:50 AM)ZGabrovski@gmail.com Wrote: But how to debug inside iconv?

You don't think you need to debug inside of iconv() itself, you just need to debug the code that is calling iconv().

(02-01-2021, 07:50 AM)ZGabrovski@gmail.com Wrote: Believe me I spent a hours to build the library with the same ndk version that I am using for my project.
The result is the same and the same.

I think you are focusing on the wrong thing. You should not be focusing on iconv itself, but rather on how it is being used by FPC/Indy.

Reply


Messages In This Thread
RE: Fix to eliminate iconv for android (and other unix-es) - by rlebeau - 02-01-2021, 05:36 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)