Re: [xml] xmllib2-2.3.4 compiler warnings on QNX

Hi Daniel, All,

I'm looking at a old sources (2.2.11), but I assume the documentation
for xmlCopyChar is out of sync, as the first parameter is referred to as
@len:  pointer to the length of the char read (or zero)

  hum, not really. In this case there was nothing read or at least
not as a char. Having len == 0 indicates we don't know what's the size of
the UTF8 serialization of this character.

Yep, but I assume there was a time where len was passed as a pointer 
(and modified) and the doc still refers to this history.

  there is 2 things:
    - xmlCopyChar is public, it is exported from parserInternals.h
      so we can't change its signature now
    - I tend to agree that the len > 1 case don't make an useful
      use of the information. Would your patch still improve things
      considering we still pass the len parameter ? I.e. is it
      faster or cleaner ?

If a macro COPY_BUF gains a siginificant performance gain at all, I 
suggest following implementation:

xmlCopyCharMultiByte does the real work.
xmlCopyChar is for compatibility
COPY_BUFL and COPY_BUFV are the macro forms of xmlCopyChar, 
one of them should be renamed COPY_BUF for compatibility.
COPY_BUFL is preferable where l is known or even compile-time known
COPY_BUFV is preferable in the other cases.


#define COPY_BUFL(l,b,i,v)                       \
    if (l == 1) b[i++] = (xmlChar) v;                   \
    else i += xmlCopyCharMultiByte(l,&b[i],v)

#define COPY_BUFV(l,b,i,v)                       \
    if (v < 0x80) b[i++] = (xmlChar) v;                   \
    else i += xmlCopyCharMultiByte(l,&b[i],v)


int xmlCopyChar(int len, xmlChar *out, int val) {
        /* the len parameter is ignored */
        if  (val >= 0x80) {
                return xmlCopyCharMultiByte (out, val) {
        *out = (xmlChar) val;
        return 1;


int xmlCopyCharMultiByte(xmlChar *out, int val) {
        xmlChar *savedout = out;
        int bits; 
        if (val <   0x800) { *out++= (val >>  6) | 0xC0;  bits=  0; }
        else if (val < 0x10000) { *out++= (val >> 12) | 0xE0;  bits=  6; }
        else if (val < 0x110000)  { *out++= (val >> 18) | 0xF0;  bits= 12; }
        else {
                        "Internal error, xmlCopyChar 0x%X out of bound\n", val);
        for ( ; bits >= 0; bits-= 6)
                *out++= ((val >> bits) & 0x3F) | 0x80 ;
        return (out - savedout);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]