Changeset 2759 for trunk/src/kmk
- Timestamp:
- Jan 28, 2015, 5:14:00 PM (10 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/config.h.win
r2702 r2759 16 16 GNU Make; see the file COPYING. If not, write to the Free Software 17 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ 18 19 #ifndef ___config_h_win 20 #define ___config_h_win 18 21 19 22 /* Suppress some Visual C++ warnings. … … 534 537 #define _DIRENT_HAVE_D_TYPE 1 535 538 536 537 /* cygwin sucks to much in one end or the other. */ 539 /* bird: Not sure if this is necessary any more... */ 538 540 #define BATCH_MODE_ONLY_SHELL 539 541 … … 557 559 #endif 558 560 561 /* bird: Include mscfakes.h to make sure we have all it's tricks applied. */ 562 #ifndef ___mscfakes_h 563 # include "kmkbuiltin/mscfakes.h" 564 #endif 565 566 #endif /* bird */ 567 -
trunk/src/kmk/kmkbuiltin/kDepObj.c
r2591 r2759 27 27 * Header Files * 28 28 *******************************************************************************/ 29 #define MSCFAKES_NO_WINDOWS_H 29 30 #include "config.h" 30 31 #include <stdio.h> -
trunk/src/kmk/kmkbuiltin/mscfakes.c
r2756 r2759 467 467 468 468 469 int writev(int fd, const struct iovec *vector, int count) 470 { 471 int size = 0; 472 int i; 473 for (i = 0; i < count; i++) 474 { 475 int cb = write(fd, vector[i].iov_base, (int)vector[i].iov_len); 476 if (cb < 0) 469 /* We override the libc write function (in our modules only, unfortunately) so 470 we can kludge our way around a ENOSPC problem observed on build servers 471 capturing STDOUT and STDERR via pipes. Apparently this may happen when the 472 pipe buffer is full, even with the mscfake_init hack in place. 473 474 XXX: Probably need to hook into fwrite as well. */ 475 ssize_t msc_write(int fd, const void *pvSrc, size_t cbSrc) 476 { 477 ssize_t cbRet; 478 if (cbSrc < UINT_MAX / 4) 479 { 480 #ifndef MSC_WRITE_TEST 481 cbRet = _write(fd, pvSrc, (unsigned int)cbSrc); 482 #else 483 cbRet = -1; errno = ENOSPC; 484 #endif 485 if (cbRet < 0) 477 486 { 478 487 /* ENOSPC on pipe kludge. */ 479 char *pbCur; 480 size_t cbLeft; 481 int cbLimit; 482 int cSinceLastSuccess; 483 int iErr = errno; 484 488 int cbLimit; 489 int cSinceLastSuccess; 490 491 if (cbSrc == 0) 492 return 0; 485 493 if (errno != ENOSPC) 486 494 return -1; 487 if ((int)vector[i].iov_len == 0) 488 continue; 495 #ifndef MSC_WRITE_TEST 489 496 if (!isPipeFd(fd)) 490 497 { … … 492 499 return -1; 493 500 } 501 #endif 494 502 495 503 /* Likely a full pipe buffer, try write smaller amounts and do some 496 504 sleeping inbetween each unsuccessful one. */ 497 pbCur = vector[i].iov_base; 498 cbLeft = vector[i].iov_len; 499 cbLimit = cbLeft / 4; 505 cbLimit = cbSrc / 4; 500 506 if (cbLimit < 4) 501 507 cbLimit = 4; … … 503 509 cbLimit = 512; 504 510 cSinceLastSuccess = 0; 505 506 while (cbLeft > 0) 511 cbRet = 0; 512 #ifdef MSC_WRITE_TEST 513 cbLimit = 4; 514 #endif 515 516 while (cbSrc > 0) 507 517 { 508 int cbAttempt = cbLeft > cbLimit ? (int)cbLimit : (int)cbLeft;509 cb = write(fd, pbCur, cbAttempt);510 if (cb > 0)518 unsigned int cbAttempt = cbSrc > cbLimit ? (int)cbLimit : (int)cbSrc; 519 ssize_t cbActual = _write(fd, pvSrc, cbAttempt); 520 if (cbActual > 0) 511 521 { 512 assert(cb <= cbAttempt); 513 pbCur += cb; 514 cbLeft -= cb; 515 size += cb; 522 assert(cbActual <= (ssize_t)cbAttempt); 523 pvSrc = (char *)pvSrc + cbActual; 524 cbSrc -= cbActual; 525 cbRet += cbActual; 526 #ifndef MSC_WRITE_TEST 516 527 if (cbLimit < 32) 517 528 cbLimit = 32; 529 #endif 518 530 cSinceLastSuccess = 0; 519 531 } … … 538 550 } 539 551 } 540 cb = 0; 541 } 552 } 553 } 554 else 555 { 556 /* 557 * Type limit exceeded. Split the job up. 558 */ 559 cbRet = 0; 560 while (cbSrc > 0) 561 { 562 size_t cbToWrite = cbSrc > UINT_MAX / 4 ? UINT_MAX / 4 : cbSrc; 563 ssize_t cbWritten = msc_write(fd, pvSrc, cbToWrite); 564 if (cbWritten > 0) 565 { 566 pvSrc = (char *)pvSrc + (size_t)cbWritten; 567 cbSrc -= (size_t)cbWritten; 568 cbRet += (size_t)cbWritten; 569 } 570 else if (cbWritten == 0 || cbRet > 0) 571 break; 572 else 573 return -1; 574 } 575 } 576 return cbRet; 577 } 578 579 ssize_t writev(int fd, const struct iovec *vector, int count) 580 { 581 int size = 0; 582 int i; 583 for (i = 0; i < count; i++) 584 { 585 int cb = msc_write(fd, vector[i].iov_base, (int)vector[i].iov_len); 586 if (cb < 0) 587 return cb; 542 588 size += cb; 543 589 } … … 626 672 627 673 628 629 674 /** 630 675 * This is a kludge to make pipe handles blocking. -
trunk/src/kmk/kmkbuiltin/mscfakes.h
r2713 r2759 28 28 #ifdef _MSC_VER 29 29 30 /* Include the config file (kmk's) so we don't need to duplicate stuff from it here. */ 31 #include "config.h" 32 30 33 #include <io.h> 31 34 #include <direct.h> … … 34 37 #include <malloc.h> 35 38 #include "getopt.h" 39 #ifndef MSCFAKES_NO_WINDOWS_H 40 # include <Windows.h> 41 #endif 36 42 37 /* Note: Duplicated it config.h.win */38 43 #include <sys/stat.h> 39 44 #include <io.h> … … 79 84 typedef unsigned short gid_t; 80 85 #endif 86 #if defined(_M_AMD64) || defined(_M_X64) || defined(_M_IA64) || defined(_WIN64) 87 typedef __int64 ssize_t; 88 #else 81 89 typedef long ssize_t; 90 #endif 82 91 typedef unsigned long u_long; 83 92 typedef unsigned int u_int; 84 93 typedef unsigned short u_short; 85 94 86 #if ndef timerisset95 #if !defined(timerisset) && defined(MSCFAKES_NO_WINDOWS_H) 87 96 struct timeval 88 97 { … … 138 147 int symlink(const char *pszDst, const char *pszLink); 139 148 int utimes(const char *pszPath, const struct timeval *paTimes); 140 int writev(int fd, const struct iovec *vector, int count);149 ssize_t writev(int fd, const struct iovec *vector, int count); 141 150 142 151 /* bird write ENOSPC hacks. */ 152 #undef write 153 #define write msc_write 154 ssize_t msc_write(int fd, const void *pvSrc, size_t cbSrc); 143 155 144 156 /*
Note:
See TracChangeset
for help on using the changeset viewer.