-rw-r--r-- | qmake/tools/qglobal.cpp | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/qmake/tools/qglobal.cpp b/qmake/tools/qglobal.cpp index 47cd6bd..342005d 100644 --- a/qmake/tools/qglobal.cpp +++ b/qmake/tools/qglobal.cpp | |||
@@ -88,129 +88,150 @@ bool qSysInfo( int *wordSize, bool *bigEndian ) | |||
88 | { | 88 | { |
89 | #if defined(QT_CHECK_NULL) | 89 | #if defined(QT_CHECK_NULL) |
90 | Q_ASSERT( wordSize != 0 ); | 90 | Q_ASSERT( wordSize != 0 ); |
91 | Q_ASSERT( bigEndian != 0 ); | 91 | Q_ASSERT( bigEndian != 0 ); |
92 | #endif | 92 | #endif |
93 | 93 | ||
94 | if ( si_alreadyDone ) { // run it only once | 94 | if ( si_alreadyDone ) { // run it only once |
95 | *wordSize = si_wordSize; | 95 | *wordSize = si_wordSize; |
96 | *bigEndian = si_bigEndian; | 96 | *bigEndian = si_bigEndian; |
97 | return TRUE; | 97 | return TRUE; |
98 | } | 98 | } |
99 | 99 | ||
100 | si_wordSize = 0; | 100 | si_wordSize = 0; |
101 | Q_ULONG n = (Q_ULONG)(~0); | 101 | Q_ULONG n = (Q_ULONG)(~0); |
102 | while ( n ) { // detect word size | 102 | while ( n ) { // detect word size |
103 | si_wordSize++; | 103 | si_wordSize++; |
104 | n /= 2; | 104 | n /= 2; |
105 | } | 105 | } |
106 | *wordSize = si_wordSize; | 106 | *wordSize = si_wordSize; |
107 | 107 | ||
108 | if ( *wordSize != 64 && | 108 | if ( *wordSize != 64 && |
109 | *wordSize != 32 && | 109 | *wordSize != 32 && |
110 | *wordSize != 16 ) { // word size: 16, 32 or 64 | 110 | *wordSize != 16 ) { // word size: 16, 32 or 64 |
111 | #if defined(QT_CHECK_RANGE) | 111 | #if defined(QT_CHECK_RANGE) |
112 | qFatal( "qSysInfo: Unsupported system word size %d", *wordSize ); | 112 | qFatal( "qSysInfo: Unsupported system word size %d", *wordSize ); |
113 | #endif | 113 | #endif |
114 | return FALSE; | 114 | return FALSE; |
115 | } | 115 | } |
116 | if ( sizeof(Q_INT8) != 1 || sizeof(Q_INT16) != 2 || sizeof(Q_INT32) != 4 || | 116 | if ( sizeof(Q_INT8) != 1 || sizeof(Q_INT16) != 2 || sizeof(Q_INT32) != 4 || |
117 | sizeof(Q_ULONG)*8 != si_wordSize || sizeof(float) != 4 || sizeof(double) != 8 ) { | 117 | sizeof(Q_ULONG)*8 != si_wordSize || sizeof(float) != 4 || sizeof(double) != 8 ) { |
118 | #if defined(QT_CHECK_RANGE) | 118 | #if defined(QT_CHECK_RANGE) |
119 | qFatal( "qSysInfo: Unsupported system data type size" ); | 119 | qFatal( "qSysInfo: Unsupported system data type size" ); |
120 | #endif | 120 | #endif |
121 | return FALSE; | 121 | return FALSE; |
122 | } | 122 | } |
123 | 123 | ||
124 | bool be16, be32; // determine byte ordering | 124 | bool be16, be32; // determine byte ordering |
125 | short ns = 0x1234; | 125 | short ns = 0x1234; |
126 | int nl = 0x12345678; | 126 | int nl = 0x12345678; |
127 | 127 | ||
128 | unsigned char *p = (unsigned char *)(&ns);// 16-bit integer | 128 | unsigned char *p = (unsigned char *)(&ns);// 16-bit integer |
129 | be16 = *p == 0x12; | 129 | be16 = *p == 0x12; |
130 | 130 | ||
131 | p = (unsigned char *)(&nl); // 32-bit integer | 131 | p = (unsigned char *)(&nl); // 32-bit integer |
132 | if ( p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78 ) | 132 | if ( p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78 ) |
133 | be32 = TRUE; | 133 | be32 = TRUE; |
134 | else | 134 | else |
135 | if ( p[0] == 0x78 && p[1] == 0x56 && p[2] == 0x34 && p[3] == 0x12 ) | 135 | if ( p[0] == 0x78 && p[1] == 0x56 && p[2] == 0x34 && p[3] == 0x12 ) |
136 | be32 = FALSE; | 136 | be32 = FALSE; |
137 | else | 137 | else |
138 | be32 = !be16; | 138 | be32 = !be16; |
139 | 139 | ||
140 | if ( be16 != be32 ) { // strange machine! | 140 | if ( be16 != be32 ) { // strange machine! |
141 | #if defined(QT_CHECK_RANGE) | 141 | #if defined(QT_CHECK_RANGE) |
142 | qFatal( "qSysInfo: Inconsistent system byte order" ); | 142 | qFatal( "qSysInfo: Inconsistent system byte order" ); |
143 | #endif | 143 | #endif |
144 | return FALSE; | 144 | return FALSE; |
145 | } | 145 | } |
146 | 146 | ||
147 | *bigEndian = si_bigEndian = be32; | 147 | *bigEndian = si_bigEndian = be32; |
148 | si_alreadyDone = TRUE; | 148 | si_alreadyDone = TRUE; |
149 | return TRUE; | 149 | return TRUE; |
150 | } | 150 | } |
151 | 151 | ||
152 | #if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN) | 152 | #if !defined(QWS) && defined(Q_OS_MAC) |
153 | |||
154 | #include "qt_mac.h" | ||
155 | |||
156 | int qMacVersion() | ||
157 | { | ||
158 | static int macver = Qt::MV_Unknown; | ||
159 | static bool first = TRUE; | ||
160 | if(first) { | ||
161 | first = FALSE; | ||
162 | long gestalt_version; | ||
163 | if(Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) { | ||
164 | if(gestalt_version >= 0x1020 && gestalt_version < 0x1030) | ||
165 | macver = Qt::MV_10_DOT_2; | ||
166 | else if(gestalt_version >= 0x1010 && gestalt_version < 0x1020) | ||
167 | macver = Qt::MV_10_DOT_1; | ||
168 | } | ||
169 | } | ||
170 | return macver; | ||
171 | } | ||
172 | Qt::MacintoshVersion qt_macver = (Qt::MacintoshVersion)qMacVersion(); | ||
173 | #elif defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN) | ||
153 | bool qt_winunicode; | 174 | bool qt_winunicode; |
154 | 175 | ||
155 | #include "qt_windows.h" | 176 | #include "qt_windows.h" |
156 | 177 | ||
157 | int qWinVersion() | 178 | int qWinVersion() |
158 | { | 179 | { |
159 | #ifndef VER_PLATFORM_WIN32s | 180 | #ifndef VER_PLATFORM_WIN32s |
160 | #define VER_PLATFORM_WIN32s 0 | 181 | #define VER_PLATFORM_WIN32s 0 |
161 | #endif | 182 | #endif |
162 | #ifndef VER_PLATFORM_WIN32_WINDOWS | 183 | #ifndef VER_PLATFORM_WIN32_WINDOWS |
163 | #define VER_PLATFORM_WIN32_WINDOWS 1 | 184 | #define VER_PLATFORM_WIN32_WINDOWS 1 |
164 | #endif | 185 | #endif |
165 | #ifndef VER_PLATFORM_WIN32_NT | 186 | #ifndef VER_PLATFORM_WIN32_NT |
166 | #define VER_PLATFORM_WIN32_NT 2 | 187 | #define VER_PLATFORM_WIN32_NT 2 |
167 | #endif | 188 | #endif |
168 | 189 | ||
169 | static int winver = Qt::WV_NT; | 190 | static int winver = Qt::WV_NT; |
170 | static int t=0; | 191 | static int t=0; |
171 | if ( !t ) { | 192 | if ( !t ) { |
172 | t=1; | 193 | t=1; |
173 | #ifdef Q_OS_TEMP | 194 | #ifdef Q_OS_TEMP |
174 | OSVERSIONINFOW osver; | 195 | OSVERSIONINFOW osver; |
175 | osver.dwOSVersionInfoSize = sizeof(osver); | 196 | osver.dwOSVersionInfoSize = sizeof(osver); |
176 | GetVersionEx( &osver ); | 197 | GetVersionEx( &osver ); |
177 | #else | 198 | #else |
178 | OSVERSIONINFOA osver; | 199 | OSVERSIONINFOA osver; |
179 | osver.dwOSVersionInfoSize = sizeof(osver); | 200 | osver.dwOSVersionInfoSize = sizeof(osver); |
180 | GetVersionExA( &osver ); | 201 | GetVersionExA( &osver ); |
181 | #endif | 202 | #endif |
182 | switch ( osver.dwPlatformId ) { | 203 | switch ( osver.dwPlatformId ) { |
183 | case VER_PLATFORM_WIN32s: | 204 | case VER_PLATFORM_WIN32s: |
184 | winver = Qt::WV_32s; | 205 | winver = Qt::WV_32s; |
185 | break; | 206 | break; |
186 | case VER_PLATFORM_WIN32_WINDOWS: | 207 | case VER_PLATFORM_WIN32_WINDOWS: |
187 | // We treat Windows Me (minor 90) the same as Windows 98 | 208 | // We treat Windows Me (minor 90) the same as Windows 98 |
188 | if ( ( osver.dwMinorVersion == 10 ) || ( osver.dwMinorVersion == 90 ) ) | 209 | if ( ( osver.dwMinorVersion == 10 ) || ( osver.dwMinorVersion == 90 ) ) |
189 | winver = Qt::WV_98; | 210 | winver = Qt::WV_98; |
190 | else | 211 | else |
191 | winver = Qt::WV_95; | 212 | winver = Qt::WV_95; |
192 | break; | 213 | break; |
193 | default: // VER_PLATFORM_WIN32_NT | 214 | default: // VER_PLATFORM_WIN32_NT |
194 | if ( osver.dwMajorVersion < 5 ) { | 215 | if ( osver.dwMajorVersion < 5 ) { |
195 | winver = Qt::WV_NT; | 216 | winver = Qt::WV_NT; |
196 | } else if ( osver.dwMinorVersion == 0 ) { | 217 | } else if ( osver.dwMinorVersion == 0 ) { |
197 | winver = Qt::WV_2000; | 218 | winver = Qt::WV_2000; |
198 | } else { | 219 | } else { |
199 | winver = Qt::WV_XP; | 220 | winver = Qt::WV_XP; |
200 | } | 221 | } |
201 | } | 222 | } |
202 | } | 223 | } |
203 | 224 | ||
204 | #if defined(UNICODE) | 225 | #if defined(UNICODE) |
205 | if ( winver & Qt::WV_NT_based ) | 226 | if ( winver & Qt::WV_NT_based ) |
206 | qt_winunicode = TRUE; | 227 | qt_winunicode = TRUE; |
207 | else | 228 | else |
208 | #endif | 229 | #endif |
209 | qt_winunicode = FALSE; | 230 | qt_winunicode = FALSE; |
210 | 231 | ||
211 | return winver; | 232 | return winver; |
212 | } | 233 | } |
213 | 234 | ||
214 | Qt::WindowsVersion qt_winver = (Qt::WindowsVersion)qWinVersion(); | 235 | Qt::WindowsVersion qt_winver = (Qt::WindowsVersion)qWinVersion(); |
215 | #endif | 236 | #endif |
216 | 237 | ||
@@ -260,145 +281,157 @@ Qt::WindowsVersion qt_winver = (Qt::WindowsVersion)qWinVersion(); | |||
260 | similar to the C printf() function. | 281 | similar to the C printf() function. |
261 | 282 | ||
262 | Example: | 283 | Example: |
263 | \code | 284 | \code |
264 | void f( int c ) | 285 | void f( int c ) |
265 | { | 286 | { |
266 | if ( c > 200 ) | 287 | if ( c > 200 ) |
267 | qWarning( "f: bad argument, c == %d", c ); | 288 | qWarning( "f: bad argument, c == %d", c ); |
268 | } | 289 | } |
269 | \endcode | 290 | \endcode |
270 | 291 | ||
271 | Under X11, the text is printed to stderr. Under Windows, the text | 292 | Under X11, the text is printed to stderr. Under Windows, the text |
272 | is sent to the debugger. | 293 | is sent to the debugger. |
273 | 294 | ||
274 | \warning The internal buffer is limited to 8196 bytes (including | 295 | \warning The internal buffer is limited to 8196 bytes (including |
275 | the '\0'-terminator). | 296 | the '\0'-terminator). |
276 | 297 | ||
277 | \warning Passing (const char *)0 as argument to qWarning might lead | 298 | \warning Passing (const char *)0 as argument to qWarning might lead |
278 | to crashes on certain platforms due to the platforms printf implementation. | 299 | to crashes on certain platforms due to the platforms printf implementation. |
279 | 300 | ||
280 | \sa qDebug(), qFatal(), qInstallMsgHandler(), | 301 | \sa qDebug(), qFatal(), qInstallMsgHandler(), |
281 | \link debug.html Debugging\endlink | 302 | \link debug.html Debugging\endlink |
282 | */ | 303 | */ |
283 | 304 | ||
284 | /*! | 305 | /*! |
285 | \fn void qFatal( const char *msg, ... ) | 306 | \fn void qFatal( const char *msg, ... ) |
286 | 307 | ||
287 | \relates QApplication | 308 | \relates QApplication |
288 | 309 | ||
289 | Prints a fatal error message \a msg and exits, or calls the | 310 | Prints a fatal error message \a msg and exits, or calls the |
290 | message handler (if it has been installed). | 311 | message handler (if it has been installed). |
291 | 312 | ||
292 | This function takes a format string and a list of arguments, | 313 | This function takes a format string and a list of arguments, |
293 | similar to the C printf() function. | 314 | similar to the C printf() function. |
294 | 315 | ||
295 | Example: | 316 | Example: |
296 | \code | 317 | \code |
297 | int divide( int a, int b ) | 318 | int divide( int a, int b ) |
298 | { | 319 | { |
299 | if ( b == 0 ) // program error | 320 | if ( b == 0 ) // program error |
300 | qFatal( "divide: cannot divide by zero" ); | 321 | qFatal( "divide: cannot divide by zero" ); |
301 | return a/b; | 322 | return a/b; |
302 | } | 323 | } |
303 | \endcode | 324 | \endcode |
304 | 325 | ||
305 | Under X11, the text is printed to stderr. Under Windows, the text | 326 | Under X11, the text is printed to stderr. Under Windows, the text |
306 | is sent to the debugger. | 327 | is sent to the debugger. |
307 | 328 | ||
308 | \warning The internal buffer is limited to 8196 bytes (including | 329 | \warning The internal buffer is limited to 8196 bytes (including |
309 | the '\0'-terminator). | 330 | the '\0'-terminator). |
310 | 331 | ||
311 | \warning Passing (const char *)0 as argument to qFatal might lead | 332 | \warning Passing (const char *)0 as argument to qFatal might lead |
312 | to crashes on certain platforms due to the platforms printf implementation. | 333 | to crashes on certain platforms due to the platforms printf implementation. |
313 | 334 | ||
314 | \sa qDebug(), qWarning(), qInstallMsgHandler(), | 335 | \sa qDebug(), qWarning(), qInstallMsgHandler(), |
315 | \link debug.html Debugging\endlink | 336 | \link debug.html Debugging\endlink |
316 | */ | 337 | */ |
317 | 338 | ||
318 | 339 | ||
319 | static QtMsgHandler handler = 0; // pointer to debug handler | 340 | static QtMsgHandler handler = 0; // pointer to debug handler |
320 | static const int QT_BUFFER_LENGTH = 8196;// internal buffer length | 341 | static const int QT_BUFFER_LENGTH = 8196;// internal buffer length |
321 | 342 | ||
322 | 343 | ||
323 | #ifdef Q_OS_MAC | 344 | #ifdef Q_OS_MAC |
324 | const unsigned char * p_str(const char * c, int len=-1) | 345 | QString cfstring2qstring(CFStringRef str) |
346 | { | ||
347 | CFIndex length = CFStringGetLength(str); | ||
348 | if(const UniChar *chars = CFStringGetCharactersPtr(str)) | ||
349 | return QString((QChar *)chars, length); | ||
350 | UniChar *buffer = (UniChar*)malloc(length * sizeof(UniChar)); | ||
351 | CFStringGetCharacters(str, CFRangeMake(0, length), buffer); | ||
352 | QString ret((QChar *)buffer, length); | ||
353 | free(buffer); | ||
354 | return ret; | ||
355 | } | ||
356 | |||
357 | unsigned char * p_str(const char * c, int len=-1) | ||
325 | { | 358 | { |
326 | const int maxlen = 255; | 359 | const int maxlen = 255; |
327 | if(len == -1) | 360 | if(len == -1) |
328 | len = qstrlen(c); | 361 | len = qstrlen(c); |
329 | if(len > maxlen) { | 362 | if(len > maxlen) { |
330 | qWarning( "p_str len must never exceed %d", maxlen ); | 363 | qWarning( "p_str len must never exceed %d", maxlen ); |
331 | len = maxlen; | 364 | len = maxlen; |
332 | } | 365 | } |
333 | unsigned char *ret = (unsigned char*)malloc(len+2); | 366 | unsigned char *ret = (unsigned char*)malloc(len+2); |
334 | *ret=len; | 367 | *ret=len; |
335 | memcpy(((char *)ret)+1,c,len); | 368 | memcpy(((char *)ret)+1,c,len); |
336 | *(ret+len+1) = '\0'; | 369 | *(ret+len+1) = '\0'; |
337 | return ret; | 370 | return ret; |
338 | } | 371 | } |
339 | 372 | ||
340 | const unsigned char * p_str(const QString &s) | 373 | unsigned char * p_str(const QString &s) |
341 | { | 374 | { |
342 | return p_str(s, s.length()); | 375 | return p_str(s, s.length()); |
343 | } | 376 | } |
344 | 377 | ||
345 | QCString p2qstring(const unsigned char *c) { | 378 | QCString p2qstring(const unsigned char *c) { |
346 | char *arr = (char *)malloc(c[0] + 1); | 379 | char *arr = (char *)malloc(c[0] + 1); |
347 | memcpy(arr, c+1, c[0]); | 380 | memcpy(arr, c+1, c[0]); |
348 | arr[c[0]] = '\0'; | 381 | arr[c[0]] = '\0'; |
349 | QCString ret = arr; | 382 | QCString ret = arr; |
350 | delete arr; | 383 | delete arr; |
351 | return ret; | 384 | return ret; |
352 | } | 385 | } |
353 | #endif | 386 | #endif |
354 | 387 | ||
355 | 388 | ||
356 | #ifdef Q_CC_MWERKS | 389 | #ifdef Q_CC_MWERKS |
357 | 390 | ||
358 | #include "qt_mac.h" | 391 | #include "qt_mac.h" |
359 | 392 | ||
360 | extern bool qt_is_gui_used; | 393 | extern bool qt_is_gui_used; |
361 | static void mac_default_handler( const char *msg ) | 394 | static void mac_default_handler( const char *msg ) |
362 | { | 395 | { |
363 | if ( qt_is_gui_used ) { | 396 | if ( qt_is_gui_used ) { |
364 | const char *p = p_str(msg); | 397 | const char *p = p_str(msg); |
365 | DebugStr(p); | 398 | DebugStr(p); |
366 | free(p); | 399 | free(p); |
367 | } else { | 400 | } else { |
368 | fprintf( stderr, msg ); | 401 | fprintf( stderr, msg ); |
369 | } | 402 | } |
370 | } | 403 | } |
371 | 404 | ||
372 | #endif | 405 | #endif |
373 | 406 | ||
374 | 407 | ||
375 | void qDebug( const char *msg, ... ) | 408 | void qDebug( const char *msg, ... ) |
376 | { | 409 | { |
377 | char buf[QT_BUFFER_LENGTH]; | 410 | char buf[QT_BUFFER_LENGTH]; |
378 | va_list ap; | 411 | va_list ap; |
379 | va_start( ap, msg ); // use variable arg list | 412 | va_start( ap, msg ); // use variable arg list |
380 | if ( handler ) { | 413 | if ( handler ) { |
381 | #if defined(QT_VSNPRINTF) | 414 | #if defined(QT_VSNPRINTF) |
382 | QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); | 415 | QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); |
383 | #else | 416 | #else |
384 | vsprintf( buf, msg, ap ); | 417 | vsprintf( buf, msg, ap ); |
385 | #endif | 418 | #endif |
386 | va_end( ap ); | 419 | va_end( ap ); |
387 | (*handler)( QtDebugMsg, buf ); | 420 | (*handler)( QtDebugMsg, buf ); |
388 | } else { | 421 | } else { |
389 | #if defined(Q_CC_MWERKS) | 422 | #if defined(Q_CC_MWERKS) |
390 | vsprintf( buf, msg, ap ); // ### is there no vsnprintf()? | 423 | vsprintf( buf, msg, ap ); // ### is there no vsnprintf()? |
391 | va_end( ap ); | 424 | va_end( ap ); |
392 | mac_default_handler(buf); | 425 | mac_default_handler(buf); |
393 | #else | 426 | #else |
394 | vfprintf( stderr, msg, ap ); | 427 | vfprintf( stderr, msg, ap ); |
395 | va_end( ap ); | 428 | va_end( ap ); |
396 | fprintf( stderr, "\n" ); // add newline | 429 | fprintf( stderr, "\n" ); // add newline |
397 | #endif | 430 | #endif |
398 | } | 431 | } |
399 | } | 432 | } |
400 | 433 | ||
401 | // copied... this looks really bad. | 434 | // copied... this looks really bad. |
402 | void debug( const char *msg, ... ) | 435 | void debug( const char *msg, ... ) |
403 | { | 436 | { |
404 | char buf[QT_BUFFER_LENGTH]; | 437 | char buf[QT_BUFFER_LENGTH]; |
@@ -580,140 +613,140 @@ void qSystemWarning( const char* msg, int code ) | |||
580 | 613 | ||
581 | FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, | 614 | FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, |
582 | NULL, | 615 | NULL, |
583 | code, | 616 | code, |
584 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | 617 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
585 | (char*)&string, | 618 | (char*)&string, |
586 | 0, | 619 | 0, |
587 | NULL ); | 620 | NULL ); |
588 | 621 | ||
589 | qWarning( "%s\n\tError code %d - %s", msg, code, (const char*)string ); | 622 | qWarning( "%s\n\tError code %d - %s", msg, code, (const char*)string ); |
590 | #endif | 623 | #endif |
591 | 624 | ||
592 | LocalFree( (HLOCAL)string ); | 625 | LocalFree( (HLOCAL)string ); |
593 | #else | 626 | #else |
594 | if ( code != -1 ) | 627 | if ( code != -1 ) |
595 | qWarning( "%s\n\tError code %d - %s", msg, code, strerror( code ) ); | 628 | qWarning( "%s\n\tError code %d - %s", msg, code, strerror( code ) ); |
596 | else | 629 | else |
597 | qWarning( msg ); | 630 | qWarning( msg ); |
598 | #endif | 631 | #endif |
599 | #endif | 632 | #endif |
600 | } | 633 | } |
601 | 634 | ||
602 | /*! | 635 | /*! |
603 | \fn void Q_ASSERT( bool test ) | 636 | \fn void Q_ASSERT( bool test ) |
604 | 637 | ||
605 | \relates QApplication | 638 | \relates QApplication |
606 | 639 | ||
607 | Prints a warning message containing the source code file name and | 640 | Prints a warning message containing the source code file name and |
608 | line number if \a test is FALSE. | 641 | line number if \a test is FALSE. |
609 | 642 | ||
610 | This is really a macro defined in \c qglobal.h. | 643 | This is really a macro defined in \c qglobal.h. |
611 | 644 | ||
612 | Q_ASSERT is useful for testing pre- and post-conditions. | 645 | Q_ASSERT is useful for testing pre- and post-conditions. |
613 | 646 | ||
614 | Example: | 647 | Example: |
615 | \code | 648 | \code |
616 | // | 649 | // |
617 | // File: div.cpp | 650 | // File: div.cpp |
618 | // | 651 | // |
619 | 652 | ||
620 | #include <qglobal.h> | 653 | #include <qglobal.h> |
621 | 654 | ||
622 | int divide( int a, int b ) | 655 | int divide( int a, int b ) |
623 | { | 656 | { |
624 | Q_ASSERT( b != 0 ); // this is line 9 | 657 | Q_ASSERT( b != 0 ); // this is line 9 |
625 | return a/b; | 658 | return a/b; |
626 | } | 659 | } |
627 | \endcode | 660 | \endcode |
628 | 661 | ||
629 | If \c b is zero, the Q_ASSERT statement will output the following | 662 | If \c b is zero, the Q_ASSERT statement will output the following |
630 | message using the qWarning() function: | 663 | message using the qWarning() function: |
631 | \code | 664 | \code |
632 | ASSERT: "b == 0" in div.cpp (9) | 665 | ASSERT: "b == 0" in div.cpp (9) |
633 | \endcode | 666 | \endcode |
634 | 667 | ||
635 | \sa qWarning(), \link debug.html Debugging\endlink | 668 | \sa qWarning(), \link debug.html Debugging\endlink |
636 | */ | 669 | */ |
637 | 670 | ||
638 | 671 | ||
639 | /*! | 672 | /*! |
640 | \fn void Q_CHECK_PTR( void *p ) | 673 | \fn void Q_CHECK_PTR( void *p ) |
641 | 674 | ||
642 | \relates QApplication | 675 | \relates QApplication |
643 | 676 | ||
644 | If \a p is null, a fatal messages says that the program ran out of | 677 | If \a p is 0, a fatal messages says that the program ran out of |
645 | memory and exits. If \e p is not null, nothing happens. | 678 | memory and exits. If \e p is not 0, nothing happens. |
646 | 679 | ||
647 | This is really a macro defined in \c qglobal.h. | 680 | This is really a macro defined in \c qglobal.h. |
648 | 681 | ||
649 | Example: | 682 | Example: |
650 | \code | 683 | \code |
651 | int *a; | 684 | int *a; |
652 | 685 | ||
653 | Q_CHECK_PTR( a = new int[80] ); // WRONG! | 686 | Q_CHECK_PTR( a = new int[80] ); // WRONG! |
654 | 687 | ||
655 | a = new int[80]; // Right | 688 | a = new (nothrow) int[80]; // Right |
656 | Q_CHECK_PTR( a ); | 689 | Q_CHECK_PTR( a ); |
657 | \endcode | 690 | \endcode |
658 | 691 | ||
659 | \sa qFatal(), \link debug.html Debugging\endlink | 692 | \sa qFatal(), \link debug.html Debugging\endlink |
660 | */ | 693 | */ |
661 | 694 | ||
662 | 695 | ||
663 | // | 696 | // |
664 | // The Q_CHECK_PTR macro calls this function to check if an allocation went ok. | 697 | // The Q_CHECK_PTR macro calls this function to check if an allocation went ok. |
665 | // | 698 | // |
666 | #if (QT_VERSION-0 >= 0x040000) | 699 | #if (QT_VERSION-0 >= 0x040000) |
667 | #if defined(Q_CC_GNU) | 700 | #if defined(Q_CC_GNU) |
668 | #warning "Change Q_CHECK_PTR to '{if ((p)==0) qt_check_pointer(__FILE__,__LINE__);}'" | 701 | #warning "Change Q_CHECK_PTR to '{if ((p)==0) qt_check_pointer(__FILE__,__LINE__);}'" |
669 | #warning "No need for qt_check_pointer() to return a value - make it void!" | 702 | #warning "No need for qt_check_pointer() to return a value - make it void!" |
670 | #endif | 703 | #endif |
671 | #endif | 704 | #endif |
672 | bool qt_check_pointer( bool c, const char *n, int l ) | 705 | bool qt_check_pointer( bool c, const char *n, int l ) |
673 | { | 706 | { |
674 | if ( c ) | 707 | if ( c ) |
675 | qWarning( "In file %s, line %d: Out of memory", n, l ); | 708 | qWarning( "In file %s, line %d: Out of memory", n, l ); |
676 | return TRUE; | 709 | return TRUE; |
677 | } | 710 | } |
678 | 711 | ||
679 | 712 | ||
680 | static bool firstObsoleteWarning(const char *obj, const char *oldfunc ) | 713 | static bool firstObsoleteWarning(const char *obj, const char *oldfunc ) |
681 | { | 714 | { |
682 | static QAsciiDict<int> *obsoleteDict = 0; | 715 | static QAsciiDict<int> *obsoleteDict = 0; |
683 | if ( !obsoleteDict ) { // first time func is called | 716 | if ( !obsoleteDict ) { // first time func is called |
684 | obsoleteDict = new QAsciiDict<int>; | 717 | obsoleteDict = new QAsciiDict<int>; |
685 | #if defined(QT_DEBUG) | 718 | #if defined(QT_DEBUG) |
686 | qDebug( | 719 | qDebug( |
687 | "You are using obsolete functions in the Qt library. Call the function\n" | 720 | "You are using obsolete functions in the Qt library. Call the function\n" |
688 | "qSuppressObsoleteWarnings() to suppress obsolete warnings.\n" | 721 | "qSuppressObsoleteWarnings() to suppress obsolete warnings.\n" |
689 | ); | 722 | ); |
690 | #endif | 723 | #endif |
691 | } | 724 | } |
692 | QCString s( obj ); | 725 | QCString s( obj ); |
693 | s += "::"; | 726 | s += "::"; |
694 | s += oldfunc; | 727 | s += oldfunc; |
695 | if ( obsoleteDict->find(s.data()) == 0 ) { | 728 | if ( obsoleteDict->find(s.data()) == 0 ) { |
696 | obsoleteDict->insert( s.data(), (int*)1 );// anything different from 0 | 729 | obsoleteDict->insert( s.data(), (int*)1 );// anything different from 0 |
697 | return TRUE; | 730 | return TRUE; |
698 | } | 731 | } |
699 | return FALSE; | 732 | return FALSE; |
700 | } | 733 | } |
701 | 734 | ||
702 | static bool suppressObsolete = FALSE; | 735 | static bool suppressObsolete = FALSE; |
703 | 736 | ||
704 | void qSuppressObsoleteWarnings( bool suppress ) | 737 | void qSuppressObsoleteWarnings( bool suppress ) |
705 | { | 738 | { |
706 | suppressObsolete = suppress; | 739 | suppressObsolete = suppress; |
707 | } | 740 | } |
708 | 741 | ||
709 | void qObsolete( const char *obj, const char *oldfunc, const char *newfunc ) | 742 | void qObsolete( const char *obj, const char *oldfunc, const char *newfunc ) |
710 | { | 743 | { |
711 | if ( suppressObsolete ) | 744 | if ( suppressObsolete ) |
712 | return; | 745 | return; |
713 | if ( !firstObsoleteWarning(obj, oldfunc) ) | 746 | if ( !firstObsoleteWarning(obj, oldfunc) ) |
714 | return; | 747 | return; |
715 | if ( obj ) | 748 | if ( obj ) |
716 | qDebug( "%s::%s: This function is obsolete, use %s instead.", | 749 | qDebug( "%s::%s: This function is obsolete, use %s instead.", |
717 | obj, oldfunc, newfunc ); | 750 | obj, oldfunc, newfunc ); |
718 | else | 751 | else |
719 | qDebug( "%s: This function is obsolete, use %s instead.", | 752 | qDebug( "%s: This function is obsolete, use %s instead.", |