Use uint32_t instead of int for the dynamic API
https://code.google.com/p/cld2/issues/detail?id=12 git-svn-id: https://cld2.googlecode.com/svn/trunk@160 b252ecd4-b096-bf77-eb8e-91563289f87e
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
@@ -40,7 +41,7 @@ CLD2DynamicData::FileHeader* loadHeaderFromFile(const char* fileName) {
|
||||
}
|
||||
|
||||
CLD2DynamicData::FileHeader* loadHeaderFromRaw(const void* basePointer,
|
||||
const int length) {
|
||||
const uint32_t length) {
|
||||
return loadInternal(NULL, basePointer, length);
|
||||
}
|
||||
|
||||
@@ -52,7 +53,7 @@ CLD2DynamicData::FileHeader* loadHeaderFromRaw(const void* basePointer,
|
||||
memcpy(&(header->field), (((char*)(basePointer)) + bytesRead), 4);\
|
||||
bytesRead += 4;\
|
||||
}
|
||||
CLD2DynamicData::FileHeader* loadInternal(FILE* inFile, const void* basePointer, const int length) {
|
||||
CLD2DynamicData::FileHeader* loadInternal(FILE* inFile, const void* basePointer, const uint32_t length) {
|
||||
const bool sourceIsFile = (inFile != NULL);
|
||||
int bytesRead = 0;
|
||||
CLD2DynamicData::FileHeader* header = new CLD2DynamicData::FileHeader;
|
||||
@@ -140,7 +141,7 @@ CLD2DynamicData::FileHeader* loadInternal(FILE* inFile, const void* basePointer,
|
||||
}
|
||||
|
||||
void unloadDataFile(CLD2::ScoringTables** scoringTables,
|
||||
void** mmapAddress, int* mmapLength) {
|
||||
void** mmapAddress, uint32_t* mmapLength) {
|
||||
CLD2DynamicDataLoader::unloadDataRaw(scoringTables);
|
||||
munmap(*mmapAddress, *mmapLength);
|
||||
*mmapAddress = NULL;
|
||||
@@ -157,7 +158,7 @@ void unloadDataRaw(CLD2::ScoringTables** scoringTables) {
|
||||
}
|
||||
|
||||
CLD2::ScoringTables* loadDataFile(const char* fileName,
|
||||
void** mmapAddressOut, int* mmapLengthOut) {
|
||||
void** mmapAddressOut, uint32_t* mmapLengthOut) {
|
||||
CLD2DynamicData::FileHeader* header = loadHeaderFromFile(fileName);
|
||||
if (header == NULL) {
|
||||
return NULL;
|
||||
@@ -175,12 +176,12 @@ CLD2::ScoringTables* loadDataFile(const char* fileName,
|
||||
return loadDataInternal(header, mapped, header->totalFileSizeBytes);
|
||||
}
|
||||
|
||||
CLD2::ScoringTables* loadDataRaw(const void* basePointer, const int length) {
|
||||
CLD2::ScoringTables* loadDataRaw(const void* basePointer, const uint32_t length) {
|
||||
CLD2DynamicData::FileHeader* header = loadHeaderFromRaw(basePointer, length);
|
||||
return loadDataInternal(header, basePointer, length);
|
||||
}
|
||||
|
||||
CLD2::ScoringTables* loadDataInternal(CLD2DynamicData::FileHeader* header, const void* basePointer, const int length) {
|
||||
CLD2::ScoringTables* loadDataInternal(CLD2DynamicData::FileHeader* header, const void* basePointer, const uint32_t length) {
|
||||
// 1. UTF8 Object
|
||||
const CLD2::uint8* state_table = static_cast<const CLD2::uint8*>(basePointer) +
|
||||
header->startOf_utf8PropObj_state_table;
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#ifndef CLD2_INTERNAL_CLD2_DYNAMIC_DATA_LOADER_H_
|
||||
#define CLD2_INTERNAL_CLD2_DYNAMIC_DATA_LOADER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "scoreonescriptspan.h"
|
||||
#include "cld2_dynamic_data.h"
|
||||
|
||||
@@ -29,11 +30,11 @@ CLD2DynamicData::FileHeader* loadHeaderFromFile(const char* fileName);
|
||||
// The header returned is dynamically allocated; you must 'delete' the array
|
||||
// of TableHeaders as well as the returned FileHeader* when done.
|
||||
CLD2DynamicData::FileHeader* loadHeaderFromRaw(
|
||||
const void* basePointer, const int length);
|
||||
const void* basePointer, const uint32_t length);
|
||||
|
||||
// Not for public consumption.
|
||||
CLD2DynamicData::FileHeader* loadInternal(
|
||||
FILE* inFile, const void* basePointer, const int length);
|
||||
FILE* inFile, const void* basePointer, const uint32_t length);
|
||||
|
||||
// Load data directly into a ScoringTables structure using a private, read-only
|
||||
// mmap and return the newly-allocated structure.
|
||||
@@ -44,16 +45,16 @@ CLD2DynamicData::FileHeader* loadInternal(
|
||||
// It is up to the caller to delete the data at a later time using
|
||||
// unloadData(...).
|
||||
CLD2::ScoringTables* loadDataFile(const char* fileName,
|
||||
void** mmapAddressOut, int* mmapLengthOut);
|
||||
void** mmapAddressOut, uint32_t* mmapLengthOut);
|
||||
|
||||
// Load data directly into a ScoringTables structure from an arbitrary region
|
||||
// of memory, which is assumed to be a pointer to an mmap-ed region of memory
|
||||
// backed by a valid data file that could alternatively be read (if access
|
||||
// were allowed or desired) using loadDataFile(...).
|
||||
CLD2::ScoringTables* loadDataRaw(const void* basePointer, const int length);
|
||||
CLD2::ScoringTables* loadDataRaw(const void* basePointer, const uint32_t length);
|
||||
|
||||
// Not for public consumption.
|
||||
CLD2::ScoringTables* loadDataInternal(CLD2DynamicData::FileHeader* header, const void* basePointer, const int length);
|
||||
CLD2::ScoringTables* loadDataInternal(CLD2DynamicData::FileHeader* header, const void* basePointer, const uint32_t length);
|
||||
|
||||
// Given pointers to the data from a previous invocation of loadDataFile,
|
||||
// unloads the data safely - freeing and deleting any malloc'd/new'd objects.
|
||||
@@ -66,7 +67,7 @@ CLD2::ScoringTables* loadDataInternal(CLD2DynamicData::FileHeader* header, const
|
||||
// is an unfortunate mixture of new and malloc involved in building the
|
||||
// in-memory represtation of the data.
|
||||
void unloadDataFile(CLD2::ScoringTables** scoringTables,
|
||||
void** mmapAddress, int* mmapLength);
|
||||
void** mmapAddress, uint32_t* mmapLength);
|
||||
|
||||
// Given a pointer to the data from a previous invocation of loadDataRaw,
|
||||
// unloads the data safely just like unloadDataFile does. This method doesn't
|
||||
|
@@ -162,7 +162,7 @@ Usage:\n\
|
||||
|
||||
if (mode == 1 || mode == 2) { // dump || verify (so perform verification)
|
||||
void* mmapAddress = NULL;
|
||||
int mmapLength = 0;
|
||||
uint32_t mmapLength = 0;
|
||||
CLD2::ScoringTables* loadedData = CLD2DynamicDataLoader::loadDataFile(fileName, &mmapAddress, &mmapLength);
|
||||
|
||||
if (loadedData == NULL) {
|
||||
|
@@ -17,6 +17,7 @@
|
||||
// Updated 2014.01 for dual table lookup
|
||||
//
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
@@ -88,7 +89,7 @@ extern const short kAvgDeltaOctaScore[];
|
||||
static bool dataSourceIsFile = false;
|
||||
static ScoringTables* dynamicTables = NULL;
|
||||
static void* mmapAddress = NULL;
|
||||
static int mmapLength = 0;
|
||||
static uint32_t mmapLength = 0;
|
||||
|
||||
bool isDataLoaded() { return dynamicDataLoaded; }
|
||||
|
||||
@@ -102,7 +103,7 @@ extern const short kAvgDeltaOctaScore[];
|
||||
dynamicDataLoaded = true;
|
||||
};
|
||||
|
||||
void loadDataFromRawAddress(const void* rawAddress, const int length) {
|
||||
void loadDataFromRawAddress(const void* rawAddress, const uint32_t length) {
|
||||
if (isDataLoaded()) {
|
||||
unloadData();
|
||||
}
|
||||
|
Reference in New Issue
Block a user