Commit 5f40053
committed
Replace setlocale with thread-safe uselocale for locale handling
The previous implementation used setlocale(LC_ALL/LC_NUMERIC, "C") which
affects the entire process and is not thread-safe. This could cause issues
in multi-threaded environments where different threads might need different
locale settings.
Replace setlocale calls with the POSIX.1-2008 thread-safe alternatives:
- Use newlocale() to create a C locale for numeric formatting
- Use uselocale() to set the locale for the current thread only
- Properly restore the previous locale and free resources
Changes:
- libvmaf/src/svm.cpp: Update svm_save_model() locale handling
- libvmaf/src/read_json_model.c: Update vmaf_read_json_model() locale handling
- libvmaf/src/output.c: Update all output functions (vmaf_write_output_xml,
vmaf_write_output_json, vmaf_write_output_csv, vmaf_write_output_sub) to
use thread-safe locale handling with LC_ALL_MASK
This ensures consistent numeric formatting (decimal point vs comma) when
reading/writing model files and generating output in all formats (XML, JSON,
CSV, subtitle) while being thread-safe and not affecting other parts of the
application.1 parent 7c4beca commit 5f40053
3 files changed
+69
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
75 | 82 | | |
76 | 83 | | |
77 | 84 | | |
| |||
154 | 161 | | |
155 | 162 | | |
156 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
157 | 169 | | |
158 | 170 | | |
159 | 171 | | |
160 | 172 | | |
161 | 173 | | |
162 | 174 | | |
163 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
164 | 182 | | |
165 | 183 | | |
166 | 184 | | |
| |||
299 | 317 | | |
300 | 318 | | |
301 | 319 | | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
302 | 325 | | |
303 | 326 | | |
304 | 327 | | |
305 | 328 | | |
306 | 329 | | |
307 | 330 | | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
308 | 337 | | |
309 | 338 | | |
310 | 339 | | |
| |||
342 | 371 | | |
343 | 372 | | |
344 | 373 | | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
345 | 379 | | |
346 | 380 | | |
347 | 381 | | |
348 | 382 | | |
349 | 383 | | |
350 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
351 | 391 | | |
352 | 392 | | |
353 | 393 | | |
| |||
381 | 421 | | |
382 | 422 | | |
383 | 423 | | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
384 | 429 | | |
385 | 430 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
432 | 433 | | |
433 | 434 | | |
434 | 435 | | |
| 436 | + | |
435 | 437 | | |
436 | 438 | | |
437 | 439 | | |
| |||
449 | 451 | | |
450 | 452 | | |
451 | 453 | | |
452 | | - | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
453 | 468 | | |
454 | 469 | | |
455 | 470 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2653 | 2653 | | |
2654 | 2654 | | |
2655 | 2655 | | |
2656 | | - | |
2657 | | - | |
2658 | | - | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
| 2659 | + | |
2659 | 2660 | | |
2660 | | - | |
2661 | 2661 | | |
2662 | 2662 | | |
2663 | 2663 | | |
| |||
2738 | 2738 | | |
2739 | 2739 | | |
2740 | 2740 | | |
2741 | | - | |
2742 | | - | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
2743 | 2745 | | |
2744 | 2746 | | |
2745 | 2747 | | |
| |||
0 commit comments