Permalink
Browse files

Added a find function to the list because using the iterator can easily

lead to a memory leak.
  • Loading branch information...
1 parent 636e2e9 commit 61f7679f95709359866eed625f8982756ec2fb76 @schuchert committed Oct 9, 2011
Showing with 47 additions and 13 deletions.
  1. +26 −13 .cproject
  2. +4 −0 .project
  3. +15 −0 linked_list.c
  4. +2 −0 linked_list.h
View
@@ -5,15 +5,10 @@
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.config.gnu.cross.lib.debug.1689682484">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.cross.lib.debug.1689682484" moduleId="org.eclipse.cdt.core.settings" name="Debug">
- <externalSettings>
- <externalSetting>
- <entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/common_c"/>
- <entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/common_c/Debug"/>
- <entry flags="RESOLVED" kind="libraryFile" name="common_c"/>
- </externalSetting>
- </externalSettings>
+ <externalSettings/>
<extensions>
- <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
+ <extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
+ <extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
@@ -24,15 +19,23 @@
<configuration artifactExtension="a" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.staticLib" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.staticLib" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.cross.lib.debug.1689682484" name="Debug" parent="cdt.managedbuild.config.gnu.cross.lib.debug">
<folderInfo id="cdt.managedbuild.config.gnu.cross.lib.debug.1689682484." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.lib.debug.888505903" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.lib.debug">
- <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.500772007" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
- <builder buildPath="${workspace_loc:/common_c/Debug}" id="cdt.managedbuild.builder.gnu.cross.1682640088" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
+ <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.MachO64;org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.500772007" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
+ <builder buildPath="${workspace_loc:/common_c/Debug}" id="cdt.managedbuild.builder.gnu.cross.1682640088" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross">
+ <outputEntries>
+ <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="Debug"/>
+ <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name="Release"/>
+ </outputEntries>
+ </builder>
<tool command="/opt/local/bin/gcc&#10;" id="cdt.managedbuild.tool.gnu.cross.c.compiler.1174502604" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.1125389995" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" valueType="enumerated"/>
<option id="gnu.c.compiler.option.debugging.level.1432984775" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<option id="gnu.c.compiler.option.include.paths.1896206093" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
- <listOptionValue builtIn="false" value="${CppUTest}/include"/>
+ <listOptionValue builtIn="false" value="/Users/schuchert/src/CppUTest2_3/include"/>
</option>
<option id="gnu.c.compiler.option.misc.other.2147306067" name="Other flags" superClass="gnu.c.compiler.option.misc.other" value="-c -fmessage-length=0 -fprofile-arcs -ftest-coverage" valueType="string"/>
+ <option id="gnu.c.compiler.option.preprocessor.def.symbols.5458098" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
+ <listOptionValue builtIn="false" value="CPPUTEST_USE_MEM_LEAK_DETECTION"/>
+ </option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1266331278" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.841351266" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
@@ -43,10 +46,16 @@
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.246949667" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker"/>
<tool id="cdt.managedbuild.tool.gnu.cross.archiver.1293802408" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>
<tool id="cdt.managedbuild.tool.gnu.cross.assembler.693348922" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler">
+ <option id="gnu.both.asm.option.include.paths.1163797026" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath">
+ <listOptionValue builtIn="false" value="/Users/schuchert/src/CppUTest2_3/include"/>
+ </option>
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1124489268" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
+ <sourceEntries>
+ <entry excluding="tests" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
+ </sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
@@ -61,7 +70,8 @@
</externalSetting>
</externalSettings>
<extensions>
- <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
+ <extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
+ <extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
@@ -72,7 +82,7 @@
<configuration artifactExtension="a" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.staticLib" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.staticLib" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.cross.lib.release.1333758393" name="Release" parent="cdt.managedbuild.config.gnu.cross.lib.release">
<folderInfo id="cdt.managedbuild.config.gnu.cross.lib.release.1333758393." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.lib.release.671743688" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.lib.release">
- <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1327697167" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
+ <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.MachO64;org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1327697167" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
<builder buildPath="${workspace_loc:/common_c/Release}" id="cdt.managedbuild.builder.gnu.cross.1497878678" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.449407436" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.1346305762" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" valueType="enumerated"/>
@@ -91,6 +101,9 @@
</tool>
</toolChain>
</folderInfo>
+ <sourceEntries>
+ <entry excluding="tests" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
+ </sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
View
@@ -10,6 +10,10 @@
<triggers>clean,full,incremental,</triggers>
<arguments>
<dictionary>
+ <key>?children?</key>
+ <value>?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|?name?=entry\\\\\\\|\\\|\||</value>
+ </dictionary>
+ <dictionary>
<key>?name?</key>
<value></value>
</dictionary>
View
@@ -56,6 +56,21 @@ void linked_list_release_destroy(linked_list *aList, RELEASE_F f) {
}
}
+void* linked_list_find(linked_list *list, COMP_F f, const void *other) {
+ list_iterator *iter = linked_list_begin(list);
+
+ while (linked_list_has_next(iter)) {
+ void *current = linked_list_next(iter);
+ if (f(current, other)) {
+ linked_list_end(iter);
+ return current;
+ }
+ }
+
+ linked_list_end(iter);
+ return NULL;
+}
+
size_t linked_list_size(linked_list *list) {
size_t size = 0;
list_node *current = list->head;
View
@@ -12,6 +12,7 @@ typedef struct linked_list linked_list;
typedef struct list_node list_node;
typedef struct list_iterator list_iterator;
typedef void (*RELEASE_F)(void *);
+typedef int (*COMP_F)(const void *current, const void *other);
linked_list *linked_list_create(void);
void linked_list_destroy(linked_list *aList);
@@ -20,6 +21,7 @@ size_t linked_list_size(linked_list *list);
void linked_list_add(linked_list *list, void *value);
list_node *linked_list_last(linked_list *list);
+void* linked_list_find(linked_list *list, COMP_F f, const void *other);
list_iterator *linked_list_begin(linked_list *list);
void linked_list_end(list_iterator *iter);
int linked_list_has_next(list_iterator *iter);

0 comments on commit 61f7679

Please sign in to comment.