[Pntool-developers] SF.net SVN: pntool:[214] third-party/memwatch-2.71
Brought to you by:
compaqdrew,
miordache
From: <Ste...@us...> - 2009-08-14 06:57:08
|
Revision: 214 http://pntool.svn.sourceforge.net/pntool/?rev=214&view=rev Author: StephenCamp Date: 2009-08-14 06:56:54 +0000 (Fri, 14 Aug 2009) Log Message: ----------- Added the third-party memory debugging routines memwatch to the third-party directory, the test makefiles, the spnbox readme on testing, and the pntool license file. Debugged miscellaneous spnbox files. Dp now appears to pass all tests. Note: Dp output has not yet been unified: some functions display 0-based indices and some display 1-based indices. Note: Dp has not yet had the pn2acpn calls used for testing replaced with the pn2eacpn calls intended for use in the final version. Modified Paths: -------------- LICENSE.txt spnbox/README.txt spnbox/admcon.c spnbox/asiph.c spnbox/dp.c spnbox/pn2acpn.c spnbox/spnbox.h spnbox/tests/Makefile spnbox/tests/test-dp.c spnbox/tests/test-dp.txt Added Paths: ----------- third-party/memwatch-2.71/ third-party/memwatch-2.71/FAQ third-party/memwatch-2.71/Makefile third-party/memwatch-2.71/README third-party/memwatch-2.71/USING third-party/memwatch-2.71/gpl.txt third-party/memwatch-2.71/memwatch.c third-party/memwatch-2.71/memwatch.h third-party/memwatch-2.71/memwatch.lsm third-party/memwatch-2.71/test.c Modified: LICENSE.txt =================================================================== --- LICENSE.txt 2009-08-07 06:29:10 UTC (rev 213) +++ LICENSE.txt 2009-08-14 06:56:54 UTC (rev 214) @@ -1,4 +1,5 @@ MILP solver released under the LGPL. (C) Respective authors. +MEMWATCH released under the GPL. (C) Respective authors. ANTLR released under the BSD License. (C) Respective authors. ACTS Copyright (c) 2009 LeTourneau University and University of Notre Dame Modified: spnbox/README.txt =================================================================== --- spnbox/README.txt 2009-08-07 06:29:10 UTC (rev 213) +++ spnbox/README.txt 2009-08-14 06:56:54 UTC (rev 214) @@ -13,7 +13,7 @@ This will generate an executable called <functionname>.exe. make all will generate test executables for all spnbox functions. To test the various functions in the matrixmath.c file, use make matrixmath. To test the functions in the extendedmatrix.c file, use make extendedmatrix. - +The test makefile includes in each source file it compiles the header files and definitions needed to use the memory debugging routines in the memwatch third-party library. (see pntool/third-party/memwatch-2.71). It also compiles and links the file memwatch.c from the library in all test executables. For all with such test programs except that ipslv, the test program is implemented as a program that will read from an input stream containing text in a human-readable format, interpret the text as parameters to the function, make a function call, and display the results. For format specifications, see the comments in StructuredIO.c/h. The programs may be invoked with a single command line argument, which will be taken as the name of a text file from which to read the input. If no command line argument is used the test programs will take input from the console. Modified: spnbox/admcon.c =================================================================== --- spnbox/admcon.c 2009-08-07 06:29:10 UTC (rev 213) +++ spnbox/admcon.c 2009-08-14 06:56:54 UTC (rev 214) @@ -219,7 +219,7 @@ /*During our iterations we will modify a flag array, cov, with an element for each of the columns that came from DX. Allocate space.*/ - int *cov = mcalloc(&mem, placeCount, sizeof(short)); + int *cov = mcalloc(&mem, placeCount, sizeof(int)); /*Start the iterations. Store in j the index of the last column of L such that its element in the last row was set to 1 within the loop. -1 means no column @@ -325,7 +325,7 @@ AllocateMatrixType(2, &DX, p->TucCount + p->TuoCount + p->TuoCount + p->ntCount + 1, NumberOfRows(*Z)); int i, j, k; - for (i = 0; i < NumberOfRows(DX); i++) + for (i = 0; i < NumberOfColumns(DX); i++) { /*Fill in Auc.*/ for (j = 0; j < p->TucCount; j++) Modified: spnbox/asiph.c =================================================================== --- spnbox/asiph.c 2009-08-07 06:29:10 UTC (rev 213) +++ spnbox/asiph.c 2009-08-14 06:56:54 UTC (rev 214) @@ -537,8 +537,8 @@ /*We are going to iterate through the columns of sx. Each column is an active siphon. For each siphon, we determine if there are any transitions such that they have at least one input arc to a place in the siphon but no output arcs - from any places in the siphon. If there are, we modify NS (in result). If not, - we modify MNS (in result) and newIndex.*/ + from any places in the siphon. If there are, we modify NS. If not, we modify + MNS and newIndex.*/ int siphon, place, transition, iFlag, oFlag; for (siphon = 0; siphon < NumberOfColumns(*sx); siphon++) { @@ -578,7 +578,7 @@ int *removeMNSRow = tcalloc(NumberOfRows(data->MNS), sizeof(int)); int removeCount = 0; /*Iterate through each row of MNS*/ - int i, j, flag = 1; + int i, j, k, flag = 1; for (i = 0; i < NumberOfRows(data->MNS); i++) { /*Take the difference MNS - vector. Fill sumDeltas with the sum of the @@ -622,16 +622,20 @@ int* newIndex = tcalloc(NumberOfRows(data->MNS) - removeCount + flag, sizeof(int)); /*Fill in the new index and remove rows from MNS.*/ - j = 0; - for (i = 0; i < NumberOfRows(data->MNS); i++) + j = NumberOfRows(data->MNS) - removeCount; + /*if (! mwIsSafeAddr(index, NumberOfRows(data->MNS) * sizeof(int))) { + merror(0, "BAD MEMORY!"); + }*/ + for (i = NumberOfRows(data->MNS) - 1; i >= 0; i--) + { if (removeMNSRow[i]) { RemoveRows(&data->MNS, i, 1, -1); } else { - newIndex[j++] = index[i]; + newIndex[--j] = index[i]; } } /*Fill in the last element of index and the last row of MNS if necessary.*/ Modified: spnbox/dp.c =================================================================== --- spnbox/dp.c 2009-08-07 06:29:10 UTC (rev 213) +++ spnbox/dp.c 2009-08-14 06:56:54 UTC (rev 214) @@ -69,6 +69,7 @@ int uci, upd, consis; //flags matrix TSIPH; //All siphons found during a run. matrix S; //New siphons found during a run. + int ID; } dpData; /*A set of marking constraints. The return type of UpdateMarkingConstraints, @@ -110,7 +111,7 @@ static void FinalPrint(dpData* d); static void FreeDpParts(dpData* d); -dp_r dp(dp_p* params) +dp_r dp(dp_p* params, int ID) { dp_r result; int i, j, flag; @@ -123,7 +124,7 @@ /*Initialize the data structure.*/ dpData d = CreateDpData(params); - + d.ID = ID; /*Initial message printing.*/ if (is_verbose() >= VRB_DP) { @@ -133,7 +134,7 @@ printf("Producing a deadlock prevention supervisor...\n"); break; case 1: - printf("Produceing a liveness enforcing supervisor...\n"); + printf("Producing a liveness enforcing supervisor...\n"); break; case 2: printf("Producing a T-liveness enforcing supervisor...\n"); @@ -745,7 +746,14 @@ /*Check the constraints if applicable.*/ if (d->consis) { - chkconsRes = chkcons(&cons.L, cons.B, &l, b); + /*We are checking constraints for consistency, not redundancy - add + the proposed new constraint to the set of constraints. Use a copy + so that the memory can be absorbed into L in an optimized operation.*/ + AddToArray(&cons.B, NumberOfRows(cons.L), b); + AllocateMatrixType(2, &l2, 1, NumberOfColumns(l)); + CopyMatrix(&l, &l2); + InsertRows(&cons.L, &l2, -1, -1); + chkconsRes = chkcons(&cons.L, cons.B, 0, 0); } else { @@ -758,9 +766,9 @@ x = 0; for (i = 0; i < NumberOfRows(d->S); i++) { - if ((! GetMatrixEl(&d->S, i, siphon)) != (! GetMatrixEl(&a, i, 0))) + if ((! GetMatrixEl(&d->S, i, siphon)) != (! GetMatrixEl(&a, 0, i))) { - /*If such a place is encounted, set the generic variable x to 2 for + /*If such a place is encountered, set the generic variable x to 2 for later use as a function parameter.*/ x = 2; break; @@ -785,7 +793,7 @@ AddToIndexArray(&d->upl, &d->upCount, NumberOfRows(supervisRes.Dfm) - 1); AddToIndexArray(&d->cpl, &d->cpCount, NumberOfRows(supervisRes.Dfm) - 1); /*Dm and Dp should be set to the supervised net Dfm and Dfp.*/ - UpdateDPData(d, "Dm Dp", &supervisRes); + UpdateDPData(d, "Dm Dp", &supervisRes); memset(&supervisRes, 0, sizeof(supervis_r)); /*Add to the constraints. Make a copy of l first so that we can do optimized row-adds and not do too many allocations.*/ @@ -807,7 +815,7 @@ { /*Add the built constraint to the initial marking constraints.*/ if (d->log) PrintConstraints(d, &l, b, currentSiphon, 0, x); - AddToArray(&d->B0, NumberOfRows(d->L0), NumberOfRows(d->L0)); + AddToArray(&d->B0, NumberOfRows(d->L0), b); InsertRows(&d->L0, &l, -1, -1); } } @@ -843,7 +851,12 @@ else { if (d->log) PrintConstraints(d, 0, 0, currentSiphon, -1, 0); - } + } + if (NumberOfRows(cons.L)) + { + DeallocateMatrix(&cons.L); + free(cons.B); + } } } @@ -1229,10 +1242,10 @@ { if (GetMatrixEl(&d->Dcm, i, j) || GetMatrixEl(&d->Dcp, i, j)) { + newApl[d->apCount++] = i; break; } } - if (j != NumberOfColumns(d->Dcm)) newApl[d->apCount++] = i; } free(d->apl); d->apl = newApl; @@ -1489,7 +1502,7 @@ int firstNewInd = -1, firstNewDep = -1; for (i = 0; i < d->ipCount; i++) { - if (d->ipl[i] > d->targetRows) + if (d->ipl[i] >= d->targetRows) { firstNewInd = i; break; @@ -1497,7 +1510,7 @@ } for (i = 0; i < d->dpCount; i++) { - if (d->dpl[i] > d->targetRows) + if (d->dpl[i] >= d->targetRows) { firstNewDep = i; break; @@ -1663,7 +1676,7 @@ is too high and marking this as the list length.*/ for (i = 0; i < d->ExcludeCount; i++) { - if (d->ExcludeT[i] > d->targetCols) break; + if (d->ExcludeT[i] >= d->targetCols) break; } d->ExcludeCount = i; d->state.perm = 1; @@ -1926,7 +1939,10 @@ else if (! strcmp(token, "Dcm")) destMatrix = &data->Dcm; else if (! strcmp(token, "Dcp")) destMatrix = &data->Dcp; else if (! strcmp(token, "L")) destMatrix = &data->L; - else if (! strcmp(token, "L0")) destMatrix = &data->L0; + else if (! strcmp(token, "L0")) + { + destMatrix = &data->L0; + } else if (! strcmp(token, "M")) destMatrix = &data->M; else if (! strcmp(token, "TSIPH")) destMatrix = &data->TSIPH; else if (! strcmp(token, "S")) destMatrix = &data->S; Modified: spnbox/pn2acpn.c =================================================================== --- spnbox/pn2acpn.c 2009-08-07 06:29:10 UTC (rev 213) +++ spnbox/pn2acpn.c 2009-08-14 06:56:54 UTC (rev 214) @@ -161,8 +161,8 @@ /*We will be adding new columns to MX and L0. Reseve space and copy existing columns.*/ - if (NumberOfRows(result->MXF)) - { + if (result->MXF.type) + { AllocateMatrixType(2, &MX, NumberOfRows(result->MXF), NumberOfColumns(result->MXF) + ToAdd); CopyBlock(NumberOfRows(result->MXF), NumberOfColumns(result->MXF), &result->MXF, 0, 0, &MX, 0, 0); } @@ -171,7 +171,7 @@ /*Zero MX.*/ AllocateMatrix(&MX, 0, 0); } - if (NumberOfRows(result->L0F)) + if (result->L0F.type) { AllocateMatrixType(2, &L0, NumberOfRows(result->L0F), NumberOfColumns(result->L0F) + ToAdd); CopyBlock(NumberOfRows(result->L0F), NumberOfColumns(result->L0F), &result->L0F, 0, 0, &L0, 0, 0); @@ -208,7 +208,7 @@ interest.*/ SetMatrixEl(&Dmf, Rows + j, Transition, GetMatrixEl(Dm, i, Transition)); /*Modify MX and L0 if they exist.*/ - if (NumberOfRows(MX) || NumberOfRows(L0)) + if (NumberOfColumns(MX) || NumberOfColumns(L0)) { /*Find out if the current place is independent..*/ for (x = 0; x < ipCount; x++) @@ -223,11 +223,11 @@ place just found. (if they exist)*/ if (x < ipCount) { - if (NumberOfRows(MX)) + if (NumberOfColumns(MX)) { CopyBlock(NumberOfRows(MX), 1, &MX, 0, x, &MX, 0, NumberOfColumns(MX) - ToAdd + j); } - if (NumberOfRows(L0)) + if (NumberOfColumns(L0)) { CopyBlock(NumberOfRows(L0), 1, &L0, 0, x, &L0, 0, NumberOfColumns(L0) - ToAdd + j); } @@ -244,7 +244,7 @@ if (x < dpCount && NumberOfRows(MX)) { SetMatrixEl(&MX, x, NumberOfColumns(MX) - ToAdd + j, -1); - } + } } } /*Increment the added-place counter.*/ @@ -255,12 +255,12 @@ result->Dmf = Dmf; DeallocateMatrix(&result->Dpf); result->Dpf = Dpf; - if (NumberOfRows(MX)) + if (NumberOfColumns(MX)) { DeallocateMatrix(&result->MXF); result->MXF = MX; } - if (NumberOfRows(L0)) + if (NumberOfColumns(L0)) { DeallocateMatrix(&result->L0F); result->L0F = L0; @@ -386,7 +386,7 @@ arc. If we exceed the matrix boundaries looking for it, fail.*/ while (! GetMatrixEl(&result->Dmf, ++i, Transition)) { - if (i >= NumberOfRows(result->Dmf)) + if (i == NumberOfRows(result->Dmf) - 1) { merror(0, "PN2ACPN: Internal Error"); /*Set U equal to an error value and return it.*/ @@ -407,7 +407,7 @@ arc. If we exceed the matrix boundaries looking for it, fail.*/ while (! GetMatrixEl(&result->Dmf, ++j, Transition)) { - if (j >= NumberOfRows(result->Dmf)) + if (j == NumberOfRows(result->Dmf) - 1) { merror(0, "PN2ACPN: Internal Error"); /*Set U equal to an error value and return it.*/ Modified: spnbox/spnbox.h =================================================================== --- spnbox/spnbox.h 2009-08-07 06:29:10 UTC (rev 213) +++ spnbox/spnbox.h 2009-08-14 06:56:54 UTC (rev 214) @@ -1023,7 +1023,7 @@ int option; } dp_p; -dp_r dp(dp_p* params); +dp_r dp(dp_p* params, int ID); /* Matlab Usage: Modified: spnbox/tests/Makefile =================================================================== --- spnbox/tests/Makefile 2009-08-07 06:29:10 UTC (rev 213) +++ spnbox/tests/Makefile 2009-08-14 06:56:54 UTC (rev 214) @@ -5,9 +5,9 @@ #<functionname> is the name of an spnbox function. This builds the test routines for that function. COMPILER=gcc -g - +MEMWCOMP=$(COMPILER) -include string.h -include ../../third-party/memwatch-2.71/memwatch.h -DMEMWATCH -DMEMWATCH_STDIO #The dependencies common to all test executables. -COMMON=StructuredIO.o test.o MemoryManager.o general.o pns.o matrix.o matrixmath.o deallocation.o +COMMON=StructuredIO.o test.o MemoryManager.o general.o pns.o matrix.o matrixmath.o deallocation.o memwatch.o #These symbols define the dependencies of various test executables. AVPR=avpr.o @@ -83,109 +83,113 @@ #Rules for making the general object files. actn.o: ../actn.c ../spnbox.h ../../pnheaders/matrix.h ../../pnheaders/pns.h ../matrixmath.h ../MemoryManager.h - $(COMPILER) -c ../actn.c + $(MEMWCOMP) -c ../actn.c admcon.o: ../admcon.c ../spnbox.h ../matrixmath.h ../extendedmatrix.h ../../pnheaders/general.h ../../pnheaders/matrix.h - $(COMPILER) -c ../admcon.c + $(MEMWCOMP) -c ../admcon.c asiph.o: ../asiph.c ../spnbox.h ../../pnheaders/general.h ../../pnheaders/matrix.h ../../pnheaders/pns.h ../extendedmatrix.h ../MemoryManager.h - $(COMPILER) -c ../asiph.c + $(MEMWCOMP) -c ../asiph.c avpr.o: ../avpr.c ../../pnheaders/general.h ../../pnheaders/matrix.h - $(COMPILER) -c ../avpr.c + $(MEMWCOMP) -c ../avpr.c chkcons.o: ../spnbox.h ../../pnheaders/matrix.h ../../pnheaders/pns.h ../chkcons.c - $(COMPILER) -c ../chkcons.c + $(MEMWCOMP) -c ../chkcons.c deallocation.o: ../deallocation.c ../spnbox.h - $(COMPILER) -c ../deallocation.c + $(MEMWCOMP) -c ../deallocation.c dp.o: ../dp.c ../spnbox.h ../matrixmath.h ../extendedmatrix.h ../../pnheaders/general.h ../../pnheaders/matrix.h ../../pnheaders/pns.h - $(COMPILER) -c ../dp.c + $(MEMWCOMP) -c ../dp.c extendedmatrix.o: ../extendedmatrix.c ../extendedmatrix.h ../../pnheaders/matrix.h ../../pnheaders/general.h - $(COMPILER) -c ../extendedmatrix.c + $(MEMWCOMP) -c ../extendedmatrix.c fvpr.o: ../fvpr.c ../../pnheaders/general.h ../../pnheaders/matrix.h - $(COMPILER) -c ../fvpr.c + $(MEMWCOMP) -c ../fvpr.c general.o: ../../pnheaders/general.c ../../pnheaders/general.h - $(COMPILER) -c ../../pnheaders/general.c + $(MEMWCOMP) -c ../../pnheaders/general.c ilpadm.o: ../spnbox.h ../matrixmath.h ../../pnheaders/general.h ../../pnheaders/matrix.h ../MemoryManager.h ../ilpadm.c - $(COMPILER) -c ../ilpadm.c + $(MEMWCOMP) -c ../ilpadm.c isadm.o: ../isadm.c ../spnbox.h ../../pnheaders/general.h ../MemoryManager.h ../../pnheaders/pns.h ../matrixmath.h - $(COMPILER) -c ../isadm.c + $(MEMWCOMP) -c ../isadm.c issiph.o: ../issiph.c ../spnbox.h ../../pnheaders/general.h ../../pnheaders/matrix.h - $(COMPILER) -c ../issiph.c + $(MEMWCOMP) -c ../issiph.c ipslv.o: ../spnbox.h ../ipslv.c - $(COMPILER) -c ../ipslv.c + $(MEMWCOMP) -c ../ipslv.c ipsolve.o: ../spnbox.h ../matrixmath.h ../../pnheaders/general.h ../../pnheaders/matrix.h ../MemoryManager.h ../ipsolve.c - $(COMPILER) -c ../ipsolve.c + $(MEMWCOMP) -c ../ipsolve.c linenf.o: ../spnbox.h ../matrixmath.h ../../pnheaders/general.h ../../pnheaders/matrix.h ../MemoryManager.h ../linenf.c - $(COMPILER) -c ../linenf.c + $(MEMWCOMP) -c ../linenf.c matrix.o: ../../pnheaders/matrix.c ../../pnheaders/matrix.h ../../pnheaders/pns.h - $(COMPILER) -c ../../pnheaders/matrix.c + $(MEMWCOMP) -c ../../pnheaders/matrix.c matrixmath.o: ../matrixmath.c ../matrixmath.h ../../pnheaders/general.h ../../pnheaders/matrix.h - $(COMPILER) -c ../matrixmath.c + $(MEMWCOMP) -c ../matrixmath.c MemoryManager.o: ../MemoryManager.h ../MemoryManager.c ../../pnheaders/general.h ../../pnheaders/matrix.h - $(COMPILER) -c ../MemoryManager.c + $(MEMWCOMP) -c ../MemoryManager.c msplit.o: ../spnbox.h ../../pnheaders/matrix.h ../matrixmath.h ../MemoryManager.h ../msplit.c - $(COMPILER) -c ../msplit.c + $(MEMWCOMP) -c ../msplit.c nltrans.o: ../nltrans.c ../spnbox.h ../../pnheaders/matrix.h ../matrixmath.h ../MemoryManager.h - $(COMPILER) -c ../nltrans.c + $(MEMWCOMP) -c ../nltrans.c pn2acpn.o: ../spnbox.h ../../pnheaders/matrix.h ../MemoryManager.h ../pn2acpn.c - $(COMPILER) -c ../pn2acpn.c + $(MEMWCOMP) -c ../pn2acpn.c pn2eacpn.o: ../spnbox.h ../../pnheaders/matrix.h ../MemoryManager.h ../pn2eacpn.c - $(COMPILER) -c ../pn2eacpn.c + $(MEMWCOMP) -c ../pn2eacpn.c pns.o: ../../pnheaders/pns.c ../../pnheaders/pns.h ../../pnheaders/general.h ../../pnheaders/matrix.h - $(COMPILER) -c ../../pnheaders/pns.c + $(MEMWCOMP) -c ../../pnheaders/pns.c reduce.o: ../spnbox.h ../extendedmatrix.h ../../pnheaders/matrix.h ../reduce.c - $(COMPILER) -c ../reduce.c + $(MEMWCOMP) -c ../reduce.c supervis.o: ../spnbox.h ../matrixmath.h ../../pnheaders/general.h ../../pnheaders/ ../../pnheaders/matrix.h ../supervis.c ../extendedmatrix.h - $(COMPILER) -c ../supervis.c + $(MEMWCOMP) -c ../supervis.c StructuredIO.o: ../MemoryManager.h ../../pnheaders/matrix.h StructuredIO.h StructuredIO.c - $(COMPILER) -c StructuredIO.c + $(MEMWCOMP) -c StructuredIO.c tactn.o: ../tactn.c ../spnbox.h ../../pnheaders/matrix.h ../../pnheaders/pns.h ../matrixmath.h ../MemoryManager.h - $(COMPILER) -c ../tactn.c + $(MEMWCOMP) -c ../tactn.c test.o: test.c test.h ../../pnheaders/pns.h ../../pnheaders/matrix.h ../matrixmath.h ../spnbox.h ../MemoryManager.h StructuredIO.h - $(COMPILER) -c test.c + $(MEMWCOMP) -c test.c #Rules for making the test executable object files. test-actn.o: test-actn.c $(COMMONHEADER) - $(COMPILER) -c test-actn.c + $(MEMWCOMP) -c test-actn.c test-admcon.o: test-admcon.c $(COMMONHEADER) - $(COMPILER) -c test-admcon.c + $(MEMWCOMP) -c test-admcon.c test-asiph.o: test-asiph.c $(COMMONHEADER) - $(COMPILER) -c test-asiph.c + $(MEMWCOMP) -c test-asiph.c test-avpr.o: test-avpr.c $(COMMONHEADER) - $(COMPILER) -c test-avpr.c + $(MEMWCOMP) -c test-avpr.c test-extendedmatrix.o: test-extendedmatrix.c $(COMMONHEADER) - $(COMPILER) -c test-extendedmatrix.c + $(MEMWCOMP) -c test-extendedmatrix.c test-dp.o: test-dp.c $(COMMONHEADER) - $(COMPILER) -c test-dp.c + $(MEMWCOMP) -c test-dp.c test-fvpr.o: test-fvpr.c $(COMMONHEADER) - $(COMPILER) -c test-fvpr.c + $(MEMWCOMP) -c test-fvpr.c test-ilpadm.o: test-ilpadm.c $(COMMONHEADER) - $(COMPILER) -c test-ilpadm.c + $(MEMWCOMP) -c test-ilpadm.c test-ipslv.o: test-ipslv.c - $(COMPILER) -c test-ipslv.c + $(MEMWCOMP) -c test-ipslv.c test-ipsolve.o: test-ipsolve.c $(COMMONHEADER) - $(COMPILER) -c test-ipsolve.c + $(MEMWCOMP) -c test-ipsolve.c test-isadm.o: test-isadm.c $(COMMONHEADER) - $(COMPILER) -c test-isadm.c + $(MEMWCOMP) -c test-isadm.c test-linenf.o: test-linenf.c $(COMMONHEADER) - $(COMPILER) -c test-linenf.c + $(MEMWCOMP) -c test-linenf.c test-matrixmath.o: test-matrixmath.c $(COMMONHEADER) - $(COMPILER) -c test-matrixmath.c + $(MEMWCOMP) -c test-matrixmath.c test-msplit.o: test-msplit.c $(COMMONHEADER) - $(COMPILER) -c test-msplit.c + $(MEMWCOMP) -c test-msplit.c test-nltrans.o: test-nltrans.c $(COMMONHEADER) - $(COMPILER) -c test-nltrans.c + $(MEMWCOMP) -c test-nltrans.c test-pn2acpn.o: test-pn2acpn.c $(COMMONHEADER) - $(COMPILER) -c test-pn2acpn.c + $(MEMWCOMP) -c test-pn2acpn.c test-pn2eacpn.o: test-pn2eacpn.c $(COMMONHEADER) - $(COMPILER) -c test-pn2eacpn.c + $(MEMWCOMP) -c test-pn2eacpn.c test-supervis.o: test-supervis.c $(COMMONHEADER) - $(COMPILER) -c test-supervis.c + $(MEMWCOMP) -c test-supervis.c test-reduce.o: test-reduce.c $(COMMONHEADER) - $(COMPILER) -c test-reduce.c + $(MEMWCOMP) -c test-reduce.c test-tactn.o: test-tactn.c $(COMMONHEADER) - $(COMPILER) -c test-tactn.c + $(MEMWCOMP) -c test-tactn.c #Rules for making the liblpsolve55.a static library for use with ipsolve. ../liblpsolve55.a: ../../third-party/lp_solve_5.5/lpsolve55/liblpsolve55.a cp ../../third-party/lp_solve_5.5/lpsolve55/liblpsolve55.a ../liblpsolve55.a ../../third-party/lp_solve_5.5/lpsolve55/liblpsolve55.a: - cd ../../third-party/lp_solve_5.5; make -f Makefile.linux lib \ No newline at end of file + cd ../../third-party/lp_solve_5.5; make -f Makefile.linux lib + +#The memwatch libraries. +memwatch.o: ../../third-party/memwatch-2.71/memwatch.c ../../third-party/memwatch-2.71/memwatch.h + $(COMPILER) -c ../../third-party/memwatch-2.71/memwatch.c \ No newline at end of file Modified: spnbox/tests/test-dp.c =================================================================== --- spnbox/tests/test-dp.c 2009-08-07 06:29:10 UTC (rev 213) +++ spnbox/tests/test-dp.c 2009-08-14 06:56:54 UTC (rev 214) @@ -7,11 +7,11 @@ { return 0; } - char iDesc[] = "matrix D, matrix Dm, matrix Dp, indexarray Tuc, indexarray Tuo, arrayi IncludeT, arrayi ExcludeT, arrayi B, arrayi B0, matrix L, matrix L0, string WriteLog, string EnforceLive"; + char iDesc[] = "matrix D, matrix Dm, matrix Dp, indexarray Tuc, indexarray Tuo, arrayi IncludeT, arrayi ExcludeT, arrayi B, arrayi B0, matrix L, matrix L0, string WriteLog, string EnforceLive, int ID"; char oDesc[] = "matrix Lf, arrayi Bf, matrix L0f, arrayi B0f, string how"; int *iFill; int oFill[5]; - int BCount, B0Count, i; + int BCount, B0Count, i, ID; matrix D; char WriteLog[128] = "", EnforceLive[128] = ""; dp_p p; @@ -30,10 +30,11 @@ remove("dp.log"); remove("dp.dat"); int transitions; - while (ParseStructure(input, iDesc, &iFill, &mem, &D, &p.Dm, &p.Dp, &p.Tuc, &p.TucCount, &p.Tuo, &p.TuoCount, &p.IncludeT, &p.IncludeCount, &p.ExcludeT, &p.ExcludeCount, &p.B, &BCount, &p.B0, &B0Count, &p.L, &p.L0, WriteLog, EnforceLive)) + ID = -1; + while (ParseStructure(input, iDesc, &iFill, &mem, &D, &p.Dm, &p.Dp, &p.Tuc, &p.TucCount, &p.Tuo, &p.TuoCount, &p.IncludeT, &p.IncludeCount, &p.ExcludeT, &p.ExcludeCount, &p.B, &BCount, &p.B0, &B0Count, &p.L, &p.L0, WriteLog, EnforceLive, &ID)) { transitions = (iFill[0] ? NumberOfColumns(D) : (iFill[1] ? NumberOfColumns(p.Dm) : (iFill[2] ? NumberOfColumns(p.Dp) : 0))); - DisplayStructure(iDesc, iFill, &D, &p.Dm, &p.Dp, p.Tuc, p.TucCount, NumberOfColumns(p.Dm), p.Tuo, p.TuoCount, NumberOfColumns(p.Dm), p.IncludeT, p.IncludeCount, p.ExcludeT, p.ExcludeCount, p.B, BCount, p.B0, B0Count, &p.L, &p.L0, WriteLog, EnforceLive); + DisplayStructure(iDesc, iFill, &D, &p.Dm, &p.Dp, p.Tuc, p.TucCount, NumberOfColumns(p.Dm), p.Tuo, p.TuoCount, NumberOfColumns(p.Dm), p.IncludeT, p.IncludeCount, p.ExcludeT, p.ExcludeCount, p.B, BCount, p.B0, B0Count, &p.L, &p.L0, WriteLog, EnforceLive, ID); FillDmDp(iFill, &D, &p.Dm, &p.Dp, &mem); /*Log writing defaults to on.*/ if (strcmp(WriteLog, "off")) p.option |= DP_OPT_WRITELOG; @@ -53,7 +54,7 @@ //For the duration of a test, append to the log files. p.option |= DP_OPT_APPENDLOGS; - dp_r res = dp(&p); + dp_r res = dp(&p, ID); printf("Solution:\n"); DisplayStructure(oDesc, oFill, &res.Lf, res.Bf, NumberOfRows(res.Lf), &res.L0f, res.B0f, NumberOfRows(res.L0f), res.how); printf("-------------------------------------------------------------------------------\n\n"); @@ -62,6 +63,7 @@ mem = CreateMemoryManager(10, 10, 0, 0); memset(&p, 0, sizeof(dp_p)); + ID = -1; WriteLog[0] = '\0'; EnforceLive[0] = '\0'; } Modified: spnbox/tests/test-dp.txt =================================================================== --- spnbox/tests/test-dp.txt 2009-08-07 06:29:10 UTC (rev 213) +++ spnbox/tests/test-dp.txt 2009-08-14 06:56:54 UTC (rev 214) @@ -2,12 +2,16 @@ rem arrayi IncludeT, arrayi ExcludeT, arrayi B, arrayi B0, matrix L, matrix L0, rem string WriteLog = on/off, string EnforceLive = on/off +echo --------------------------------------------------------------------------- +echo ----- Deadlock Prevention Tests ----- +echo --------------------------------------------------------------------------- echo Deadlock prevention tests. echo Problem 1. echo Example 5.2 from [Iordache, 2000] echo Answer should be: echo L = [ 2 2 1 ] echo b = [ 2 ] +ID 1 Dp 3 5 0 1 0 1 0 0 0 1 0 1 @@ -21,6 +25,7 @@ echo Problem 2. echo A Petri net in which deadlock cannot be prevented. +ID 2 Dp 3 3 0 1 0 0 0 1 @@ -34,6 +39,7 @@ echo Problem 3. echo A repetetive Petri net with no smaller siphons. +ID 3 Dm 3 3 0 1 0 1 0 0 @@ -48,6 +54,7 @@ echo Problem 4. echo A similar net that is not strongly connected, i.e. the union of two echo distinct repetitive Petri nets. +ID 4 Dm 6 6 0 1 0 0 0 0 1 0 0 0 0 0 @@ -74,7 +81,7 @@ echo B = [ 1 ] echo ....[ 1 ] echo ....[ 3 ] - +ID 5 Dm 4 5 1 0 1 0 1 0 0 0 1 0 @@ -94,7 +101,7 @@ echo L = [ 1 1 0 0 ] B = [ 1 ] echo ....[ 0 0 1 1 ] [ 1 ] echo ....[ 1 1 1 1 ] [ 3 ] - +ID 6 Dm 4 5 1 0 1 0 1 0 0 0 1 0 @@ -117,6 +124,7 @@ echo This is an example from K. Lautenback, et al, "The Linear Algebra of echo Deadlock Avoidance - A Petri Net Approach", technical report at the echo University of Koblenz, Institute for Computer Science, 1996. +ID 7 Dm 4 4 3 0 5 0 0 1 0 0 @@ -135,6 +143,7 @@ echo L = [ 2 0 1 ] B = [ 1 ] echo .....[ 0 2 1 ] [ 1 ] echo L0 = [ 2 2 2 ] B0 = [ 3 ] +ID 8 D 3 3 -1 1 0 -1 0 1 @@ -142,4 +151,156 @@ Tuo 1 0 done + +echo --------------------------------------------------------------------------- +echo ----- Liveness Enforcement Tests ----- +echo --------------------------------------------------------------------------- +echo Problem 0. (from dpdem4.m) +ID 100 +D 15 11 +-1 0 0 0 1 0 1 0 0 0 0 + 0 0 0 0 0 1 -1 0 0 0 0 + 0 1 -1 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 1 -1 0 + 0 0 1 -1 0 0 0 0 0 0 0 + 0 0 0 0 -1 0 0 0 0 0 0 + 1 -1 0 0 0 -1 0 0 0 0 0 + 0 0 0 0 0 0 0 1 -1 0 0 + 0 0 0 0 0 0 0 0 0 0 -1 + 0 0 0 0 0 0 0 -1 0 0 1 +-1 1 0 0 0 1 0 0 0 0 0 + 0 -1 1 0 0 0 0 0 0 -1 1 + 0 0 -1 1 0 0 0 0 -1 1 0 + 0 0 0 -1 1 0 0 -1 1 0 0 + 0 0 0 0 0 -1 1 0 0 0 0 +EnforceLive on +done + +echo Problem 1. Example 5.2 from the ISIS report #4 of 2000. +echo The answer should be: +echo L = [ 2 2 1 ] B = [ 2 ] +ID 101 +Dp 3 5 +0 1 0 1 0 +0 0 1 0 1 +1 0 0 0 0 +Dm 3 5 +1 0 0 0 1 +1 0 0 1 0 +0 2 2 0 0 +EnforceLive on +done + +echo Problem 2. A Petri net in which deadlock cannot be prevented. +ID 102 +Dp 3 3 +0 1 0 +0 0 1 +1 0 0 +Dm 3 3 +1 0 0 +1 0 0 +0 1 1 +EnforceLive on +done + +echo Problem 3. A repetitive net. +ID 103 +Dm 3 3 +0 1 0 +1 0 0 +0 0 1 +Dp 3 3 +1 0 0 +0 0 1 +0 1 0 +EnforceLive on +done + +echo Problem 4. The union of two distinct repetetive Petri nets. +ID 104 +Dm 6 6 +0 1 0 0 0 0 +1 0 0 0 0 0 +0 0 1 0 0 0 +0 0 0 0 1 0 +0 0 0 1 0 0 +0 0 0 0 0 1 +Dp 6 6 +1 0 0 0 0 0 +0 0 1 0 0 0 +0 1 0 0 0 0 +0 0 0 1 0 0 +0 0 0 0 0 1 +0 0 0 0 1 0 +EnforceLive on +done + +echo Problem 5. DAta from Example 5.1 from ISIS report #3 of 2000. +ID 105 +Dm 4 5 +1 0 1 0 1 +0 0 0 1 0 +0 1 0 0 1 +1 0 1 0 0 +Dp 4 5 +0 0 0 1 0 +0 0 2 0 1 +3 0 0 0 0 +0 1 0 0 0 +EnforceLive on +done + +echo Problem 6. The same as Problem 5 (Data from Example 5.1 from ISIS report #3 +echo of 2000.) except with an initial constraint. +ID 106 +Dm 4 5 +1 0 1 0 1 +0 0 0 1 0 +0 1 0 0 1 +1 0 1 0 0 +Dp 4 5 +0 0 0 1 0 +0 0 2 0 1 +3 0 0 0 0 +0 1 0 0 0 +L 1 4 +1 1 1 1 +B 1 3 +EnforceLive on +done + +echo Problem 7. Example 5.3 from ISIS report #4 of 2000. +echo Has an unobservable transition. +echo Answer should be: +echo L = [ 2 0 1 ] B = [ 1 ] +echo .....[ 0 2 1 ] [ 1 ] +echo L0 = [ 2 2 2 ] B0 = [ 3 ] +ID 107 +D 3 3 +-1 1 0 +-1 0 1 + 2 -1 -1 +Tuo 1 0 +EnforceLive on +done + +echo Problem 8. Example 5.4 from ISIS report #4 of 2000. +echo Has initial constraints. +echo The right answer should be: +echo L = [ 1 0 1 1 1 ] B = [ 1 ] +echo .....[ 0 1 1 1 1 ] [ 1 ] +echo L0 = [ -1 -1 -1 -1 -1 ] B0 = [ -1 ] +ID 108 +D 5 6 +-1 1 0 0 0 0 +-1 0 1 0 0 0 + 2 -1 -1 -1 0 0 + 0 0 0 1 1 -1 + 0 0 0 0 -1 1 +L0 1 5 +-1 -1 -1 -1 -1 +B0 1 -1 +EnforceLive on +done quit Added: third-party/memwatch-2.71/FAQ =================================================================== --- third-party/memwatch-2.71/FAQ (rev 0) +++ third-party/memwatch-2.71/FAQ 2009-08-14 06:56:54 UTC (rev 214) @@ -0,0 +1,133 @@ +Frequently Asked Questions for memwatch + +Q. I'm not getting any log file! What's wrong?? + +A. Did you define MEMWATCH when compiling all files? + Did you include memwatch.h in all the files? + If you did, then...: + + Memwatch creates the file when it initializes. If you're not + getting the log file, it's because a) memwatch is not + initializing or b) it's initializing, but can't create the + file. + + Memwatch has two functions, mwInit() and mwTerm(), that + initialize and terminate memwatch, respectively. They are + nestable. You USUALLY don't need to call mwInit() and + mwTerm(), since memwatch will auto-initialize on the first + call to a memory function, and then add mwTerm() to the + atexit() list. + + You can call mwInit() and mwTerm() manually, if it's not + initializing properly or if your system doesn't support + atexit(). Call mwInit() as soon as you can, and mwTerm() at + the logical no-error ending of your program. Call mwAbort() + if the program is stopping due to an error; this will + terminate memwatch even if more than one call to mwTerm() is + outstanding. + + If you are using C++, remember that global and static C++ + objects constructors execute before main() when considering + where to put mwInit(). Also, their destructors execute after + main(). You may want to create a global object very early + with mwInit() in the constructor and mwTerm() in the + destructor. Too bad C++ does not guarantee initialization + order for global objects. + + If this didn't help, try adding a call to mwDoFlush(1) after + mwInit(). If THAT didn't help, then memwatch is unable to + create the log file. Check write permissions. + + If you can't use a log file, you can still use memwatch by + redirecting the output to a function of your choice. See the + next question. + +Q. I'd like memwatch's output to pipe to my fave debugger! How? + +A. Call mwSetOutFunc() with the address of a "void func(int c)" + function. You should also consider doing something about + the ARI handler, see memwatch.h for more details about that. + +Q. Why isn't there any C++ support? + +A. Because C++ is for sissies! =) Just kidding. + C++ comes with overridable allocation/deallocation + built-in. You can define your own new/delete operators + for any class, and thus circumvent memwatch, or confuse + it to no end. Also, the keywords "new" and "delete" may + appear in declarations in C++, making the preprocessor + replacement approach shaky. You can do it, but it's not + very stable. + + If someone were to write a rock solid new/delete checker + for C++, there is no conflict with memwatch; use them both. + +Q. I'm getting "WILD free" errors, but the code is bug-free! + +A. If memwatch's free() recieves a pointer that wasn't allocated + by memwatch, a "WILD free" message appears. If the source of + the memory buffer is outside of memwatch (a non-standard + library function, for instance), you can use mwFree_() to + release it. mwFree_() calls free() on the pointer given if + memwatch can't recognize it, instead of blocking it. + + Another source of "WILD free" messages is that if memwatch + is terminated before all memory allocated is freed, memwatch + will have forgotten about it, and thus generate the errors. + This is commonly caused by having memwatch auto-initialize, + and then using atexit() to clean up. When auto-initializing, + memwatch registers mwTerm() with atexit(), but if mwTerm() + runs before all memory is freed, then you will get "unfreed" + and "WILD free" messages when your own atexit()-registered + cleanup code runs, and frees the memory. + +Q. I'm getting "unfreed" errors, but the code is bug-free! + +A. You can get erroneous "unfreed" messages if memwatch + terminates before all memory has been freed. Try using + mwInit() and mwTerm() instead of auto-initialization. + + If you _are_ using mwInit() and mwTerm(), it may be that + some code in your program executes before mwInit() or + after mwTerm(). Make sure that mwInit() is the first thing + executed, and mwTerm() the last. + +Q. When compiling memwatch I get these 'might get clobbered' + errors, and something about a longjmp() inside memwatch. + +A. When using gcc or egcs with the optimization to inline + functions, this warning occurs. This is because gcc and + egcs inlines memwatch's functions with setjmp/longjmp, + causing the calling functions to become unstable. + + The gcc/egcs maintainers have been informed of this + problem, but until they modify the inline optimization + so that it leaves setjmp functions alone, make sure to + compile memwatch without inline function optimizations. + + gcc 2.95.2 can be patched for this, and I have been told + it will be fixed in an upcoming version. + +Q. My program crashes with SIGSEGV or alignment errors, but + only when I compile with memwatch enabled! + +A. You are using a 64-bit (or higher) platform, and memwatch + was unable to detect and adjust for this. You'll have to + either compile with a suitable define for mwROUNDALLOC, + I suggest (number of bits / 8), or define mwROUNDALLOC + directly in memwatch.c. + + Also, please check your limits.h file for the relevant + #defines, and tell me what they are. + +Q. When I include string.h after memwatch.h, I get errors + related to strdup(), what gives? + +A. Most, but probably not all, platforms are nice about + including files multiple times, so I could probably + avoid these errors by including string.h from memwatch.h. + But since I want to be on the safe side, I don't. + + To fix this, simply include string.h before memwatch.h, + or modify memwatch.h to include string.h. + Added: third-party/memwatch-2.71/Makefile =================================================================== --- third-party/memwatch-2.71/Makefile (rev 0) +++ third-party/memwatch-2.71/Makefile 2009-08-14 06:56:54 UTC (rev 214) @@ -0,0 +1,2 @@ +test: + $(CC) -DMEMWATCH -DMW_STDIO test.c memwatch.c Added: third-party/memwatch-2.71/README =================================================================== --- third-party/memwatch-2.71/README (rev 0) +++ third-party/memwatch-2.71/README 2009-08-14 06:56:54 UTC (rev 214) @@ -0,0 +1,99 @@ +README for MEMWATCH 2.69 + + This file should be enough to get you started, and should be + enough for small projects. For more info, see the files USING + and the FAQ. If this is not enough, see memwatch.h, which is + well documented. + + Memwatch is licensed under the GPL from version 2.69 + onwards. Please read the file gpl.txt for more details. + + If you choose to use memwatch to validate your projects, I + would like to hear about it. Please drop me a line at + jo...@li... about the project itself, the hardware, + operating system, compiler and any URL(s) you feel is + appropriate. + +***** To run the test program: + + Look at the source code for test.c first. It does some really + nasty things, and I want you to be aware of that. If memwatch + can't capture SIGSEGV (General Protection Fault for Windoze), + your program will dump core (crash for Windoze). + + Once you've done that, you can build the test program. + + Linux and other *nixes with gcc: + + gcc -o test -DMEMWATCH -DMEMWATCH_STDIO test.c memwatch.c + + Windows 95, Windows NT with MS Visual C++: + + cl -DMEMWATCH -DMEMWATCH_STDIO test.c memwatch.c + + Then simply run the test program. + + ./test + + +***** Quick-start instructions: + + 1. Make sure that memwatch.h is included in all of the + source code files. If you have an include file that + all of the source code uses, you might be able to include + memwatch.h from there. + + 2. Recompile the program with MEMWATCH defined. See your + compiler's documentation if you don't know how to do this. + The usual switch looks like "-DMEMWATCH". To have MEMWATCH + use stderr for some output (like, "Abort, Retry, Ignore?"), + please also define MW_STDIO (or MEMWATCH_STDIO, same thing). + + 3. Run the program and examine the output in the + log file "memwatch.log". If you didn't get a log file, + you probably didn't do step 1 and 2 correctly, or your + program crashed before memwatch flushed the file buffer. + To have memwatch _always_ flush the buffer, add a call + to "mwDoFlush(1)" at the top of your main function. + + 4. There is no fourth step... but remember that there + are limits to what memwatch can do, and that you need + to be aware of them: + +***** Limits to memwatch: + + Memwatch cannot catch all wild pointer writes. It can catch + those it could make itself due to your program trashing + memwatch's internal data structures. It can catch, sort of, + wild writes into No Mans Land buffers (see the header file for + more info). Anything else and you're going to get core dumped, + or data corruption if you're lucky. + + There are other limits of course, but that one is the most + serious one, and the one that you're likely to be suffering + from. + +***** Can use memwatch with XXXXX? + + Probably the answer is yes. It's been tested with several + different platforms and compilers. It may not work on yours + though... but there's only one way to find out. + +***** Need more assistance? + + I don't want e-mail on "how to program in C", or "I've got a + bug, help me". I _do_ want you to send email to me if you + find a bug in memwatch, or if it won't compile cleanly on your + system (assuming it's an ANSI-C compiler of course). + + If you need help with using memwatch, read the header file. + If, after reading the header file, you still can't resolve the + problem, please mail me with the details. + + I can be reached at "jo...@li...". + + The latest version of memwatch should be found at + "http://www.linkdata.se/". + + Johan Lindh + Added: third-party/memwatch-2.71/USING =================================================================== --- third-party/memwatch-2.71/USING (rev 0) +++ third-party/memwatch-2.71/USING 2009-08-14 06:56:54 UTC (rev 214) @@ -0,0 +1,213 @@ +Using memwatch +============== + +What is it? + + Memwatch is primarily a memory leak detector for C. Besides + detecting leaks, it can do a bunch of other stuff, but lets + stay to the basics. If you _really_ want to know all the + gory details, you should check out the header file, + memwatch.h, and the source code. It's actually got some + comments! (Whoa, what a concept!) + +How do I get the latest version? + + http://www.linkdata.se/sourcecode.html + ftp://ftp.linkdata.se/pub/memwatch/ + +How does it work? + + Using the C preprocessor, memwatch replaces all your + programs calls to ANSI C memory allocation functions with + calls to it's own functions, which keeps a record of all + allocations. + + Memwatch is very unobtrusive; unless the define MEMWATCH is + defined, memwatch removes all traces of itself from the + code (using the preprocessor). + + Memwatch normally writes it's data to the file + memwatch.log, but this can be overridden; see the section + on I/O, later. + +Can I use it for my C++ sources? + + You can, but it's not recommended. C++ allows individual + classes to have their own memory management, and the + preprocessor approach used by memwatch can cause havoc + with such class declarations if improperly used. + + If you have no such classes, or have them but still want + to test it, you can give it a try. + + First, re-enable the C++ support code in memwatch. + If you can't find it, you probably shouldn't be using + it. Then, in your source code, after including ALL + header files: + + #define new mwNew + #define delete mwDelete + + This will cause calls to new and delete in that source file + to be directed to memwatch. Also, be sure to read all the + text in memwatch.h regarding C++ support. + +Is this stuff thread-safe? + + I doubt it. As of version 2.66, there is rudimentary support + for threads, if you happen to be using Win32 or if you have + pthreads. Define WIN32 or MW_PTHREADS to signify this fact. + + This will cause a global mutex to be created, and memwatch + will lock it when accessing the global memory chain, but it's + still far from certified threadsafe. + +Initialization and cleanup + + In order to do it's work in a timely fashion, memwatch + needs to do some startup and cleanup work. mwInit() + initializes memwatch and mwTerm() terminates it. Memwatch + can auto-initialize, and will do so if you don't call + mwInit() yourself. If this is the case, memwatch will use + atexit() to register mwTerm() to the atexit-queue. + + The auto-init technique has a caveat; if you are using + atexit() yourself to do cleanup work, memwatch may + terminate before your program is done. To be on the safe + side, use mwInit() and mwTerm(). + + mwInit() and mwTerm() is nestable, so you can call mwInit() + several times, requiring mwTerm() to be called an equal + number of times to terminate memwatch. + + In case of the program aborting in a controlled way, you + may want to call mwAbort() instead of mwTerm(). mwAbort() + will terminate memwatch even if there are outstanding calls + to mwTerm(). + +I/O operations + + During normal operations, memwatch creates a file named + memwatch.log. Sometimes, memwatch.log can't be created; + then memwatch tries to create files name memwatNN.log, + where NN is between 01 and 99. If that fails, no log will + be produced. + + If you can't use a file log, or don't want to, no worry. + Just call mwSetOutFunc() with the address of a "void + func(int c)" function, and all output will be directed + there, character by character. + + Memwatch also has an Abort/Retry/Ignore handler that is + used when an ASSERT or VERIFY fails. The default handler + does no I/O, but automatically aborts the program. You can + use any handler you want; just send the address of a "int + func(const char*)" to mwSetAriFunc(). For more details on + that, see memwatch.h. + +TRACE/ASSERT/VERIFY macros + + Memwatch defines (if not already defined) the macros TRACE, + ASSERT and VERIFY. If you are already using macros with + these names, memwatch 2.61 and later will not override + them. Memwatch 2.61 and later will also always define the + macros mwTRACE, mwASSERT and mwVERIFY, so you can use these + to make sure you're talking to memwatch. Versions prior + to 2.61 will *OVERRIDE* existing TRACE, ASSERT and VERIFY. + + To make sure that existing TRACE, ASSERT and VERIFY macros + are preserved, you can define MW_NOTRACE, MW_NOASSERT and + MW_NOVERIFY. All versions of memwatch will abide by these. + +How slow can you go? + + Memwatch slows things down. Large allocations aren't + affected so that you can measure it, but small allocations + that would utilize a compilers small-allocator function + suddenly cannot, and so gets slowed down alot. As a worst + case, expect it to be 3-5 times slower. + + Free'ing gets hit worse, I'm afraid, as memwatch checks + a lot of stuff when freeing. Expect it to be 5-7 times + slower, no matter what the size of the allocation. + +Stress-testing the application + + You can simulate low-memory conditions using mwLimit(). + mwLimit() takes the maximum number of bytes to be + allocated; when the limit is hit, allocation requests will + fail, and a "limit" message will be logged. + + If you hit a real low-memory situation, memwatch logs that + too. Memwatch itself has some reserve memory tucked away so + it should continue running even in the worst conditions. + +Hunting down wild writes and other Nasty Things + + Wild writes are usually caused by using pointers that arent + initialized, or that were initialized, but then the memory + they points to is moved or freed. The best way to avoid + these kind of problems is to ALWAYS initialize pointers to + NULL, and after freeing a memory buffer, setting all + pointers that pointed to it to NULL. + + To aid in tracking down uninitialized pointers memwatch + zaps all memory with certain values. Recently allocated + memory (unless calloc'd, of course), contains 0xFE. + Recently freed memory contains 0xFD. So if your program + crashes when using memwatch and not without memwatch, it's + most likely because you are not initializing your allocated + buffers, or using the buffers after they've been freed. + + In the event that a wild pointer should damage memwatch's + internal data structures, memwatch employs checksums, + multiple copies of some values, and can also repair it's + own data structures. + + If you are a paranoid person, and as programmer you should + be, you can use memwatch's mwIsReadAddr() and + mwIsSafeAddr() functions to check the accessibility of + memory. These are implemented for both ANSI C systems and + Win32 systems. Just put an mwASSERT() around the check and + forget about it. + +Can I help? + + Well, sure. For instance, I like memwatch to compile + without any warnings or errors. If you are using an ANSI C + compliant compiler, and are getting warnings or errors, + please mail me the details and instructions on how to fix + them, if you can. + + Another thing you can do if you decide to use memwatch is + to mail me the name of the project(s) (and URL, if any), + hardware and operating system, compiler and what user + (organization). I will then post this info on the list of + memwatch users. + (http://www.linkdata.se/memwatchusers.html) + +Top five problems using memwatch + + 5. Passed a non-memwatch allocated pointer to memwatch's + free(). Symtom: Causes an erroneous "WILD free" log + entry to appear. Cure: Either include memwatch.h for + the file that allocates, or use mwFree_() to free it. + + 4. Relied on auto-initialization when using atexit(). + Symptom: Causes incorrect "unfreed" and "WILD free" + messages. Cure: Use mwInit() and mwTerm(). + + 3. Forgot to include memwatch.h in all files. Symptom: + Tends to generate "WILD free" and "unfreed" messages. + Cure: Make sure to include memwatch.h! + + 2. No write permissions in currect directory. Symptom: + Seems like memwatch 'just aint working'. Cure: Use + mwSetOutFunc() to redirect output. + + ...and the number one problem is... + + 1. Didn't define MEMWATCH when compiling. Symptom: + Memwatch dutifully disables itself. Cure: Try adding + -DMEMWATCH to the command line. + Added: third-party/memwatch-2.71/gpl.txt =================================================================== --- third-party/memwatch-2.71/gpl.txt (rev 0) +++ third-party/memwatch-2.71/gpl.txt 2009-08-14 06:56:54 UTC (rev 214) @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest va... [truncated message content] |