From 80fdb634ba1c7f0bd4addf9c206e685a8e8a5240 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 1 May 2017 17:44:22 +0200 Subject: [PATCH 1/6] classify: Remove unused ContextsSeen Signed-off-by: Stefan Weil --- classify/adaptive.cpp | 7 ------- classify/adaptive.h | 1 - 2 files changed, 8 deletions(-) diff --git a/classify/adaptive.cpp b/classify/adaptive.cpp index 039373c581..94e09adf95 100644 --- a/classify/adaptive.cpp +++ b/classify/adaptive.cpp @@ -21,7 +21,6 @@ ----------------------------------------------------------------------------*/ #include "adaptive.h" #include "emalloc.h" -#include "freelist.h" #include "globals.h" #include "classify.h" @@ -81,11 +80,8 @@ void AddAdaptedClass(ADAPT_TEMPLATES Templates, */ void FreeTempConfig(TEMP_CONFIG Config) { assert (Config != NULL); - - destroy_nodes (Config->ContextsSeen, memfree); FreeBitVector (Config->Protos); free(Config); - } /* FreeTempConfig */ /*---------------------------------------------------------------------------*/ @@ -231,7 +227,6 @@ TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId) { Config->NumTimesSeen = 1; Config->MaxProtoId = MaxProtoId; Config->ProtoVectorSize = WordsInVectorOfSize (NumProtos); - Config->ContextsSeen = NIL_LIST; zero_all_bits (Config->Protos, Config->ProtoVectorSize); Config->FontinfoId = FontinfoId; @@ -547,8 +542,6 @@ void WritePermConfig(FILE *File, PERM_CONFIG Config) { */ void WriteTempConfig(FILE *File, TEMP_CONFIG Config) { assert (Config != NULL); - /* contexts not yet implemented */ - assert (Config->ContextsSeen == NULL); fwrite ((char *) Config, sizeof (TEMP_CONFIG_STRUCT), 1, File); fwrite ((char *) Config->Protos, sizeof (uinT32), diff --git a/classify/adaptive.h b/classify/adaptive.h index 0f5f362796..c71bc90039 100644 --- a/classify/adaptive.h +++ b/classify/adaptive.h @@ -41,7 +41,6 @@ typedef struct uinT8 NumTimesSeen; uinT8 ProtoVectorSize; PROTO_ID MaxProtoId; - LIST ContextsSeen; BIT_VECTOR Protos; int FontinfoId; // font information inferred from pre-trained templates } TEMP_CONFIG_STRUCT; From ca89a11f285fc9b883d82a63573bfb14eab75494 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 1 May 2017 17:45:49 +0200 Subject: [PATCH 2/6] cutil: Remove unused code using memfree The case (destructor == NULL) never occurs in the current code. Signed-off-by: Stefan Weil --- cutil/oldlist.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cutil/oldlist.cpp b/cutil/oldlist.cpp index 9e3f6f4c06..52c3725e09 100644 --- a/cutil/oldlist.cpp +++ b/cutil/oldlist.cpp @@ -87,8 +87,6 @@ #include #if MAC_OR_DOS #include -#else -#include "freelist.h" #endif /*---------------------------------------------------------------------- @@ -202,8 +200,7 @@ LIST destroy(LIST list) { * Return the space taken by the LISTs of a list to the heap. **********************************************************************/ void destroy_nodes(LIST list, void_dest destructor) { - if (destructor == NULL) - destructor = memfree; + ASSERT_HOST(destructor != NULL); while (list != NIL_LIST) { if (first_node(list) != NULL) (*destructor)(first_node(list)); From 1d6dd03bfcbf7a2841e3c0510c7b24fd10a6ef27 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 1 May 2017 17:46:44 +0200 Subject: [PATCH 3/6] training: Replace memfree by free free also accepts a nullptr argument, so the code can be simplified. Signed-off-by: Stefan Weil --- training/commontraining.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/training/commontraining.cpp b/training/commontraining.cpp index 72ce5c5083..cd6dd75cba 100644 --- a/training/commontraining.cpp +++ b/training/commontraining.cpp @@ -22,7 +22,6 @@ #include "emalloc.h" #include "featdefs.h" #include "fontinfo.h" -#include "freelist.h" #include "globals.h" #include "intfeaturespace.h" #include "mastertrainer.h" @@ -579,18 +578,12 @@ void CleanUpUnusedData( iterate(ProtoList) { Prototype = (PROTOTYPE *) first_node (ProtoList); - if (Prototype->Variance.Elliptical != nullptr) { - memfree(Prototype->Variance.Elliptical); - Prototype->Variance.Elliptical = nullptr; - } - if (Prototype->Magnitude.Elliptical != nullptr) { - memfree(Prototype->Magnitude.Elliptical); - Prototype->Magnitude.Elliptical = nullptr; - } - if (Prototype->Weight.Elliptical != nullptr) { - memfree(Prototype->Weight.Elliptical); - Prototype->Weight.Elliptical = nullptr; - } + free(Prototype->Variance.Elliptical); + Prototype->Variance.Elliptical = nullptr; + free(Prototype->Magnitude.Elliptical); + Prototype->Magnitude.Elliptical = nullptr; + free(Prototype->Weight.Elliptical); + Prototype->Weight.Elliptical = nullptr; } } From e219ad195c98b329f780d30f236a633846d7deca Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 1 May 2017 17:47:18 +0200 Subject: [PATCH 4/6] classify: Replace memfree by free free also accepts a nullptr argument, so the code can be simplified. Signed-off-by: Stefan Weil --- classify/cluster.cpp | 45 +++++++++++++++++----------------------- classify/kdtree.cpp | 7 +++---- classify/ocrfeatures.cpp | 3 +-- classify/protos.cpp | 5 ++--- 4 files changed, 25 insertions(+), 35 deletions(-) diff --git a/classify/cluster.cpp b/classify/cluster.cpp index 1f82349552..cbb74691aa 100644 --- a/classify/cluster.cpp +++ b/classify/cluster.cpp @@ -24,7 +24,6 @@ #include "matrix.h" #include "tprintf.h" #include "danerror.h" -#include "freelist.h" #include #define HOTELLING 1 // If true use Hotelling's test to decide where to split. @@ -546,7 +545,7 @@ LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config) { */ void FreeClusterer(CLUSTERER *Clusterer) { if (Clusterer != NULL) { - memfree (Clusterer->ParamDesc); + free(Clusterer->ParamDesc); if (Clusterer->KDTree != NULL) FreeKDTree (Clusterer->KDTree); if (Clusterer->Root != NULL) @@ -558,7 +557,7 @@ void FreeClusterer(CLUSTERER *Clusterer) { FreeBuckets(Clusterer->bucket_cache[d][c]); } - memfree(Clusterer); + free(Clusterer); } } // FreeClusterer @@ -593,19 +592,14 @@ void FreePrototype(void *arg) { //PROTOTYPE *Prototype) Prototype->Cluster->Prototype = FALSE; // deallocate the prototype statistics and then the prototype itself - if (Prototype->Distrib != NULL) - memfree (Prototype->Distrib); - if (Prototype->Mean != NULL) - memfree (Prototype->Mean); + free (Prototype->Distrib); + free (Prototype->Mean); if (Prototype->Style != spherical) { - if (Prototype->Variance.Elliptical != NULL) - memfree (Prototype->Variance.Elliptical); - if (Prototype->Magnitude.Elliptical != NULL) - memfree (Prototype->Magnitude.Elliptical); - if (Prototype->Weight.Elliptical != NULL) - memfree (Prototype->Weight.Elliptical); + free (Prototype->Variance.Elliptical); + free (Prototype->Magnitude.Elliptical); + free (Prototype->Weight.Elliptical); } - memfree(Prototype); + free(Prototype); } // FreePrototype /** @@ -756,7 +750,7 @@ void CreateClusterTree(CLUSTERER *Clusterer) { FreeKDTree(context.tree); Clusterer->KDTree = NULL; delete context.heap; - memfree(context.candidates); + free(context.candidates); } // CreateClusterTree /** @@ -1173,9 +1167,9 @@ PROTOTYPE *TestEllipticalProto(CLUSTERER *Clusterer, } Tsq += Delta[x] * temp; } - memfree(Covariance); - memfree(Inverse); - memfree(Delta); + free(Covariance); + free(Inverse); + free(Delta); // Changed this function to match the formula in // Statistical Methods in Medical Research p 473 // By Peter Armitage, Geoffrey Berry, J. N. S. Matthews. @@ -1485,7 +1479,7 @@ ComputeStatistics (inT16 N, PARAM_DESC ParamDesc[], CLUSTER * Cluster) { 1.0 / N); // release temporary memory and return - memfree(Distance); + free(Distance); return (Statistics); } // ComputeStatistics @@ -2157,10 +2151,10 @@ BOOL8 DistributionOK(BUCKETS *Buckets) { * @note History: 6/5/89, DSJ, Created. */ void FreeStatistics(STATISTICS *Statistics) { - memfree (Statistics->CoVariance); - memfree (Statistics->Min); - memfree (Statistics->Max); - memfree(Statistics); + free(Statistics->CoVariance); + free(Statistics->Min); + free(Statistics->Max); + free(Statistics); } // FreeStatistics /** @@ -2190,7 +2184,7 @@ void FreeCluster(CLUSTER *Cluster) { if (Cluster != NULL) { FreeCluster (Cluster->Left); FreeCluster (Cluster->Right); - memfree(Cluster); + free(Cluster); } } // FreeCluster @@ -2487,8 +2481,7 @@ CLUSTER * Cluster, FLOAT32 MaxIllegal) NumIllegalInCluster = 0; if (Clusterer->NumChar > NumFlags) { - if (CharFlags != NULL) - memfree(CharFlags); + free(CharFlags); NumFlags = Clusterer->NumChar; CharFlags = (BOOL8 *) Emalloc (NumFlags * sizeof (BOOL8)); } diff --git a/classify/kdtree.cpp b/classify/kdtree.cpp index 6ba7086d23..28bf935016 100644 --- a/classify/kdtree.cpp +++ b/classify/kdtree.cpp @@ -24,7 +24,6 @@ #include "kdtree.h" #include "const.h" #include "emalloc.h" -#include "freelist.h" #include #include @@ -349,7 +348,7 @@ void KDWalk(KDTREE *Tree, void_proc action, void *context) { */ void FreeKDTree(KDTREE *Tree) { FreeSubTree(Tree->Root.Left); - memfree(Tree); + free(Tree); } /* FreeKDTree */ @@ -389,7 +388,7 @@ KDNODE *MakeKDNode(KDTREE *tree, FLOAT32 Key[], void *Data, int Index) { /*---------------------------------------------------------------------------*/ void FreeKDNode(KDNODE *Node) { - memfree ((char *)Node); + free(Node); } @@ -555,6 +554,6 @@ void FreeSubTree(KDNODE *sub_tree) { if (sub_tree != NULL) { FreeSubTree(sub_tree->Left); FreeSubTree(sub_tree->Right); - memfree(sub_tree); + free(sub_tree); } } diff --git a/classify/ocrfeatures.cpp b/classify/ocrfeatures.cpp index dae1d6763c..2dfd693043 100644 --- a/classify/ocrfeatures.cpp +++ b/classify/ocrfeatures.cpp @@ -22,7 +22,6 @@ #include "emalloc.h" #include "callcpp.h" #include "danerror.h" -#include "freelist.h" #include "scanutils.h" #include @@ -75,7 +74,7 @@ void FreeFeatureSet(FEATURE_SET FeatureSet) { if (FeatureSet) { for (i = 0; i < FeatureSet->NumFeatures; i++) FreeFeature(FeatureSet->Features[i]); - memfree(FeatureSet); + free(FeatureSet); } } /* FreeFeatureSet */ diff --git a/classify/protos.cpp b/classify/protos.cpp index 6291f12cd4..0c5f0981e4 100644 --- a/classify/protos.cpp +++ b/classify/protos.cpp @@ -28,7 +28,6 @@ #include "protos.h" #include "const.h" #include "emalloc.h" -#include "freelist.h" #include "callcpp.h" #include "tprintf.h" #include "scanutils.h" @@ -230,11 +229,11 @@ void FreeClassFields(CLASS_TYPE Class) { if (Class) { if (Class->MaxNumProtos > 0) - memfree (Class->Prototypes); + free(Class->Prototypes); if (Class->MaxNumConfigs > 0) { for (i = 0; i < Class->NumConfigs; i++) FreeBitVector (Class->Configurations[i]); - memfree (Class->Configurations); + free(Class->Configurations); } } } From 030d29a4d0d040608da8442c8147d508d26d960c Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 1 May 2017 17:48:50 +0200 Subject: [PATCH 5/6] cutil: Remove unused freelist.c and freelist.h Signed-off-by: Stefan Weil --- cutil/Makefile.am | 6 ++---- cutil/freelist.cpp | 18 ------------------ cutil/freelist.h | 31 ------------------------------- 3 files changed, 2 insertions(+), 53 deletions(-) delete mode 100644 cutil/freelist.cpp delete mode 100644 cutil/freelist.h diff --git a/cutil/Makefile.am b/cutil/Makefile.am index 5b0ffc6ebb..d523105aaf 100644 --- a/cutil/Makefile.am +++ b/cutil/Makefile.am @@ -7,7 +7,7 @@ endif noinst_HEADERS = \ bitvec.h callcpp.h const.h cutil.h cutil_class.h danerror.h efio.h \ - emalloc.h freelist.h globals.h \ + emalloc.h globals.h \ oldlist.h structures.h if !USING_MULTIPLELIBS @@ -22,7 +22,5 @@ endif libtesseract_cutil_la_SOURCES = \ bitvec.cpp callcpp.cpp cutil.cpp cutil_class.cpp danerror.cpp efio.cpp \ - emalloc.cpp freelist.cpp \ + emalloc.cpp \ oldlist.cpp structures.cpp - - diff --git a/cutil/freelist.cpp b/cutil/freelist.cpp deleted file mode 100644 index 4dfeaafa1e..0000000000 --- a/cutil/freelist.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/************************************************************************** - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** http://www.apache.org/licenses/LICENSE-2.0 - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ** See the License for the specific language governing permissions and - ** limitations under the License. -**************************************************************************/ -#include "freelist.h" - -#include - -void memfree(void *element) { - free(element); -} diff --git a/cutil/freelist.h b/cutil/freelist.h deleted file mode 100644 index b848453d4c..0000000000 --- a/cutil/freelist.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*-C-*- - ******************************************************************************** - * - * File: freelist.h (Formerly freelist.h) - * Description: Memory allocator - * Author: Mark Seaman, OCR Technology - * Created: Wed May 30 13:50:28 1990 - * Modified: Mon Dec 10 15:15:25 1990 (Mark Seaman) marks@hpgrlt - * Language: C - * Package: N/A - * Status: Experimental (Do Not Distribute) - * - * (c) Copyright 1990, Hewlett-Packard Company. - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** http://www.apache.org/licenses/LICENSE-2.0 - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ** See the License for the specific language governing permissions and - ** limitations under the License. - * - *********************************************************************************/ - -#ifndef FREELIST_H -#define FREELIST_H - -void memfree(void *element); - -#endif From 6bfde5dcafdd835373f780699620c7e6ee0c9240 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 1 May 2017 18:17:33 +0200 Subject: [PATCH 6/6] Remove undefined macro MAC_OR_DOS Signed-off-by: Stefan Weil --- cutil/cutil.h | 2 +- cutil/oldlist.cpp | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/cutil/cutil.h b/cutil/cutil.h index 42967093ab..41d3599aca 100644 --- a/cutil/cutil.h +++ b/cutil/cutil.h @@ -56,7 +56,7 @@ Import original HP distribution #define CHARS_PER_LINE 500 -#if defined(__STDC__) || defined(__cplusplus) || MAC_OR_DOS +#if defined(__STDC__) || defined(__cplusplus) # define _ARGS(s) s #else # define _ARGS(s) () diff --git a/cutil/oldlist.cpp b/cutil/oldlist.cpp index 52c3725e09..67168a5cfe 100644 --- a/cutil/oldlist.cpp +++ b/cutil/oldlist.cpp @@ -85,9 +85,6 @@ #include "oldlist.h" #include "structures.h" #include -#if MAC_OR_DOS -#include -#endif /*---------------------------------------------------------------------- M a c r o s