Hi,
I am reading carefully the e_capi.c code...
The piece of code Line 1119 is not clear :
len is a size in byte giving the size of the LP-T-STR name,
So, whatever is the sizeof(TCHAR), one is allowed to do : name = (TCHAR
*) malloc(len).
So it is not clear why one should use alloca when TCHAR is char, and
OPENSSL_malloc when TCHAR is wchar_t.
Because in wchar_t case you have to convert it to ASCII afterwards and
conversion takes a malloc-ation. alloca is about minimizing malloc-ations.
I suggest : no more if (sizeof(TCHAR) == sieof(char),
and then just : name = (TCHAR *) OPENSSL_malloc(len);
Then we'd have to free the wchar_t buffer. As mentioned we're returning
malloc-ated ANSI result.
Another question is : why using alloca for ANSI and OPENSSL_malloc when
both are taking size in bytes...
See above.
Note : len is ALWAYS a size in byte, not in "characters".
Right.
===
More generally I do NOT recommend using "sizeof(TCHAR)!=sizeof(char))"
where it is in fact expected to get a compilation directive such as
#ifdef UNICODE
It is not only confusing from an operational point of view, as if both
branches of the code could be used in the same run time session,
but also time consuming at run time...
The rationale behind using if(sizeof(TCHAR)!=sizeof(char)) in favor of
preprocessor directives is that compiler always parses both cases, so
that you don't have to explicitly test them separately. Yes, some
[otherwise redundant] casts sneak in, but the gain is that there is no
way to get one of code paths wrong. To demonstrate the point consider
one of your suggested modifications, to dso_win32.c. Is len=0 actually
proper solution? No, http://cvs.openssl.org/chngview?cn=23134 is. As for
branches. As conditions are constant, compiler eliminates the unused
code during optimization pass. At least all compilers I've tested did
that. So that it shouldn't have side effects at run time, binary code
should be as if it was #ifdef-ed.
===
Line 1185: well.., in UNICODE there is an allocation for cspname as
TCHAR*...but there is NO free(cspname) of anykind later !
That's the beauty of alloca, you don't need deallocation of any kind,
return redeems it automatically.
===
...
Remaining comments are variation of above. Yes,
if(sizeof(TCHAR)!=sizeof(char)) might appear controversial, but there is
reason for that: keeping as much as possible in active loop. There are
really too many #ifdefs...
===
So Andy, let me know how we can proceed : do you agree for some changes
to e_capi.c like I suggest above, and if so, do you want to do it
yourself or do you want me to propose something ?
As just mentioned, the code appearance is actually intentional. A bit
non-conventional code also keeps you more concentrated, because you have
to pay attention. And look, you totally did! So that mission is actually
accomplished! :-) Cheers.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List openssl-dev@openssl.org
Automated List Manager majord...@openssl.org