BusyBox Bug and Patch Tracking
BusyBox
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0001491 [buildroot] Architecture Specific major always 09-06-07 08:54 10-20-07 06:49
Reporter HappyCactus View Status public  
Assigned To UlfSamuelsson
Priority normal Resolution open  
Status assigned   Product Version
Summary 0001491: QTopia4 and uclibc string.h macro "index()" conflict
Description QTopia4 4.3.1 and uclibc doesn't compile when __UCLIBC_SUSV3_LEGACY_MACROS__ is defined in uclibc.
Infacts we see in $(STAGING_DIR)/usr/include/string.h:

# ifdef __UCLIBC_SUSV3_LEGACY_MACROS__
/* bcopy/bzero/bcmp/index/rindex are marked LEGACY in SuSv3.
 * They are replaced as proposed by SuSv3. Don't sync this part
 * with glibc and keep it in sync with strings.h. */

# define bcopy(src,dest,n) (memmove((dest), (src), (n)), (void) 0)
# define bzero(s,n) (memset((s), '\0', (n)), (void) 0)
# define bcmp(s1,s2,n) memcmp((s1), (s2), (size_t)(n))
# define index(s,c) strchr((s), (c))
# define rindex(s,c) strrchr((s), (c))
# endif
#

Not very smart to define a macro for this very common names. Imagine what happens if src/corelib/kernel/qabstractitemmodel.h contains his code:

class Q_CORE_EXPORT QAbstractItemModel : public QObject
{
// ...
    virtual QModelIndex index(int row, int column,
           const QModelIndex &parent = QModelIndex()) const = 0;
 
Of course, the preprocessor changes the index to strchr( ... and doesn't compile.
A workaround is a patch for the QByteArray.h file that unsets the macro.
But it should be better to change the #define index(r,s) with a simple call to the chrchr () function and let the compiler do his optimizations.

Additional Information
Attached Files

- Relationships

- Notes
(0002768)
UlfSamuelsson
09-23-07 11:48

THere is a UCLIBC configuration item UCLIBC_SUSV3_LEGACY_MACROS
and you can instead set UCLIBC_SUSV3_LEGACY.
Then uclibc should be built without the macros.
There are warnings on ABI incompatability, which
someone who knows why, might care to explain further.
 
(0002844)
bernhardf
10-19-07 14:43

Thinking about this, qtopia sounds like is is using a reserved name (i.e. "index"), so it really is qtopia's fault, from a quick look.
 
(0002848)
HappyCactus
10-20-07 06:49

Nope.
The is no reserved keyword in C/C++ such as index. it's a normal function, that may be present in any library.
The C++ language has an elegant solution for these kind of conflicts, that is namespaces and class access.
Now, index() in C++ is resolved first in a class scope (by looking in the class definition for any method), second in the namespace scope (by searching through the namespace definition), last in the global or name-less scope.
Index is not a reserved word in the language.
So it should preserve the language normal way to resolve the name scopes.
QTopia correctly defines index as a class method.
But uclibc defines index as a MACRO - so subverting the normal C++ resolution of names.
So it is definitely a uclibc problem, NOT a qtopia issue: it break the language paradigms, so it's wrong.
It's also can be a problem with other programs, because macros introduces weak points where bugs can be very difficult to spot and correct.

as a 1st rule of a C/C++ good programmer guideline I suggest to avoid macros when possible, use inlining declaration to allow compiler optimization.
This should, in the current issue, solve this bug and any other future similar bug.

regards,

ing. Federico Fuga
 

- Issue History
Date Modified Username Field Change
09-06-07 08:54 HappyCactus New Issue
09-06-07 08:54 HappyCactus Status new => assigned
09-06-07 08:54 HappyCactus Assigned To  => buildroot
09-23-07 11:46 UlfSamuelsson Assigned To buildroot => UlfSamuelsson
09-23-07 11:48 UlfSamuelsson Note Added: 0002768
10-19-07 14:43 bernhardf Note Added: 0002844
10-20-07 06:49 HappyCactus Note Added: 0002848


Copyright © 2000 - 2006 Mantis Group
Powered by Mantis Bugtracker