Changeset 3173 in kBuild
- Timestamp:
- Mar 21, 2018 9:37:41 PM (7 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/Makefile.kmk
r3170 r3173 27 27 include $(KBUILD_PATH)/subheader.kmk 28 28 29 # Enable new children handling for windows. 30 CONFIG_NEW_WIN_CHILDREN = 1 29 31 30 32 # … … 225 227 kmk_DEFS += CONFIG_WITH_MAKE_STATS 226 228 endif 227 ifdef CONFIG_WITH_KMK_BUILTIN_STATS229 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS 228 230 kmk_DEFS += CONFIG_WITH_KMK_BUILTIN_STATS 229 endif231 #endif 230 232 ifdef CONFIG_WITH_EVAL_COMPILER 231 233 kmk_DEFS += CONFIG_WITH_EVAL_COMPILER -
trunk/src/kmk/kmkbuiltin.c
r3172 r3173 5 5 6 6 /* 7 * Copyright (c) 2005-201 0knut st. osmundsen <[email protected]>7 * Copyright (c) 2005-2018 knut st. osmundsen <[email protected]> 8 8 * 9 9 * This file is part of kBuild. … … 24 24 */ 25 25 26 /******************************************************************************* 27 * Header Files * 28 *******************************************************************************/ 26 27 /********************************************************************************************************************************* 28 * Header Files * 29 *********************************************************************************************************************************/ 29 30 #include <string.h> 30 31 #include <stdlib.h> … … 39 40 #include "makeint.h" 40 41 #include "job.h" 42 #include "variable.h" 41 43 #if defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN) 42 44 # include "w32/winchildren.h" … … 48 50 extern char **environ; 49 51 #endif 52 53 54 /********************************************************************************************************************************* 55 * Global Variables * 56 *********************************************************************************************************************************/ 57 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS 58 extern int print_stats_flag; 59 #endif 60 50 61 51 62 … … 234 245 static const KMKBUILTINENTRY g_aBuiltIns[] = 235 246 { 236 #define BUILTIN_ENTRY(a_fn, a_sz, a_uFnSignature, fM pSafe, fNeedEnv) \247 #define BUILTIN_ENTRY(a_fn, a_sz, a_uFnSignature, fMtSafe, fNeedEnv) \ 237 248 { { { sizeof(a_sz) - 1, a_sz, } }, \ 238 (uintptr_t)a_fn, a_uFnSignature, fM pSafe, fNeedEnv }249 (uintptr_t)a_fn, a_uFnSignature, fMtSafe, fNeedEnv } 239 250 240 251 /* More frequently used commands: */ … … 245 256 BUILTIN_ENTRY(kmk_builtin_kDepObj, "kDepObj", FN_SIG_MAIN, 1, 0), 246 257 #ifdef KBUILD_OS_WINDOWS 247 BUILTIN_ENTRY(kmk_builtin_kSubmit, "kSubmit", FN_SIG_MAIN_SPAWNS, 0, 0),258 BUILTIN_ENTRY(kmk_builtin_kSubmit, "kSubmit", FN_SIG_MAIN_SPAWNS, 0, 1), 248 259 #endif 249 260 BUILTIN_ENTRY(kmk_builtin_mkdir, "mkdir", FN_SIG_MAIN, 0, 0), 250 261 BUILTIN_ENTRY(kmk_builtin_mv, "mv", FN_SIG_MAIN, 0, 0), 251 BUILTIN_ENTRY(kmk_builtin_redirect, "redirect", FN_SIG_MAIN_SPAWNS, 0, 1),262 BUILTIN_ENTRY(kmk_builtin_redirect, "redirect", FN_SIG_MAIN_SPAWNS, 1, 1), 252 263 BUILTIN_ENTRY(kmk_builtin_rm, "rm", FN_SIG_MAIN, 0, 1), 253 264 BUILTIN_ENTRY(kmk_builtin_rmdir, "rmdir", FN_SIG_MAIN, 0, 0), … … 347 358 /* 348 359 * That's a match! 360 * 361 * First get the environment if it is actually needed. This is 362 * especially important when we run on a worker thread as it must 363 * not under any circumstances do stuff like target_environment. 349 364 */ 350 int rc; 365 int rc; 366 char **papszEnvVars = NULL; 367 if (pEntry->fNeedEnv) 368 { 369 papszEnvVars = pChild->environment; 370 if (!papszEnvVars) 371 pChild->environment = papszEnvVars = target_environment(pChild->file); 372 } 373 351 374 #if defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN) 352 if (pEntry->fMpSafe) 353 { 354 rc = MkWinChildCreateBuiltIn(pEntry, argc, argv, pEntry->fNeedEnv ? pChild->environment : NULL, 355 pChild, pPidSpawned); 375 /* 376 * If the built-in is multi thread safe, we will run it on a job slot thread. 377 */ 378 if (pEntry->fMtSafe) 379 { 380 rc = MkWinChildCreateBuiltIn(pEntry, argc, argv, papszEnvVars, pChild, pPidSpawned); 356 381 # ifdef CONFIG_WITH_KMK_BUILTIN_STATS 357 382 g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cAsyncTimes++; … … 361 386 #endif 362 387 { 363 char **envp = pChild->environment ? pChild->environment : environ;364 365 388 /* 366 389 * Call the worker function, making sure to preserve umask. 367 390 */ 368 391 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS 369 big_int nsStart = nano_timestamp();392 big_int nsStart = print_stats_flag ? nano_timestamp() : 0; 370 393 #endif 371 394 int const iUmask = umask(0); /* save umask */ … … 373 396 374 397 if (pEntry->uFnSignature == FN_SIG_MAIN) 375 rc = pEntry->u.pfnMain(argc, argv, envp);398 rc = pEntry->u.pfnMain(argc, argv, papszEnvVars); 376 399 else if (pEntry->uFnSignature == FN_SIG_MAIN_SPAWNS) 377 rc = pEntry->u.pfnMainSpawns(argc, argv, envp, pChild, pPidSpawned);400 rc = pEntry->u.pfnMainSpawns(argc, argv, papszEnvVars, pChild, pPidSpawned); 378 401 else if (pEntry->uFnSignature == FN_SIG_MAIN_TO_SPAWN) 379 402 { … … 383 406 * problem then (the call stack shows what's been going on). 384 407 */ 385 rc = pEntry->u.pfnMainToSpawn(argc, argv, envp, ppapszArgvToSpawn);408 rc = pEntry->u.pfnMainToSpawn(argc, argv, papszEnvVars, ppapszArgvToSpawn); 386 409 if ( !rc 387 410 && *ppapszArgvToSpawn … … 410 433 411 434 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS 412 g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cTimes++; 413 g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cNs += nano_timestamp() - nsStart; 435 if (print_stats_flag) 436 { 437 uintptr_t iEntry = pEntry - &g_aBuiltIns[0]; 438 g_aBuiltInStats[iEntry].cTimes++; 439 g_aBuiltInStats[iEntry].cNs += nano_timestamp() - nsStart; 440 } 414 441 #endif 415 442 } … … 442 469 extern void kmk_builtin_print_stats(FILE *pOutput, const char *pszPrefix) 443 470 { 444 const unsigned 471 const unsigned cEntries = sizeof(g_aBuiltInStats) / sizeof(g_aBuiltInStats[0]); 445 472 unsigned i; 473 assert(print_stats_flag); 446 474 fprintf(pOutput, "\n%skmk built-in command statistics:\n", pszPrefix); 447 475 for (i = 0; i < cEntries; i++) -
trunk/src/kmk/kmkbuiltin.h
r3172 r3173 88 88 } u; 89 89 size_t uFnSignature : 8; 90 size_t fM pSafe : 1;91 size_t fNeedEnv : 1; 90 size_t fMtSafe : 1; /**< Safe for multi threaded execution. */ 91 size_t fNeedEnv : 1; /**< Needs the (target) enviornment. */ 92 92 } KMKBUILTINENTRY; 93 93 /** Pointer to kmk built-in command entry. */ … … 138 138 extern int kBuiltinOptEnvPrepend(char ***ppapszEnv, unsigned *pcEnvVars, unsigned *pcAllocatedEnvVars, 139 139 int cVerbosity, const char *pszValue); 140 extern int kBuiltinOptEnvUnset(char **papszEnv, unsigned *pcEnvVars, int cVerbosity, const char *pszVarToRemove); 140 extern int kBuiltinOptEnvUnset(char ***ppapszEnv, unsigned *pcEnvVars, unsigned *pcAllocatedEnvVars, int cVerbosity, const char *pszVarToRemove); 141 extern int kBuiltinOptEnvZap(char ***ppapszEnv, unsigned *pcEnvVars, unsigned *pcAllocatedEnvVars, int cVerbosity); 142 extern void kBuiltinOptEnvCleanup(char ***ppapszEnv, unsigned cEnvVars, unsigned *pcAllocatedEnvVars); 141 143 extern int kBuiltinOptChDir(char *pszCwd, size_t cbCwdBuf, const char *pszValue); 142 144 -
trunk/src/kmk/kmkbuiltin/common-env-and-cwd-opt.c
r3133 r3173 31 31 #include <stdlib.h> 32 32 #include <string.h> 33 #include <assert.h> 33 34 34 35 #include "kmkbuiltin.h" … … 43 44 # define KSUBMIT_ENV_NCMP strncmp 44 45 #endif 46 47 48 /** 49 * Duplicates a read-only enviornment vector. 50 * 51 * @returns The duplicate enviornment. 52 * @param papszEnv The read-only vector. 53 * @param cEnvVars The number of variables. 54 * @param pcAllocatedEnvVars The allocated papszEnv size. This is zero on 55 * input and non-zero on successful return. 56 * @param cVerbosity The verbosity level. 57 */ 58 static char **kBuiltinOptEnvDuplicate(char **papszEnv, unsigned cEnvVars, unsigned *pcAllocatedEnvVars, int cVerbosity) 59 { 60 unsigned cAllocatedEnvVars = (cEnvVars + 2 + 0xf) * ~(unsigned)0xf; 61 char **papszEnvNew = malloc(cAllocatedEnvVars * sizeof(papszEnvNew[0])); 62 assert(*pcAllocatedEnvVars == 0); 63 if (papszEnvNew) 64 { 65 unsigned i; 66 for (i = 0; i < cEnvVars; i++) 67 { 68 papszEnvNew[i] = strdup(papszEnv[i]); 69 if (!papszEnvNew) 70 { 71 while (i-- > 0) 72 free(papszEnvNew[i]); 73 free(papszEnvNew); 74 errx(1, "out of memory"); 75 return NULL; 76 } 77 } 78 papszEnvNew[i] = NULL; 79 *pcAllocatedEnvVars = cAllocatedEnvVars; 80 } 81 else 82 errx(1, "out of memory"); 83 return papszEnvNew; 84 } 45 85 46 86 … … 136 176 unsigned cEnvVars = *pcEnvVars; 137 177 size_t const cchVar = pszEqual - pszValue; 178 179 if (!*pcAllocatedEnvVars) 180 { 181 papszEnv = kBuiltinOptEnvDuplicate(papszEnv, cEnvVars, pcAllocatedEnvVars, cVerbosity); 182 if (!papszEnv) 183 return errx(1, "out of memory!"); 184 *ppapszEnv = papszEnv; 185 } 186 138 187 for (iEnvVar = 0; iEnvVar < cEnvVars; iEnvVar++) 139 188 { … … 180 229 unsigned cEnvVars = *pcEnvVars; 181 230 size_t const cchVar = pszEqual - pszValue; 231 232 if (!*pcAllocatedEnvVars) 233 { 234 papszEnv = kBuiltinOptEnvDuplicate(papszEnv, cEnvVars, pcAllocatedEnvVars, cVerbosity); 235 if (!papszEnv) 236 return errx(1, "out of memory!"); 237 *ppapszEnv = papszEnv; 238 } 239 182 240 for (iEnvVar = 0; iEnvVar < cEnvVars; iEnvVar++) 183 241 { … … 257 315 * 258 316 * @returns 0 on success, non-zero exit code on error. 259 * @param papszEnv The environment vector. 260 * @param pcEnvVars Pointer to the variable holding the number of 261 * environment variables held by @a papszEnv. 317 * @param ppapszEnv The environment vector pointer. 318 * @param pcEnvVars Pointer to the variable holding the number of 319 * environment variables held by @a papszEnv. 320 * @param pcAllocatedEnvVars Pointer to the size of the vector allocation. 321 * The size is zero when read-only (CRT, GNU make) 322 * environment. 262 323 * @param cVerbosity The verbosity level. 263 324 * @param pszVarToRemove The name of the variable to remove. 264 325 */ 265 int kBuiltinOptEnvUnset(char ** papszEnv, unsigned *pcEnvVars, int cVerbosity, const char *pszVarToRemove)326 int kBuiltinOptEnvUnset(char ***ppapszEnv, unsigned *pcEnvVars, unsigned *pcAllocatedEnvVars, int cVerbosity, const char *pszVarToRemove) 266 327 { 267 328 if (strchr(pszVarToRemove, '=') == NULL) 268 329 { 330 char **papszEnv = *ppapszEnv; 269 331 unsigned cRemoved = 0; 270 332 size_t const cchVar = strlen(pszVarToRemove); … … 278 340 if (cVerbosity > 0) 279 341 warnx(!cRemoved ? "removing '%s'" : "removing duplicate '%s'", papszEnv[iEnvVar]); 342 343 if (!*pcAllocatedEnvVars) 344 { 345 papszEnv = kBuiltinOptEnvDuplicate(papszEnv, cEnvVars, pcAllocatedEnvVars, cVerbosity); 346 if (!papszEnv) 347 return errx(1, "out of memory!"); 348 *ppapszEnv = papszEnv; 349 } 350 280 351 free(papszEnv[iEnvVar]); 281 352 cEnvVars--; … … 296 367 } 297 368 369 370 /** 371 * Handles the --zap-env & --ignore-environment options. 372 * 373 * @returns 0 on success, non-zero exit code on error. 374 * @param ppapszEnv The environment vector pointer. 375 * @param pcEnvVars Pointer to the variable holding the number of 376 * environment variables held by @a papszEnv. 377 * @param pcAllocatedEnvVars Pointer to the size of the vector allocation. 378 * The size is zero when read-only (CRT, GNU make) 379 * environment. 380 * @param cVerbosity The verbosity level. 381 */ 382 int kBuiltinOptEnvZap(char ***ppapszEnv, unsigned *pcEnvVars, unsigned *pcAllocatedEnvVars, int cVerbosity) 383 { 384 if (*pcAllocatedEnvVars > 0) 385 { 386 char **papszEnv = *ppapszEnv; 387 unsigned i = *pcEnvVars; 388 while (i-- > 0) 389 { 390 free(papszEnv[i]); 391 papszEnv[i] = NULL; 392 } 393 } 394 else 395 { 396 char **papszEnv = calloc(4, sizeof(char *)); 397 if (!papszEnv) 398 return err(1, "out of memory!"); 399 *ppapszEnv = papszEnv; 400 *pcAllocatedEnvVars = 4; 401 } 402 *pcEnvVars = 0; 403 return 0; 404 } 405 406 407 /** 408 * Cleans up afterwards, if necessary. 409 * 410 * @param ppapszEnv The environment vector pointer. 411 * @param cEnvVars The number of variables in the vector. 412 * @param pcAllocatedEnvVars Pointer to the size of the vector allocation. 413 * The size is zero when read-only (CRT, GNU make) 414 * environment. 415 */ 416 void kBuiltinOptEnvCleanup(char ***ppapszEnv, unsigned cEnvVars, unsigned *pcAllocatedEnvVars) 417 { 418 char **papszEnv = *ppapszEnv; 419 *ppapszEnv = NULL; 420 if (*pcAllocatedEnvVars > 0) 421 { 422 *pcAllocatedEnvVars = 0; 423 while (cEnvVars-- > 0) 424 { 425 free(papszEnv[cEnvVars]); 426 papszEnv[cEnvVars] = NULL; 427 } 428 free(papszEnv); 429 } 430 } 298 431 299 432 -
trunk/src/kmk/kmkbuiltin/kSubmit.c
r3156 r3173 1250 1250 int iArg; 1251 1251 unsigned cAllocatedEnvVars; 1252 unsigned iEnvVar;1253 1252 unsigned cEnvVars; 1254 char **papszEnv = NULL;1253 char **papszEnvVars; 1255 1254 const char *pszExecutable = NULL; 1256 1255 int iPostCmd = argc; … … 1267 1266 /* 1268 1267 * Create default program environment. 1268 * 1269 * Note! We only clean up the environment on successful return, assuming 1270 * make will stop after that. 1269 1271 */ 1270 1272 if (getcwd_fs(szCwd, cbCwdBuf) != NULL) … … 1273 1275 return err(1, "getcwd_fs failed\n"); 1274 1276 1275 papszEnv = pChild->environment;1276 if (!papszEnv)1277 pChild->environment = papszEnv = target_environment(pChild->file);1277 /* The environment starts out in read-only mode and will be duplicated if modified. */ 1278 cAllocatedEnvVars = 0; 1279 papszEnvVars = envp; 1278 1280 cEnvVars = 0; 1279 while (papszEnv [cEnvVars] != NULL)1281 while (papszEnvVars[cEnvVars] != NULL) 1280 1282 cEnvVars++; 1281 cAllocatedEnvVars = cEnvVars;1282 1283 1283 1284 /* … … 1387 1388 case 'Z': 1388 1389 case 'i': /* GNU env compatibility. */ 1389 for (iEnvVar = 0; iEnvVar < cEnvVars; iEnvVar++) 1390 free(papszEnv[iEnvVar]); 1391 papszEnv[0] = NULL; 1392 cEnvVars = 0; 1393 break; 1394 1395 case 'E': 1396 rcExit = kBuiltinOptEnvSet(&papszEnv, &cEnvVars, &cAllocatedEnvVars, cVerbosity, pszValue); 1397 pChild->environment = papszEnv; 1390 rcExit = kBuiltinOptEnvZap(&papszEnvVars, &cEnvVars, &cAllocatedEnvVars, cVerbosity); 1398 1391 if (rcExit == 0) 1399 1392 break; 1400 1393 return rcExit; 1401 1394 1402 case 'A': 1403 rcExit = kBuiltinOptEnvAppend(&papszEnv, &cEnvVars, &cAllocatedEnvVars, cVerbosity, pszValue); 1404 pChild->environment = papszEnv; 1395 case 'E': 1396 rcExit = kBuiltinOptEnvSet(&papszEnvVars, &cEnvVars, &cAllocatedEnvVars, cVerbosity, pszValue); 1405 1397 if (rcExit == 0) 1406 1398 break; 1407 1399 return rcExit; 1408 1400 1409 case 'D': 1410 rcExit = kBuiltinOptEnvPrepend(&papszEnv, &cEnvVars, &cAllocatedEnvVars, cVerbosity, pszValue); 1411 pChild->environment = papszEnv; 1401 case 'A': 1402 rcExit = kBuiltinOptEnvAppend(&papszEnvVars, &cEnvVars, &cAllocatedEnvVars, cVerbosity, pszValue); 1412 1403 if (rcExit == 0) 1413 1404 break; 1414 1405 return rcExit; 1415 1406 1407 case 'D': 1408 rcExit = kBuiltinOptEnvPrepend(&papszEnvVars, &cEnvVars, &cAllocatedEnvVars, cVerbosity, pszValue); 1409 if (rcExit == 0) 1410 break; 1411 return rcExit; 1412 1416 1413 case 'U': 1417 rcExit = kBuiltinOptEnvUnset( papszEnv, &cEnvVars, cVerbosity, pszValue);1414 rcExit = kBuiltinOptEnvUnset(&papszEnvVars, &cEnvVars, &cAllocatedEnvVars, cVerbosity, pszValue); 1418 1415 if (rcExit == 0) 1419 1416 break; … … 1458 1455 case 'h': 1459 1456 usage(stdout, argv[0]); 1457 kBuiltinOptEnvCleanup(&papszEnvVars, cEnvVars, &cAllocatedEnvVars); 1460 1458 return 0; 1461 1459 1462 1460 case 'V': 1461 kBuiltinOptEnvCleanup(&papszEnvVars, cEnvVars, &cAllocatedEnvVars); 1463 1462 return kbuild_version(argv[0]); 1464 1463 } … … 1478 1477 { 1479 1478 uint32_t cbMsg; 1480 void *pvMsg = kSubmitComposeJobMessage(pszExecutable, &argv[iArg], papszEnv , szCwd,1479 void *pvMsg = kSubmitComposeJobMessage(pszExecutable, &argv[iArg], papszEnvVars, szCwd, 1481 1480 fWatcomBrainDamage, fNoPchCaching, 1482 1481 &argv[iPostCmd], cPostCmdArgs, &cbMsg); … … 1505 1504 } 1506 1505 1506 kBuiltinOptEnvCleanup(&papszEnvVars, cEnvVars, &cAllocatedEnvVars); 1507 1507 return rcExit; 1508 1508 } -
trunk/src/kmk/kmkbuiltin/redirect.c
r3164 r3173 74 74 #include "kmkbuiltin.h" 75 75 #ifdef KMK 76 # include "job.h"77 # include "variable.h"78 76 # ifdef KBUILD_OS_WINDOWS 79 77 # ifndef CONFIG_NEW_WIN_CHILDREN … … 1161 1159 /* Windows is slightly complicated due to handles and winchildren.c. */ 1162 1160 HANDLE hProcess = INVALID_HANDLE_VALUE; 1163 rcExit = kRedirectCreateProcessWindows(pszExecutable, cArgs, papszArgs, papszEnvVars, pszCwd,1164 cOrders, paOrders, &hProcess);1161 rcExit = kRedirectCreateProcessWindows(pszExecutable, cArgs, papszArgs, papszEnvVars, 1162 pszSavedCwd ? pszCwd : NULL, cOrders, paOrders, &hProcess); 1165 1163 if (rcExit == 0) 1166 1164 { … … 1168 1166 if (process_kmk_register_redirect(hProcess, pPidSpawned) == 0) 1169 1167 # else 1170 if (MkWinChildCreateRedirect((intptr_t)hProcess, pPidSpawned) == 0) 1168 if ( pPidSpawned 1169 && MkWinChildCreateRedirect((intptr_t)hProcess, pPidSpawned) == 0) 1171 1170 # endif 1172 1171 { … … 1180 1179 warn("sub_proc is out of slots, waiting for child..."); 1181 1180 # else 1182 warn("MkWinChildCreateRedirect failed..."); 1181 if (pPidSpawned) 1182 warn("MkWinChildCreateRedirect failed..."); 1183 1183 # endif 1184 1184 dwTmp = WaitForSingleObject(hProcess, INFINITE); … … 1196 1196 1197 1197 CloseHandle(hProcess); 1198 *pPidSpawned = 0; 1198 if (pPidSpawned) 1199 *pPidSpawned = 0; 1199 1200 *pfIsChildExitCode = K_TRUE; 1200 1201 } … … 1234 1235 # ifdef KBUILD_OS_WINDOWS 1235 1236 HANDLE hProcess = INVALID_HANDLE_VALUE; 1236 rcExit = kRedirectCreateProcessWindows(pszExecutable, cArgs, papszArgs, papszEnvVars, pszCwd,1237 cOrders, paOrders, &hProcess);1237 rcExit = kRedirectCreateProcessWindows(pszExecutable, cArgs, papszArgs, papszEnvVars, 1238 pszSavedCwd ? pszCwd : NULL, cOrders, paOrders, &hProcess); 1238 1239 if (rcExit == 0) 1239 1240 { … … 1348 1349 char **papszEnvVars = NULL; 1349 1350 unsigned cAllocatedEnvVars; 1350 unsigned iEnvVar;1351 1351 unsigned cEnvVars; 1352 1352 int fWatcomBrainDamage = 0; … … 1378 1378 return err(9, "getcwd failed"); 1379 1379 1380 #if defined(KMK) 1381 /* We get it from kmk and just count it: */ 1382 papszEnvVars = pChild->environment; 1383 if (!papszEnvVars) 1384 pChild->environment = papszEnvVars = target_environment(pChild->file); 1380 /* We start out with a read-only enviornment from kmk or the crt, and will 1381 duplicate it if we make changes to it. */ 1382 cAllocatedEnvVars = 0; 1383 papszEnvVars = envp; 1385 1384 cEnvVars = 0; 1386 1385 while (papszEnvVars[cEnvVars] != NULL) 1387 1386 cEnvVars++; 1388 cAllocatedEnvVars = cEnvVars;1389 #else1390 /* We make a copy and we manage ourselves: */1391 cEnvVars = 0;1392 while (envp[cEnvVars] != NULL)1393 cEnvVars++;1394 1395 cAllocatedEnvVars = cEnvVars + 4;1396 papszEnvVars = malloc((cAllocatedEnvVars + 1) * sizeof(papszEnvVars));1397 if (!papszEnvVars)1398 return errx(9, "out of memory!");1399 1400 iEnvVar = cEnvVars;1401 papszEnvVars[iEnvVar] = NULL;1402 while (iEnvVar-- > 0)1403 {1404 papszEnvVars[iEnvVar] = strdup(envp[iEnvVar]);1405 if (!papszEnvVars[iEnvVar])1406 {1407 while (iEnvVar-- > 0)1408 free(papszEnvVars[iEnvVar]);1409 free(papszEnvVars);1410 return errx(9, "out of memory!");1411 }1412 }1413 #endif1414 1387 1415 1388 #ifdef USE_POSIX_SPAWN … … 1578 1551 { 1579 1552 if (pchEqual[1] != '\0') 1580 {1581 1553 rcExit = kBuiltinOptEnvSet(&papszEnvVars, &cEnvVars, &cAllocatedEnvVars, cVerbosity, pszValue); 1582 #ifdef KMK1583 pChild->environment = papszEnvVars;1584 #endif1585 }1586 1554 else 1587 1555 { … … 1590 1558 { 1591 1559 pszCopy[pchEqual - pszValue] = '\0'; 1592 rcExit = kBuiltinOptEnvUnset( papszEnvVars, &cEnvVars, cVerbosity, pszCopy);1560 rcExit = kBuiltinOptEnvUnset(&papszEnvVars, &cEnvVars, &cAllocatedEnvVars, cVerbosity, pszCopy); 1593 1561 free(pszCopy); 1594 1562 } … … 1633 1601 else 1634 1602 #endif 1635 rcExit = kBuiltinOptEnvUnset( papszEnvVars, &cEnvVars, cVerbosity, pszValue);1603 rcExit = kBuiltinOptEnvUnset(&papszEnvVars, &cEnvVars, &cAllocatedEnvVars, cVerbosity, pszValue); 1636 1604 continue; 1637 1605 } … … 1643 1611 || chOpt == 'i' /* GNU env compatibility. */ ) 1644 1612 { 1645 for (iEnvVar = 0; iEnvVar < cEnvVars; iEnvVar++) 1646 free(papszEnvVars[iEnvVar]); 1647 papszEnvVars[0] = NULL; 1648 cEnvVars = 0; 1613 rcExit = kBuiltinOptEnvZap(&papszEnvVars, &cEnvVars, &cAllocatedEnvVars, cVerbosity); 1649 1614 continue; 1650 1615 } … … 1998 1963 * Cleanup. 1999 1964 */ 1965 kBuiltinOptEnvCleanup(&papszEnvVars, cEnvVars, &cAllocatedEnvVars); 2000 1966 if (pszSavedCwd) 2001 1967 free(pszSavedCwd); … … 2004 1970 posix_spawn_file_actions_destroy(&FileActions); 2005 1971 #endif 2006 #ifndef KMK2007 iEnvVar = cEnvVars;2008 while (iEnvVar-- > 0)2009 free(papszEnvVars[iEnvVar]);2010 free(papszEnvVars);2011 #endif2012 1972 #ifdef KBUILD_OS_OS2 2013 1973 for (ulLibPath = 0; ulLibPath < K_ELEMENTS(apszSavedLibPaths); ulLibPath++) -
trunk/src/kmk/misc.c
r3170 r3173 1072 1072 printf (_("\n# CRT Heap: %u bytes in use, in %u blocks, avg %u bytes/block\n"), 1073 1073 (unsigned)s.size_in_use, (unsigned)s.blocks_in_use, 1074 (unsigned)(s.size_in_use / s.blocks_in_use));1074 s.blocks_in_use ? (unsigned)(s.size_in_use / s.blocks_in_use : 0)); 1075 1075 printf (_("# %u bytes max in use (high water mark)\n"), 1076 1076 (unsigned)s.max_size_in_use); … … 1104 1104 1105 1105 printf (_("\n# CRT Heap: %u bytes in use, in %u blocks, avg %u bytes/block\n"), 1106 bytes_used, blocks_used, b ytes_used / blocks_used);1106 bytes_used, blocks_used, blocks_used ? bytes_used / blocks_used : 0); 1107 1107 printf (_("# %u bytes avail, in %u blocks, avg %u bytes/block\n"), 1108 bytes_avail, blocks_avail, b ytes_avail / blocks_avail);1108 bytes_avail, blocks_avail, blocks_avail ? bytes_avail / blocks_avail : 0); 1109 1109 # endif /* _MSC_VER */ 1110 1110 -
trunk/src/kmk/w32/w32os.c
r3156 r3173 187 187 /* Build array of handles to wait for. */ 188 188 dwHandleCount = 1 + process_set_handles (&handles[1]); 189 #else190 /* Add the completed children event as the 2nd one. */191 handles[1] = (HANDLE)MkWinChildGetCompleteEventHandle();192 dwHandleCount = 2;193 #endif194 195 189 dwEvent = WaitForMultipleObjects ( 196 190 dwHandleCount, /* number of objects in array */ … … 198 192 FALSE, /* wait for any object */ 199 193 INFINITE); /* wait until object is signalled */ 194 #else 195 /* Add the completed children event as the 2nd one. */ 196 handles[1] = (HANDLE)MkWinChildGetCompleteEventHandle(); 197 if (handles[1] == NULL) 198 return 0; 199 dwHandleCount = 2; 200 dwEvent = WaitForMultipleObjectsEx (dwHandleCount, 201 handles, 202 FALSE /*bWaitAll*/, 203 256, /* INFINITE - paranoia, only wait 256 ms before checking again. */ 204 TRUE /*bAlertable*/); 205 #endif 200 206 201 207 if (dwEvent == WAIT_FAILED) -
trunk/src/kmk/w32/winchildren.c
r3172 r3173 2536 2536 * that completed children is the typical source of these tokens (esp. for kmk). 2537 2537 * 2538 * @returns Event handle.2538 * @returns Zero if completed children, event handle if waiting is required. 2539 2539 */ 2540 2540 intptr_t MkWinChildGetCompleteEventHandle(void) 2541 2541 { 2542 return (intptr_t)g_hEvtWaitChildren; 2542 /* We don't return the handle if we've got completed children. This 2543 is a safe guard against being called twice in a row without any 2544 MkWinChildWait call inbetween. */ 2545 if (!g_pTailCompletedChildren) 2546 return (intptr_t)g_hEvtWaitChildren; 2547 return 0; 2543 2548 } 2544 2549
Note:
See TracChangeset
for help on using the changeset viewer.