@@ -68,8 +68,8 @@ typedef struct {
68
68
typedef ds_status (* ds_score_release )(void * score );
69
69
static ds_status releaseDSProfile (ds_profile * profile , ds_score_release sr ) {
70
70
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 ) {
73
73
unsigned int i ;
74
74
for (i = 0 ; i < profile -> numDevices ; i ++ ) {
75
75
free (profile -> devices [i ].oclDeviceName );
@@ -89,51 +89,50 @@ static ds_status releaseDSProfile(ds_profile* profile, ds_score_release sr) {
89
89
static ds_status initDSProfile (ds_profile * * p , const char * version ) {
90
90
int numDevices ;
91
91
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 ;
94
94
ds_status status = DS_SUCCESS ;
95
- ds_profile * profile = NULL ;
96
95
unsigned int next ;
97
96
unsigned int i ;
98
97
99
- if (p == NULL )
98
+ if (p == nullptr )
100
99
return DS_INVALID_PROFILE ;
101
100
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 )
104
103
return DS_MEMORY_ERROR ;
105
104
106
105
memset (profile , 0 , sizeof (ds_profile ));
107
106
108
- clGetPlatformIDs (0 , NULL , & numPlatforms );
107
+ clGetPlatformIDs (0 , nullptr , & numPlatforms );
109
108
if (numPlatforms == 0 )
110
109
goto cleanup ;
111
110
112
111
platforms = (cl_platform_id * )malloc (numPlatforms * sizeof (cl_platform_id ));
113
- if (platforms == NULL ) {
112
+ if (platforms == nullptr ) {
114
113
status = DS_MEMORY_ERROR ;
115
114
goto cleanup ;
116
115
}
117
- clGetPlatformIDs (numPlatforms , platforms , NULL );
116
+ clGetPlatformIDs (numPlatforms , platforms , nullptr );
118
117
119
118
numDevices = 0 ;
120
119
for (i = 0 ; i < (unsigned int )numPlatforms ; i ++ ) {
121
120
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 );
123
122
numDevices += num ;
124
123
}
125
124
if (numDevices == 0 )
126
125
goto cleanup ;
127
126
128
127
devices = (cl_device_id * )malloc (numDevices * sizeof (cl_device_id ));
129
- if (devices == NULL ) {
128
+ if (devices == nullptr ) {
130
129
status = DS_MEMORY_ERROR ;
131
130
goto cleanup ;
132
131
}
133
132
134
133
profile -> numDevices = numDevices + 1 ; // +1 to numDevices to include the native CPU
135
134
profile -> devices = (ds_device * )malloc (profile -> numDevices * sizeof (ds_device ));
136
- if (profile -> devices == NULL ) {
135
+ if (profile -> devices == nullptr ) {
137
136
profile -> numDevices = 0 ;
138
137
status = DS_MEMORY_ERROR ;
139
138
goto cleanup ;
@@ -153,13 +152,13 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
153
152
profile -> devices [next ].oclDeviceID = devices [j ];
154
153
155
154
clGetDeviceInfo (profile -> devices [next ].oclDeviceID , CL_DEVICE_NAME
156
- , DS_DEVICE_NAME_LENGTH , & buffer , NULL );
155
+ , DS_DEVICE_NAME_LENGTH , & buffer , nullptr );
157
156
length = strlen (buffer );
158
157
profile -> devices [next ].oclDeviceName = (char * )malloc (length + 1 );
159
158
memcpy (profile -> devices [next ].oclDeviceName , buffer , length + 1 );
160
159
161
160
clGetDeviceInfo (profile -> devices [next ].oclDeviceID , CL_DRIVER_VERSION
162
- , DS_DEVICE_NAME_LENGTH , & buffer , NULL );
161
+ , DS_DEVICE_NAME_LENGTH , & buffer , nullptr );
163
162
length = strlen (buffer );
164
163
profile -> devices [next ].oclDriverVersion = (char * )malloc (length + 1 );
165
164
memcpy (profile -> devices [next ].oclDriverVersion , buffer , length + 1 );
@@ -202,10 +201,10 @@ static ds_status profileDevices(ds_profile* profile,
202
201
unsigned int i ;
203
202
unsigned int updates = 0 ;
204
203
205
- if (profile == NULL ) {
204
+ if (profile == nullptr ) {
206
205
return DS_INVALID_PROFILE ;
207
206
}
208
- if (evaluator == NULL ) {
207
+ if (evaluator == nullptr ) {
209
208
return DS_INVALID_PERF_EVALUATOR ;
210
209
}
211
210
@@ -214,7 +213,7 @@ static ds_status profileDevices(ds_profile* profile,
214
213
215
214
switch (type ) {
216
215
case DS_EVALUATE_NEW_ONLY :
217
- if (profile -> devices [i ].score != NULL )
216
+ if (profile -> devices [i ].score != nullptr )
218
217
break ;
219
218
// else fall through
220
219
case DS_EVALUATE_ALL :
@@ -260,14 +259,12 @@ static ds_status writeProfileToFile(ds_profile* profile,
260
259
ds_score_serializer serializer ,
261
260
const char * file ) {
262
261
ds_status status = DS_SUCCESS ;
263
- FILE * profileFile = NULL ;
264
262
265
-
266
- if (profile == NULL )
263
+ if (profile == nullptr )
267
264
return DS_INVALID_PROFILE ;
268
265
269
- profileFile = fopen (file , "wb" );
270
- if (profileFile == NULL ) {
266
+ FILE * profileFile = fopen (file , "wb" );
267
+ if (profileFile == nullptr ) {
271
268
status = DS_FILE_ERROR ;
272
269
}
273
270
else {
@@ -330,7 +327,7 @@ static ds_status writeProfileToFile(ds_profile* profile,
330
327
fwrite (DS_TAG_SCORE , sizeof (char ), strlen (DS_TAG_SCORE ), profileFile );
331
328
status = serializer (profile -> devices + i , & serializedScore ,
332
329
& serializedScoreSize );
333
- if (status == DS_SUCCESS && serializedScore != NULL && serializedScoreSize > 0 ) {
330
+ if (status == DS_SUCCESS && serializedScore != nullptr && serializedScoreSize > 0 ) {
334
331
fwrite (serializedScore , sizeof (char ), serializedScoreSize , profileFile );
335
332
free (serializedScore );
336
333
}
@@ -346,23 +343,21 @@ static ds_status writeProfileToFile(ds_profile* profile,
346
343
347
344
static ds_status readProFile (const char * fileName , char * * content ,
348
345
size_t * contentSize ) {
349
- FILE * input = NULL ;
350
346
size_t size = 0 ;
351
- char * binary = NULL ;
352
347
353
348
* contentSize = 0 ;
354
- * content = NULL ;
349
+ * content = nullptr ;
355
350
356
- input = fopen (fileName , "rb" );
357
- if (input == NULL ) {
351
+ FILE * input = fopen (fileName , "rb" );
352
+ if (input == nullptr ) {
358
353
return DS_FILE_ERROR ;
359
354
}
360
355
361
356
fseek (input , 0L , SEEK_END );
362
357
size = ftell (input );
363
358
rewind (input );
364
- binary = (char * )malloc (size );
365
- if (binary == NULL ) {
359
+ char * binary = (char * )malloc (size );
360
+ if (binary == nullptr ) {
366
361
fclose (input );
367
362
return DS_FILE_ERROR ;
368
363
}
@@ -379,8 +374,7 @@ static const char* findString(const char* contentStart, const char* contentEnd,
379
374
const char * string ) {
380
375
size_t stringLength ;
381
376
const char * currentPosition ;
382
- const char * found ;
383
- found = NULL ;
377
+ const char * found = nullptr ;
384
378
stringLength = strlen (string );
385
379
currentPosition = contentStart ;
386
380
for (currentPosition = contentStart ; currentPosition < contentEnd ; currentPosition ++ ) {
@@ -405,11 +399,11 @@ static ds_status readProfileFromFile(ds_profile* profile,
405
399
const char * file ) {
406
400
407
401
ds_status status = DS_SUCCESS ;
408
- char * contentStart = NULL ;
409
- const char * contentEnd = NULL ;
402
+ char * contentStart = nullptr ;
403
+ const char * contentEnd = nullptr ;
410
404
size_t contentSize ;
411
405
412
- if (profile == NULL )
406
+ if (profile == nullptr )
413
407
return DS_INVALID_PROFILE ;
414
408
415
409
status = readProFile (file , & contentStart , & contentSize );
@@ -425,14 +419,14 @@ static ds_status readProfileFromFile(ds_profile* profile,
425
419
426
420
// parse the version string
427
421
dataStart = findString (currentPosition , contentEnd , DS_TAG_VERSION );
428
- if (dataStart == NULL ) {
422
+ if (dataStart == nullptr ) {
429
423
status = DS_PROFILE_FILE_ERROR ;
430
424
goto cleanup ;
431
425
}
432
426
dataStart += strlen (DS_TAG_VERSION );
433
427
434
428
dataEnd = findString (dataStart , contentEnd , DS_TAG_VERSION_END );
435
- if (dataEnd == NULL ) {
429
+ if (dataEnd == nullptr ) {
436
430
status = DS_PROFILE_FILE_ERROR ;
437
431
goto cleanup ;
438
432
}
@@ -464,27 +458,27 @@ static ds_status readProfileFromFile(ds_profile* profile,
464
458
const char * deviceDriverEnd ;
465
459
466
460
dataStart = findString (currentPosition , contentEnd , DS_TAG_DEVICE );
467
- if (dataStart == NULL ) {
461
+ if (dataStart == nullptr ) {
468
462
// nothing useful remain, quit...
469
463
break ;
470
464
}
471
465
dataStart += strlen (DS_TAG_DEVICE );
472
466
dataEnd = findString (dataStart , contentEnd , DS_TAG_DEVICE_END );
473
- if (dataEnd == NULL ) {
467
+ if (dataEnd == nullptr ) {
474
468
status = DS_PROFILE_FILE_ERROR ;
475
469
goto cleanup ;
476
470
}
477
471
478
472
// parse the device type
479
473
deviceTypeStart = findString (dataStart , contentEnd , DS_TAG_DEVICE_TYPE );
480
- if (deviceTypeStart == NULL ) {
474
+ if (deviceTypeStart == nullptr ) {
481
475
status = DS_PROFILE_FILE_ERROR ;
482
476
goto cleanup ;
483
477
}
484
478
deviceTypeStart += strlen (DS_TAG_DEVICE_TYPE );
485
479
deviceTypeEnd = findString (deviceTypeStart , contentEnd ,
486
480
DS_TAG_DEVICE_TYPE_END );
487
- if (deviceTypeEnd == NULL ) {
481
+ if (deviceTypeEnd == nullptr ) {
488
482
status = DS_PROFILE_FILE_ERROR ;
489
483
goto cleanup ;
490
484
}
@@ -495,29 +489,29 @@ static ds_status readProfileFromFile(ds_profile* profile,
495
489
if (deviceType == DS_DEVICE_OPENCL_DEVICE ) {
496
490
497
491
deviceNameStart = findString (dataStart , contentEnd , DS_TAG_DEVICE_NAME );
498
- if (deviceNameStart == NULL ) {
492
+ if (deviceNameStart == nullptr ) {
499
493
status = DS_PROFILE_FILE_ERROR ;
500
494
goto cleanup ;
501
495
}
502
496
deviceNameStart += strlen (DS_TAG_DEVICE_NAME );
503
497
deviceNameEnd = findString (deviceNameStart , contentEnd ,
504
498
DS_TAG_DEVICE_NAME_END );
505
- if (deviceNameEnd == NULL ) {
499
+ if (deviceNameEnd == nullptr ) {
506
500
status = DS_PROFILE_FILE_ERROR ;
507
501
goto cleanup ;
508
502
}
509
503
510
504
511
505
deviceDriverStart = findString (dataStart , contentEnd ,
512
506
DS_TAG_DEVICE_DRIVER_VERSION );
513
- if (deviceDriverStart == NULL ) {
507
+ if (deviceDriverStart == nullptr ) {
514
508
status = DS_PROFILE_FILE_ERROR ;
515
509
goto cleanup ;
516
510
}
517
511
deviceDriverStart += strlen (DS_TAG_DEVICE_DRIVER_VERSION );
518
512
deviceDriverEnd = findString (deviceDriverStart , contentEnd ,
519
513
DS_TAG_DEVICE_DRIVER_VERSION_END );
520
- if (deviceDriverEnd == NULL ) {
514
+ if (deviceDriverEnd == nullptr ) {
521
515
status = DS_PROFILE_FILE_ERROR ;
522
516
goto cleanup ;
523
517
}
@@ -538,7 +532,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
538
532
&& strncmp (profile -> devices [i ].oclDriverVersion , deviceDriverStart ,
539
533
driverVersionLength )== 0 ) {
540
534
deviceScoreStart = findString (dataStart , contentEnd , DS_TAG_SCORE );
541
- if (deviceNameStart == NULL ) {
535
+ if (deviceNameStart == nullptr ) {
542
536
status = DS_PROFILE_FILE_ERROR ;
543
537
goto cleanup ;
544
538
}
@@ -560,7 +554,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
560
554
for (i = 0 ; i < profile -> numDevices ; i ++ ) {
561
555
if (profile -> devices [i ].type == DS_DEVICE_NATIVE_CPU ) {
562
556
deviceScoreStart = findString (dataStart , contentEnd , DS_TAG_SCORE );
563
- if (deviceScoreStart == NULL ) {
557
+ if (deviceScoreStart == nullptr ) {
564
558
status = DS_PROFILE_FILE_ERROR ;
565
559
goto cleanup ;
566
560
}
0 commit comments