Skip to content

Commit

Permalink
More clang-tidy from previous commits
Browse files Browse the repository at this point in the history
  • Loading branch information
theraysmith committed Dec 6, 2016
1 parent 025689f commit d55f462
Show file tree
Hide file tree
Showing 9 changed files with 412 additions and 531 deletions.
4 changes: 1 addition & 3 deletions api/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,7 @@ class TESS_API TessBaseAPI {
int** y1,
PAGE_RES* page_res);

TESS_LOCAL const PAGE_RES* GetPageRes() const {
return page_res_;
}
TESS_LOCAL const PAGE_RES* GetPageRes() const { return page_res_; }
/* @} */


Expand Down
8 changes: 4 additions & 4 deletions ccmain/thresholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ void ImageThresholder::OtsuThresholdRectToPix(Pix* src_pix,
OpenclDevice od;
if ((num_channels == 4 || num_channels == 1) &&
od.selectedDeviceIsOpenCL() && rect_top_ == 0 && rect_left_ == 0 ) {
od.ThresholdRectToPixOCL((unsigned char*)pixGetData(src_pix),
num_channels, pixGetWpl(src_pix) * 4,
thresholds, hi_values, out_pix /*pix_OCL*/,
rect_height_, rect_width_, rect_top_, rect_left_);
od.ThresholdRectToPixOCL((unsigned char*)pixGetData(src_pix), num_channels,
pixGetWpl(src_pix) * 4, thresholds, hi_values,
out_pix /*pix_OCL*/, rect_height_, rect_width_,
rect_top_, rect_left_);
} else {
#endif
ThresholdRectToPix(src_pix, num_channels, thresholds, hi_values, out_pix);
Expand Down
4 changes: 1 addition & 3 deletions ccutil/strngs.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ class TESS_API STRING
}

// returns the string data part of storage
inline char* GetCStr() {
return ((char *)data_) + sizeof(STRING_HEADER);
}
inline char* GetCStr() { return ((char*)data_) + sizeof(STRING_HEADER); }

inline const char* GetCStr() const {
return ((const char *)data_) + sizeof(STRING_HEADER);
Expand Down
3 changes: 2 additions & 1 deletion lstm/lstmtrainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ void LSTMTrainer::StartSubtrainer(STRING* log_msg) {
// Reduce learning rate so it doesn't diverge this time.
sub_trainer_->ReduceLearningRates(this, log_msg);
// If it fails again, we will wait twice as long before reverting again.
int stall_offset = learning_iteration() - sub_trainer_->learning_iteration();
int stall_offset =
learning_iteration() - sub_trainer_->learning_iteration();
stall_iteration_ = learning_iteration() + 2 * stall_offset;
sub_trainer_->stall_iteration_ = stall_iteration_;
// Re-save the best trainer with the new learning rates and stall iteration.
Expand Down
3 changes: 2 additions & 1 deletion lstm/lstmtrainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ class LSTMTrainer : public LSTMRecognizer {
// previously setup UNICHARSET and UnicharCompress.
// ctc_mode controls how the truth text is mapped to the network targets.
// Note: Call before InitNetwork!
void InitCharSet(const UNICHARSET& unicharset, const UnicharCompress& recoder);
void InitCharSet(const UNICHARSET& unicharset,
const UnicharCompress& recoder);

// Initializes the trainer with a network_spec in the network description
// net_flags control network behavior according to the NetworkFlags enum.
Expand Down
65 changes: 31 additions & 34 deletions opencl/opencl_device_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ typedef struct {
typedef ds_status (*ds_score_release)(void* score);
static ds_status releaseDSProfile(ds_profile* profile, ds_score_release sr) {
ds_status status = DS_SUCCESS;
if (profile!=nullptr) {
if (profile->devices!=nullptr && sr!=nullptr) {
if (profile != nullptr) {
if (profile->devices != nullptr && sr != nullptr) {
unsigned int i;
for (i = 0; i < profile->numDevices; i++) {
free(profile->devices[i].oclDeviceName);
Expand All @@ -90,18 +90,16 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
int numDevices;
cl_uint numPlatforms;
cl_platform_id* platforms = nullptr;
cl_device_id* devices = nullptr;
cl_device_id* devices = nullptr;
ds_status status = DS_SUCCESS;
unsigned int next;
unsigned int i;

if (p == nullptr)
return DS_INVALID_PROFILE;
if (p == nullptr) return DS_INVALID_PROFILE;

ds_profile* profile = (ds_profile*)malloc(sizeof(ds_profile));
if (profile == nullptr)
return DS_MEMORY_ERROR;

if (profile == nullptr) return DS_MEMORY_ERROR;

memset(profile, 0, sizeof(ds_profile));

clGetPlatformIDs(0, nullptr, &numPlatforms);
Expand Down Expand Up @@ -131,7 +129,8 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
}

profile->numDevices = numDevices+1; // +1 to numDevices to include the native CPU
profile->devices = (ds_device*)malloc(profile->numDevices*sizeof(ds_device));
profile->devices =
(ds_device*)malloc(profile->numDevices * sizeof(ds_device));
if (profile->devices == nullptr) {
profile->numDevices = 0;
status = DS_MEMORY_ERROR;
Expand All @@ -151,14 +150,14 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
profile->devices[next].type = DS_DEVICE_OPENCL_DEVICE;
profile->devices[next].oclDeviceID = devices[j];

clGetDeviceInfo(profile->devices[next].oclDeviceID, CL_DEVICE_NAME
, DS_DEVICE_NAME_LENGTH, &buffer, nullptr);
clGetDeviceInfo(profile->devices[next].oclDeviceID, CL_DEVICE_NAME,
DS_DEVICE_NAME_LENGTH, &buffer, nullptr);
length = strlen(buffer);
profile->devices[next].oclDeviceName = (char*)malloc(length+1);
memcpy(profile->devices[next].oclDeviceName, buffer, length+1);

clGetDeviceInfo(profile->devices[next].oclDeviceID, CL_DRIVER_VERSION
, DS_DEVICE_NAME_LENGTH, &buffer, nullptr);
clGetDeviceInfo(profile->devices[next].oclDeviceID, CL_DRIVER_VERSION,
DS_DEVICE_NAME_LENGTH, &buffer, nullptr);
length = strlen(buffer);
profile->devices[next].oclDriverVersion = (char*)malloc(length+1);
memcpy(profile->devices[next].oclDriverVersion, buffer, length+1);
Expand Down Expand Up @@ -213,8 +212,7 @@ static ds_status profileDevices(ds_profile* profile,

switch (type) {
case DS_EVALUATE_NEW_ONLY:
if (profile->devices[i].score != nullptr)
break;
if (profile->devices[i].score != nullptr) break;
// else fall through
case DS_EVALUATE_ALL:
evaluatorStatus = evaluator(profile->devices+i, evaluatorData);
Expand Down Expand Up @@ -260,11 +258,10 @@ static ds_status writeProfileToFile(ds_profile* profile,
const char* file) {
ds_status status = DS_SUCCESS;

if (profile == nullptr)
return DS_INVALID_PROFILE;
if (profile == nullptr) return DS_INVALID_PROFILE;

FILE* profileFile = fopen(file, "wb");
if (profileFile==nullptr) {
if (profileFile == nullptr) {
status = DS_FILE_ERROR;
}
else {
Expand Down Expand Up @@ -327,7 +324,8 @@ static ds_status writeProfileToFile(ds_profile* profile,
fwrite(DS_TAG_SCORE, sizeof(char), strlen(DS_TAG_SCORE), profileFile);
status = serializer(profile->devices+i, &serializedScore,
&serializedScoreSize);
if (status == DS_SUCCESS && serializedScore!=nullptr && serializedScoreSize > 0) {
if (status == DS_SUCCESS && serializedScore != nullptr &&
serializedScoreSize > 0) {
fwrite(serializedScore, sizeof(char), serializedScoreSize, profileFile);
free(serializedScore);
}
Expand All @@ -349,15 +347,15 @@ static ds_status readProFile(const char* fileName, char** content,
*content = nullptr;

FILE* input = fopen(fileName, "rb");
if(input == nullptr) {
if (input == nullptr) {
return DS_FILE_ERROR;
}

fseek(input, 0L, SEEK_END);
size = ftell(input);
rewind(input);
char* binary = (char*)malloc(size);
if(binary == nullptr) {
if (binary == nullptr) {
fclose(input);
return DS_FILE_ERROR;
}
Expand Down Expand Up @@ -403,8 +401,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
const char* contentEnd = nullptr;
size_t contentSize;

if (profile==nullptr)
return DS_INVALID_PROFILE;
if (profile == nullptr) return DS_INVALID_PROFILE;

status = readProFile(file, &contentStart, &contentSize);
if (status == DS_SUCCESS) {
Expand All @@ -426,7 +423,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
dataStart += strlen(DS_TAG_VERSION);

dataEnd = findString(dataStart, contentEnd, DS_TAG_VERSION_END);
if (dataEnd==nullptr) {
if (dataEnd == nullptr) {
status = DS_PROFILE_FILE_ERROR;
goto cleanup;
}
Expand Down Expand Up @@ -458,27 +455,27 @@ static ds_status readProfileFromFile(ds_profile* profile,
const char* deviceDriverEnd;

dataStart = findString(currentPosition, contentEnd, DS_TAG_DEVICE);
if (dataStart==nullptr) {
if (dataStart == nullptr) {
// nothing useful remain, quit...
break;
}
dataStart+=strlen(DS_TAG_DEVICE);
dataEnd = findString(dataStart, contentEnd, DS_TAG_DEVICE_END);
if (dataEnd==nullptr) {
if (dataEnd == nullptr) {
status = DS_PROFILE_FILE_ERROR;
goto cleanup;
}

// parse the device type
deviceTypeStart = findString(dataStart, contentEnd, DS_TAG_DEVICE_TYPE);
if (deviceTypeStart==nullptr) {
if (deviceTypeStart == nullptr) {
status = DS_PROFILE_FILE_ERROR;
goto cleanup;
}
deviceTypeStart+=strlen(DS_TAG_DEVICE_TYPE);
deviceTypeEnd = findString(deviceTypeStart, contentEnd,
DS_TAG_DEVICE_TYPE_END);
if (deviceTypeEnd==nullptr) {
if (deviceTypeEnd == nullptr) {
status = DS_PROFILE_FILE_ERROR;
goto cleanup;
}
Expand All @@ -489,29 +486,29 @@ static ds_status readProfileFromFile(ds_profile* profile,
if (deviceType == DS_DEVICE_OPENCL_DEVICE) {

deviceNameStart = findString(dataStart, contentEnd, DS_TAG_DEVICE_NAME);
if (deviceNameStart==nullptr) {
if (deviceNameStart == nullptr) {
status = DS_PROFILE_FILE_ERROR;
goto cleanup;
}
deviceNameStart+=strlen(DS_TAG_DEVICE_NAME);
deviceNameEnd = findString(deviceNameStart, contentEnd,
DS_TAG_DEVICE_NAME_END);
if (deviceNameEnd==nullptr) {
if (deviceNameEnd == nullptr) {
status = DS_PROFILE_FILE_ERROR;
goto cleanup;
}


deviceDriverStart = findString(dataStart, contentEnd,
DS_TAG_DEVICE_DRIVER_VERSION);
if (deviceDriverStart==nullptr) {
if (deviceDriverStart == nullptr) {
status = DS_PROFILE_FILE_ERROR;
goto cleanup;
}
deviceDriverStart+=strlen(DS_TAG_DEVICE_DRIVER_VERSION);
deviceDriverEnd = findString(deviceDriverStart, contentEnd,
DS_TAG_DEVICE_DRIVER_VERSION_END);
if (deviceDriverEnd ==nullptr) {
if (deviceDriverEnd == nullptr) {
status = DS_PROFILE_FILE_ERROR;
goto cleanup;
}
Expand All @@ -532,7 +529,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
&& strncmp(profile->devices[i].oclDriverVersion, deviceDriverStart,
driverVersionLength)==0) {
deviceScoreStart = findString(dataStart, contentEnd, DS_TAG_SCORE);
if (deviceNameStart==nullptr) {
if (deviceNameStart == nullptr) {
status = DS_PROFILE_FILE_ERROR;
goto cleanup;
}
Expand All @@ -554,7 +551,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
for (i = 0; i < profile->numDevices; i++) {
if (profile->devices[i].type == DS_DEVICE_NATIVE_CPU) {
deviceScoreStart = findString(dataStart, contentEnd, DS_TAG_SCORE);
if (deviceScoreStart==nullptr) {
if (deviceScoreStart == nullptr) {
status = DS_PROFILE_FILE_ERROR;
goto cleanup;
}
Expand Down
Loading

0 comments on commit d55f462

Please sign in to comment.