Changeset 476
- Timestamp:
- Jun 1, 2015, 6:58:33 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/acconfig.h
r295 r476 375 375 /* Define if your vsnprintf is broken. */ 376 376 #undef HAVE_BROKEN_VSNPRINTF 377 378 /* Define if you have va_copy. */379 #undef VA_COPY380 381 /* Define if va_list may be copied as array. */382 #undef VA_COPY_AS_ARRAY383 377 384 378 /* Define if you need unix entropy gatherer. */ -
trunk/aclocal.m4
r475 r476 276 276 dnl *** va_copy checks *** 277 277 dnl ********************** 278 AC_DEFUN([SL_CHECK_VA_COPY], 279 [AC_MSG_CHECKING(for va_copy()) 280 AC_CACHE_VAL(sh_cv_va_copy,[ 281 AC_TRY_RUN([ 282 #include <stdarg.h> 283 void f (int i, ...) { 284 va_list args1, args2; 285 va_start (args1, i); 286 va_copy (args2, args1); 287 if (va_arg (args2, int) != 42) 288 exit (1); 289 if (va_arg (args1, int) != 42) 290 exit (1); 291 va_end (args1); va_end (args2); 292 } 293 int main() { 294 f (0, 42); 295 return 0; 296 }], 297 sh_cv_va_copy=yes 298 , 299 sh_cv_va_copy=no 300 , 301 sh_cv_va_copy=no) 278 # va_copy.m4 serial 1 (js-1.6.20070208) 279 280 dnl ## From the OpenWrt Project (http://openwrt.org) 281 dnl ## Project is GPL v2 282 dnl ## 283 dnl ## 284 dnl ## Check for C99 va_copy() implementation 285 dnl ## (and provide fallback implementation if neccessary) 286 dnl ## 287 dnl ## configure.in: 288 dnl ## AC_CHECK_VA_COPY 289 dnl ## foo.c: 290 dnl ## #include "config.h" 291 dnl ## [...] 292 dnl ## va_copy(d,s) 293 dnl ## 294 dnl ## This check is rather complex: first because we really have to 295 dnl ## try various possible implementations in sequence and second, we 296 dnl ## cannot define a macro in config.h with parameters directly. 297 dnl ## 298 299 dnl # test program for va_copy() implementation 300 changequote(<<,>>) 301 m4_define(__va_copy_test, <<[ 302 #include <stdlib.h> 303 #include <stdarg.h> 304 #include <string.h> 305 #define DO_VA_COPY(d, s) $1 306 void test(char *str, ...) 307 { 308 va_list ap, ap2; 309 int i; 310 va_start(ap, str); 311 DO_VA_COPY(ap2, ap); 312 for (i = 1; i <= 9; i++) { 313 int k = (int)va_arg(ap, int); 314 if (k != i) 315 abort(); 316 } 317 DO_VA_COPY(ap, ap2); 318 for (i = 1; i <= 9; i++) { 319 int k = (int)va_arg(ap, int); 320 if (k != i) 321 abort(); 322 } 323 va_end(ap); 324 } 325 int main(int argc, char *argv[]) 326 { 327 test("test", 1, 2, 3, 4, 5, 6, 7, 8, 9); 328 exit(0); 329 } 330 ]>>) 331 changequote([,]) 332 333 dnl # test driver for va_copy() implementation 334 m4_define(__va_copy_check, [ 335 AH_VERBATIM($1, 336 [/* Predefined possible va_copy() implementation (id: $1) */ 337 #define __VA_COPY_USE_$1(d, s) $2]) 338 if test ".$ac_cv_va_copy" = .; then 339 AC_TRY_RUN(__va_copy_test($2), [ac_cv_va_copy="$1"]) 340 fi 302 341 ]) 303 AC_MSG_RESULT($sh_cv_va_copy) 304 AC_MSG_CHECKING(for __va_copy()) 305 AC_CACHE_VAL(sh_cv___va_copy,[ 306 AC_TRY_RUN([ 307 #include <stdarg.h> 308 void f (int i, ...) { 309 va_list args1, args2; 310 va_start (args1, i); 311 __va_copy (args2, args1); 312 if (va_arg (args2, int) != 42) 313 exit (1); 314 if (va_arg (args1, int) != 42) 315 exit (1); 316 va_end (args1); va_end (args2); 317 } 318 int main() { 319 f (0, 42); 320 return 0; 321 }], 322 sh_cv___va_copy=yes 323 , 324 sh_cv___va_copy=no 325 , 326 sh_cv___va_copy=no) 342 343 dnl # Autoconf check for va_copy() implementation checking 344 AC_DEFUN([AC_CHECK_VA_COPY],[ 345 dnl # provide Autoconf display check message 346 AC_MSG_CHECKING(for va_copy() function) 347 dnl # check for various implementations in priorized sequence 348 AC_CACHE_VAL(ac_cv_va_copy, [ 349 ac_cv_va_copy="" 350 dnl # 1. check for standardized C99 macro 351 __va_copy_check(C99, [va_copy((d), (s))]) 352 dnl # 2. check for alternative/deprecated GCC macro 353 __va_copy_check(GCM, [VA_COPY((d), (s))]) 354 dnl # 3. check for internal GCC macro (high-level define) 355 __va_copy_check(GCH, [__va_copy((d), (s))]) 356 dnl # 4. check for internal GCC macro (built-in function) 357 __va_copy_check(GCB, [__builtin_va_copy((d), (s))]) 358 dnl # 5. check for assignment approach (assuming va_list is a struct) 359 __va_copy_check(ASS, [do { (d) = (s); } while (0)]) 360 dnl # 6. check for assignment approach (assuming va_list is a pointer) 361 __va_copy_check(ASP, [do { *(d) = *(s); } while (0)]) 362 dnl # 7. check for memory copying approach (assuming va_list is a struct) 363 __va_copy_check(CPS, [memcpy((void *)&(d), (void *)&(s)), sizeof((s))]) 364 dnl # 8. check for memory copying approach (assuming va_list is a pointer) 365 __va_copy_check(CPP, [memcpy((void *)(d), (void *)(s)), sizeof(*(s))]) 366 if test ".$ac_cv_va_copy" = .; then 367 AC_ERROR([no working implementation found]) 368 fi 369 ]) 370 dnl # optionally activate the fallback implementation 371 if test ".$ac_cv_va_copy" = ".C99"; then 372 AC_DEFINE(HAVE_VA_COPY, 1, [Define if va_copy() macro exists (and no fallback implementation is required)]) 373 fi 374 dnl # declare which fallback implementation to actually use 375 AC_DEFINE_UNQUOTED([__VA_COPY_USE], [__VA_COPY_USE_$ac_cv_va_copy], 376 [Define to id of used va_copy() implementation]) 377 dnl # provide activation hook for fallback implementation 378 AH_VERBATIM([__VA_COPY_ACTIVATION], 379 [/* Optional va_copy() implementation activation */ 380 #ifndef HAVE_VA_COPY 381 #define va_copy(d, s) __VA_COPY_USE(d, s) 382 #endif 327 383 ]) 328 AC_MSG_RESULT($sh_cv___va_copy) 329 AC_MSG_CHECKING(whether va_lists can be copied by value) 330 AC_CACHE_VAL(sh_cv_va_val_copy,[ 331 AC_TRY_RUN([ 332 #include <stdarg.h> 333 void f (int i, ...) { 334 va_list args1, args2; 335 va_start (args1, i); 336 args2 = args1; 337 if (va_arg (args2, int) != 42) 338 exit (1); 339 if (va_arg (args1, int) != 42) 340 exit (1); 341 va_end (args1); va_end (args2); 342 } 343 int main() { 344 f (0, 42); 345 return 0; 346 }], 347 sh_cv_va_val_copy=yes 348 , 349 sh_cv_va_val_copy=no 350 , 351 sh_cv_va_val_copy=no) 352 ]) 353 if test "x$sh_cv_va_copy" = "xyes"; then 354 AC_DEFINE(VA_COPY, va_copy) 355 else if test "x$sh_cv___va_copy" = "xyes"; then 356 AC_DEFINE(VA_COPY, __va_copy) 357 fi 358 fi 359 if test "x$sh_cv_va_val_copy" = "xno"; then 360 AC_DEFINE(VA_COPY_AS_ARRAY) 361 fi 362 AC_MSG_RESULT($sh_cv_va_val_copy) 384 dnl # provide Autoconf display result message 385 if test ".$ac_cv_va_copy" = ".C99"; then 386 AC_MSG_RESULT([yes]) 387 else 388 AC_MSG_RESULT([no (using fallback implementation)]) 389 fi 363 390 ]) 364 391 -
trunk/configure.ac
r474 r476 395 395 ) 396 396 AC_CHECK_FUNC(statfs, AC_DEFINE(HAVE_STATFS) statfs="yes", statfs="no") 397 SL_CHECK_VA_COPY397 AC_CHECK_VA_COPY 398 398 AC_CHECK_FUNCS(vsnprintf, [SL_CHECK_VSNPRINTF]) 399 399 AC_CHECK_MLOCK -
trunk/docs/Changelog
r475 r476 1 1 3.1.6: 2 * More modern and more complete VA_COPY autoconf macro 3 (from the openwrt project) 2 4 * Modify testcompile.sh to remove 'smatch' and use 'clang' 3 5 instead. -
trunk/src/sh_error.c
r444 r476 1574 1574 } 1575 1575 1576 #if !defined(VA_COPY)1577 #if defined(__GNUC__) && defined(__PPC__) && (defined(_CALL_SYSV) || defined(_WIN32))1578 #define VA_COPY(ap1, ap2) (*(ap1) = *(ap2))1579 #elif defined(VA_COPY_AS_ARRAY)1580 #define VA_COPY(ap1, ap2) memmove ((ap1), (ap2), sizeof (va_list))1581 #else /* va_list is a pointer */1582 #define VA_COPY(ap1, ap2) ((ap1) = (ap2))1583 #endif1584 #endif1585 1586 1576 1587 1577 /* print an error into string … … 1717 1707 else 1718 1708 { 1719 /* use VA_COPY*/1720 /*@i@*/ VA_COPY(vl2, vl);1709 /* use va_copy */ 1710 /*@i@*/va_copy(vl2, vl); 1721 1711 len = sl_strlen(lmsg->msg); 1722 1712 /*@i@*/required = sl_vsnprintf(&(lmsg->msg[len]), -
trunk/src/slib.c
r473 r476 587 587 588 588 589 #if !defined (VA_COPY)590 #if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))591 #define VA_COPY(ap1, ap2) (*(ap1) = *(ap2))592 #elif defined (VA_COPY_AS_ARRAY)593 #define VA_COPY(ap1, ap2) memmove ((ap1), (ap2), sizeof (va_list))594 #else /* va_list is a pointer */595 #define VA_COPY(ap1, ap2) ((ap1) = (ap2))596 #endif597 #endif598 599 589 #if !defined(HAVE_VSNPRINTF) || defined(HAVE_BROKEN_VSNPRINTF) 600 590 static … … 784 774 str[n-1] = '\0'; 785 775 #else 786 VA_COPY (vl2, vl);/* save the argument list */776 va_copy(vl2, vl); /* save the argument list */ 787 777 total = sl_printf_count (format, vl); 788 778 len = (int) total; … … 830 820 str[n-1] = '\0'; 831 821 #else 832 VA_COPY (vl2, vl);/* save the argument list */822 va_copy(vl2, vl); /* save the argument list */ 833 823 total = sl_printf_count (format, vl); 834 824 if (total < n)
Note:
See TracChangeset
for help on using the changeset viewer.