Skip to content

Commit

Permalink
strngs: Replace alloc_mem, free_mem by standard functions
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Jun 25, 2018
1 parent 8953f41 commit 20e243d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ccutil/strngs.cpp
Expand Up @@ -19,10 +19,10 @@

#include "strngs.h"
#include <cassert> // for assert
#include <cstdlib> // for malloc, free
#include "errcode.h" // for ASSERT_HOST
#include "genericvector.h" // for GenericVector
#include "helpers.h" // for ReverseN
#include "memry.h" // for alloc_string, free_string
#include "serialis.h" // for TFile

using tesseract::TFile;
Expand Down Expand Up @@ -51,7 +51,7 @@ const int kMaxDoubleSize = 16;
const int kMinCapacity = 16;

char* STRING::AllocData(int used, int capacity) {
data_ = (STRING_HEADER *)alloc_string(capacity + sizeof(STRING_HEADER));
data_ = (STRING_HEADER *)malloc(capacity + sizeof(STRING_HEADER));

// header is the metadata for this memory block
STRING_HEADER* header = GetHeader();
Expand All @@ -61,7 +61,8 @@ char* STRING::AllocData(int used, int capacity) {
}

void STRING::DiscardData() {
free_string((char *)data_);
free(data_);
data_ = nullptr;
}

// This is a private method; ensure FixHeader is called (or used_ is well defined)
Expand All @@ -78,7 +79,7 @@ char* STRING::ensure_cstr(int32_t min_capacity) {
min_capacity = 2 * orig_header->capacity_;

int alloc = sizeof(STRING_HEADER) + min_capacity;
STRING_HEADER* new_header = (STRING_HEADER*)(alloc_string(alloc));
STRING_HEADER* new_header = (STRING_HEADER*)(malloc(alloc));

memcpy(&new_header[1], GetCStr(), orig_header->used_);
new_header->capacity_ = min_capacity;
Expand Down

0 comments on commit 20e243d

Please sign in to comment.