Skip to content

Commit dc06621

Browse files
committed
opencl: Replace NULL by nullptr
Remove also some unneeded nullptr assignments. Signed-off-by: Stefan Weil <[email protected]>
1 parent 397bcc6 commit dc06621

File tree

2 files changed

+228
-234
lines changed

2 files changed

+228
-234
lines changed

opencl/opencl_device_selection.h

+43-49
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ typedef struct {
6868
typedef ds_status (*ds_score_release)(void* score);
6969
static ds_status releaseDSProfile(ds_profile* profile, ds_score_release sr) {
7070
ds_status status = DS_SUCCESS;
71-
if (profile!=NULL) {
72-
if (profile->devices!=NULL && sr!=NULL) {
71+
if (profile!=nullptr) {
72+
if (profile->devices!=nullptr && sr!=nullptr) {
7373
unsigned int i;
7474
for (i = 0; i < profile->numDevices; i++) {
7575
free(profile->devices[i].oclDeviceName);
@@ -89,51 +89,50 @@ static ds_status releaseDSProfile(ds_profile* profile, ds_score_release sr) {
8989
static ds_status initDSProfile(ds_profile** p, const char* version) {
9090
int numDevices;
9191
cl_uint numPlatforms;
92-
cl_platform_id* platforms = NULL;
93-
cl_device_id* devices = NULL;
92+
cl_platform_id* platforms = nullptr;
93+
cl_device_id* devices = nullptr;
9494
ds_status status = DS_SUCCESS;
95-
ds_profile* profile = NULL;
9695
unsigned int next;
9796
unsigned int i;
9897

99-
if (p == NULL)
98+
if (p == nullptr)
10099
return DS_INVALID_PROFILE;
101100

102-
profile = (ds_profile*)malloc(sizeof(ds_profile));
103-
if (profile == NULL)
101+
ds_profile* profile = (ds_profile*)malloc(sizeof(ds_profile));
102+
if (profile == nullptr)
104103
return DS_MEMORY_ERROR;
105104

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

108-
clGetPlatformIDs(0, NULL, &numPlatforms);
107+
clGetPlatformIDs(0, nullptr, &numPlatforms);
109108
if (numPlatforms == 0)
110109
goto cleanup;
111110

112111
platforms = (cl_platform_id*)malloc(numPlatforms*sizeof(cl_platform_id));
113-
if (platforms == NULL) {
112+
if (platforms == nullptr) {
114113
status = DS_MEMORY_ERROR;
115114
goto cleanup;
116115
}
117-
clGetPlatformIDs(numPlatforms, platforms, NULL);
116+
clGetPlatformIDs(numPlatforms, platforms, nullptr);
118117

119118
numDevices = 0;
120119
for (i = 0; i < (unsigned int)numPlatforms; i++) {
121120
cl_uint num;
122-
clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &num);
121+
clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, nullptr, &num);
123122
numDevices+=num;
124123
}
125124
if (numDevices == 0)
126125
goto cleanup;
127126

128127
devices = (cl_device_id*)malloc(numDevices*sizeof(cl_device_id));
129-
if (devices == NULL) {
128+
if (devices == nullptr) {
130129
status = DS_MEMORY_ERROR;
131130
goto cleanup;
132131
}
133132

134133
profile->numDevices = numDevices+1; // +1 to numDevices to include the native CPU
135134
profile->devices = (ds_device*)malloc(profile->numDevices*sizeof(ds_device));
136-
if (profile->devices == NULL) {
135+
if (profile->devices == nullptr) {
137136
profile->numDevices = 0;
138137
status = DS_MEMORY_ERROR;
139138
goto cleanup;
@@ -153,13 +152,13 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
153152
profile->devices[next].oclDeviceID = devices[j];
154153

155154
clGetDeviceInfo(profile->devices[next].oclDeviceID, CL_DEVICE_NAME
156-
, DS_DEVICE_NAME_LENGTH, &buffer, NULL);
155+
, DS_DEVICE_NAME_LENGTH, &buffer, nullptr);
157156
length = strlen(buffer);
158157
profile->devices[next].oclDeviceName = (char*)malloc(length+1);
159158
memcpy(profile->devices[next].oclDeviceName, buffer, length+1);
160159

161160
clGetDeviceInfo(profile->devices[next].oclDeviceID, CL_DRIVER_VERSION
162-
, DS_DEVICE_NAME_LENGTH, &buffer, NULL);
161+
, DS_DEVICE_NAME_LENGTH, &buffer, nullptr);
163162
length = strlen(buffer);
164163
profile->devices[next].oclDriverVersion = (char*)malloc(length+1);
165164
memcpy(profile->devices[next].oclDriverVersion, buffer, length+1);
@@ -202,10 +201,10 @@ static ds_status profileDevices(ds_profile* profile,
202201
unsigned int i;
203202
unsigned int updates = 0;
204203

205-
if (profile == NULL) {
204+
if (profile == nullptr) {
206205
return DS_INVALID_PROFILE;
207206
}
208-
if (evaluator == NULL) {
207+
if (evaluator == nullptr) {
209208
return DS_INVALID_PERF_EVALUATOR;
210209
}
211210

@@ -214,7 +213,7 @@ static ds_status profileDevices(ds_profile* profile,
214213

215214
switch (type) {
216215
case DS_EVALUATE_NEW_ONLY:
217-
if (profile->devices[i].score != NULL)
216+
if (profile->devices[i].score != nullptr)
218217
break;
219218
// else fall through
220219
case DS_EVALUATE_ALL:
@@ -260,14 +259,12 @@ static ds_status writeProfileToFile(ds_profile* profile,
260259
ds_score_serializer serializer,
261260
const char* file) {
262261
ds_status status = DS_SUCCESS;
263-
FILE* profileFile = NULL;
264262

265-
266-
if (profile == NULL)
263+
if (profile == nullptr)
267264
return DS_INVALID_PROFILE;
268265

269-
profileFile = fopen(file, "wb");
270-
if (profileFile==NULL) {
266+
FILE* profileFile = fopen(file, "wb");
267+
if (profileFile==nullptr) {
271268
status = DS_FILE_ERROR;
272269
}
273270
else {
@@ -330,7 +327,7 @@ static ds_status writeProfileToFile(ds_profile* profile,
330327
fwrite(DS_TAG_SCORE, sizeof(char), strlen(DS_TAG_SCORE), profileFile);
331328
status = serializer(profile->devices+i, &serializedScore,
332329
&serializedScoreSize);
333-
if (status == DS_SUCCESS && serializedScore!=NULL && serializedScoreSize > 0) {
330+
if (status == DS_SUCCESS && serializedScore!=nullptr && serializedScoreSize > 0) {
334331
fwrite(serializedScore, sizeof(char), serializedScoreSize, profileFile);
335332
free(serializedScore);
336333
}
@@ -346,23 +343,21 @@ static ds_status writeProfileToFile(ds_profile* profile,
346343

347344
static ds_status readProFile(const char* fileName, char** content,
348345
size_t* contentSize) {
349-
FILE * input = NULL;
350346
size_t size = 0;
351-
char* binary = NULL;
352347

353348
*contentSize = 0;
354-
*content = NULL;
349+
*content = nullptr;
355350

356-
input = fopen(fileName, "rb");
357-
if(input == NULL) {
351+
FILE* input = fopen(fileName, "rb");
352+
if(input == nullptr) {
358353
return DS_FILE_ERROR;
359354
}
360355

361356
fseek(input, 0L, SEEK_END);
362357
size = ftell(input);
363358
rewind(input);
364-
binary = (char*)malloc(size);
365-
if(binary == NULL) {
359+
char* binary = (char*)malloc(size);
360+
if(binary == nullptr) {
366361
fclose(input);
367362
return DS_FILE_ERROR;
368363
}
@@ -379,8 +374,7 @@ static const char* findString(const char* contentStart, const char* contentEnd,
379374
const char* string) {
380375
size_t stringLength;
381376
const char* currentPosition;
382-
const char* found;
383-
found = NULL;
377+
const char* found = nullptr;
384378
stringLength = strlen(string);
385379
currentPosition = contentStart;
386380
for(currentPosition = contentStart; currentPosition < contentEnd; currentPosition++) {
@@ -405,11 +399,11 @@ static ds_status readProfileFromFile(ds_profile* profile,
405399
const char* file) {
406400

407401
ds_status status = DS_SUCCESS;
408-
char* contentStart = NULL;
409-
const char* contentEnd = NULL;
402+
char* contentStart = nullptr;
403+
const char* contentEnd = nullptr;
410404
size_t contentSize;
411405

412-
if (profile==NULL)
406+
if (profile==nullptr)
413407
return DS_INVALID_PROFILE;
414408

415409
status = readProFile(file, &contentStart, &contentSize);
@@ -425,14 +419,14 @@ static ds_status readProfileFromFile(ds_profile* profile,
425419

426420
// parse the version string
427421
dataStart = findString(currentPosition, contentEnd, DS_TAG_VERSION);
428-
if (dataStart == NULL) {
422+
if (dataStart == nullptr) {
429423
status = DS_PROFILE_FILE_ERROR;
430424
goto cleanup;
431425
}
432426
dataStart += strlen(DS_TAG_VERSION);
433427

434428
dataEnd = findString(dataStart, contentEnd, DS_TAG_VERSION_END);
435-
if (dataEnd==NULL) {
429+
if (dataEnd==nullptr) {
436430
status = DS_PROFILE_FILE_ERROR;
437431
goto cleanup;
438432
}
@@ -464,27 +458,27 @@ static ds_status readProfileFromFile(ds_profile* profile,
464458
const char* deviceDriverEnd;
465459

466460
dataStart = findString(currentPosition, contentEnd, DS_TAG_DEVICE);
467-
if (dataStart==NULL) {
461+
if (dataStart==nullptr) {
468462
// nothing useful remain, quit...
469463
break;
470464
}
471465
dataStart+=strlen(DS_TAG_DEVICE);
472466
dataEnd = findString(dataStart, contentEnd, DS_TAG_DEVICE_END);
473-
if (dataEnd==NULL) {
467+
if (dataEnd==nullptr) {
474468
status = DS_PROFILE_FILE_ERROR;
475469
goto cleanup;
476470
}
477471

478472
// parse the device type
479473
deviceTypeStart = findString(dataStart, contentEnd, DS_TAG_DEVICE_TYPE);
480-
if (deviceTypeStart==NULL) {
474+
if (deviceTypeStart==nullptr) {
481475
status = DS_PROFILE_FILE_ERROR;
482476
goto cleanup;
483477
}
484478
deviceTypeStart+=strlen(DS_TAG_DEVICE_TYPE);
485479
deviceTypeEnd = findString(deviceTypeStart, contentEnd,
486480
DS_TAG_DEVICE_TYPE_END);
487-
if (deviceTypeEnd==NULL) {
481+
if (deviceTypeEnd==nullptr) {
488482
status = DS_PROFILE_FILE_ERROR;
489483
goto cleanup;
490484
}
@@ -495,29 +489,29 @@ static ds_status readProfileFromFile(ds_profile* profile,
495489
if (deviceType == DS_DEVICE_OPENCL_DEVICE) {
496490

497491
deviceNameStart = findString(dataStart, contentEnd, DS_TAG_DEVICE_NAME);
498-
if (deviceNameStart==NULL) {
492+
if (deviceNameStart==nullptr) {
499493
status = DS_PROFILE_FILE_ERROR;
500494
goto cleanup;
501495
}
502496
deviceNameStart+=strlen(DS_TAG_DEVICE_NAME);
503497
deviceNameEnd = findString(deviceNameStart, contentEnd,
504498
DS_TAG_DEVICE_NAME_END);
505-
if (deviceNameEnd==NULL) {
499+
if (deviceNameEnd==nullptr) {
506500
status = DS_PROFILE_FILE_ERROR;
507501
goto cleanup;
508502
}
509503

510504

511505
deviceDriverStart = findString(dataStart, contentEnd,
512506
DS_TAG_DEVICE_DRIVER_VERSION);
513-
if (deviceDriverStart==NULL) {
507+
if (deviceDriverStart==nullptr) {
514508
status = DS_PROFILE_FILE_ERROR;
515509
goto cleanup;
516510
}
517511
deviceDriverStart+=strlen(DS_TAG_DEVICE_DRIVER_VERSION);
518512
deviceDriverEnd = findString(deviceDriverStart, contentEnd,
519513
DS_TAG_DEVICE_DRIVER_VERSION_END);
520-
if (deviceDriverEnd ==NULL) {
514+
if (deviceDriverEnd ==nullptr) {
521515
status = DS_PROFILE_FILE_ERROR;
522516
goto cleanup;
523517
}
@@ -538,7 +532,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
538532
&& strncmp(profile->devices[i].oclDriverVersion, deviceDriverStart,
539533
driverVersionLength)==0) {
540534
deviceScoreStart = findString(dataStart, contentEnd, DS_TAG_SCORE);
541-
if (deviceNameStart==NULL) {
535+
if (deviceNameStart==nullptr) {
542536
status = DS_PROFILE_FILE_ERROR;
543537
goto cleanup;
544538
}
@@ -560,7 +554,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
560554
for (i = 0; i < profile->numDevices; i++) {
561555
if (profile->devices[i].type == DS_DEVICE_NATIVE_CPU) {
562556
deviceScoreStart = findString(dataStart, contentEnd, DS_TAG_SCORE);
563-
if (deviceScoreStart==NULL) {
557+
if (deviceScoreStart==nullptr) {
564558
status = DS_PROFILE_FILE_ERROR;
565559
goto cleanup;
566560
}

0 commit comments

Comments
 (0)