Skip to content

Commit

Permalink
Misc tidying up
Browse files Browse the repository at this point in the history
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@239 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
theraysmith committed Jun 2, 2009
1 parent 98204f0 commit a5ad60c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 86 deletions.
2 changes: 1 addition & 1 deletion ccutil/clst.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ inline void *CLIST_ITERATOR::move_to_first() {
current = list->First ();
prev = list->last;
next = current != NULL ? current->next : NULL;
return current->data;
return current != NULL ? current->data : NULL;
}


Expand Down
5 changes: 5 additions & 0 deletions ccutil/serialis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ DLLSYM double de_serialise_FLOAT64(FILE *f) {
return the_float;
}

// Byte swap an inT64 or uinT64.
DLLSYM uinT64 reverse64(uinT64 num) {
return ((uinT64)reverse32((uinT32)(num & 0xffffffff)) << 32)
| reverse32((uinT32)((num >> 32) & 0xffffffff));
}

/**********************************************************************
* reverse32
Expand Down
10 changes: 4 additions & 6 deletions ccutil/serialis.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ extern DLLSYM void serialise_INT32(FILE *f, inT32 the_int);
extern DLLSYM inT32 de_serialise_INT32(FILE *f);
extern DLLSYM void serialise_FLOAT64(FILE *f, double the_float);
extern DLLSYM double de_serialise_FLOAT64(FILE *f);
extern DLLSYM uinT32 reverse32( //switch endian
uinT32 num //number to fix
);
extern DLLSYM uinT16 reverse16( //switch endian
uinT16 num //number to fix
);
// Switch endinan.
extern DLLSYM uinT64 reverse64(uinT64);
extern DLLSYM uinT32 reverse32(uinT32);
extern DLLSYM uinT16 reverse16(uinT16);

/***********************************************************************
QUOTE_IT MACRO DEFINITION
Expand Down
7 changes: 4 additions & 3 deletions ccutil/strngs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,10 @@ STRING & STRING::operator=(const char* cstr) {
this_header->used_ = len;
}
else {
// preserve old behavior
*GetCStr() = '\0';
this_header->used_ = 1;
// Reallocate to zero capacity buffer, consistent with the corresponding
// copy constructor.
DiscardData();
AllocData(0, 0);
}

CHECK_INVARIANT(this);
Expand Down
28 changes: 0 additions & 28 deletions cutil/emalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,9 @@ void *Erealloc(void *ptr, size_t size);

void Efree(void *ptr);

/*
#if defined(__STDC__) || defined(__cplusplus)
# define _ARGS(s) s
#else
# define _ARGS(s) ()
#endif*/

/* emalloc.c
void *Emalloc
_ARGS((size_t Size));
void *Erealloc
_ARGS((void *ptr,
size_t size));
void Efree
_ARGS((void *ptr));
#undef _ARGS
*/

/**----------------------------------------------------------------------------
Global Data Definitions and Declarations
----------------------------------------------------------------------------**/

//extern void* c_alloc_struct();
//#define alloc_struct c_alloc_struct
/*extern void c_free_struct(void*
deadstruct, //structure to free
inT32 count, //no of bytes
const char* name //class name
);*/
//#define free_struct c_free_struct
#endif
30 changes: 10 additions & 20 deletions cutil/freelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,14 @@
** limitations under the License.
**************************************************************************/
#include "freelist.h"
#include "danerror.h"
#include "callcpp.h"

#include <memory.h>

static int mem_alloc_counter = 0;
#include "danerror.h"
#include "memry.h"
#include "tprintf.h"

/**********************************************************************
* memalloc_p
*
* Memory allocator with protection.
**********************************************************************/
int *memalloc_p(int size) {
mem_alloc_counter++;
if (!size)
DoError (0, "Allocation of 0 bytes");
return ((int *) c_alloc_mem_p (size));
}
static int mem_alloc_counter = 0;


/**********************************************************************
Expand All @@ -37,7 +27,7 @@ int *memalloc_p(int size) {
**********************************************************************/
int *memalloc(int size) {
mem_alloc_counter++;
return ((int *) c_alloc_mem (size));
return ((int *) alloc_mem (size));
}


Expand All @@ -51,9 +41,9 @@ int *memrealloc(void *ptr, int size, int oldsize) {
int *newbuf;

shiftsize = size > oldsize ? oldsize : size;
newbuf = (int *) c_alloc_mem (size);
newbuf = (int *) alloc_mem (size);
memcpy(newbuf, ptr, shiftsize);
c_free_mem(ptr);
free_mem(ptr);
return newbuf;
}

Expand All @@ -65,11 +55,11 @@ int *memrealloc(void *ptr, int size, int oldsize) {
**********************************************************************/
void memfree(void *element) {
if (element) {
c_free_mem(element);
free_mem(element);
mem_alloc_counter--;
}
else {
cprintf ("%d MEM_ALLOC's used\n", mem_alloc_counter);
tprintf ("%d MEM_ALLOC's used\n", mem_alloc_counter);
DoError (0, "Memfree of NULL pointer");
}
}
Expand All @@ -81,5 +71,5 @@ void memfree(void *element) {
* Do nothing.
**********************************************************************/
void mem_tidy(int level) {
c_check_mem ("Old tidy", level);
check_mem ("Old tidy", level);
}
32 changes: 4 additions & 28 deletions cutil/freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,12 @@
/*----------------------------------------------------------------------
F u n c t i o n s
----------------------------------------------------------------------*/
int *memalloc_p(int size);
int *memalloc(int size);

int *memalloc(int size);
int *memrealloc(void *ptr, int size, int oldsize);

int *memrealloc(void *ptr, int size, int oldsize);
void memfree(void *element);

void memfree(void *element);
void mem_tidy(int level);

void mem_tidy(int level);

/*
#if defined(__STDC__) || defined(__cplusplus)
# define _ARGS(s) s
#else
# define _ARGS(s) ()
#endif*/

/* freelist.c
int *memalloc_p
_ARGS((int size));
int *memalloc
_ARGS((int size));
void memfree
_ARGS((void *element));
void mem_tidy
_ARGS((void));
#undef _ARGS
*/
#endif

0 comments on commit a5ad60c

Please sign in to comment.