forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita2bbc58
committed
thread-safety: gmtime_r(), localtime_r()
Use gmtime_r() and localtime_r() instead of gmtime() and localtime(),for thread-safety.There are a few affected calls in libpq and ecpg's libpgtypes, whichare probably effectively bugs, because those libraries already claimto be thread-safe.There is one affected call in the backend. Most of the backendotherwise uses the custom functions pg_gmtime() and pg_localtime(),which are implemented differently.While we're here, change the call in the backend to gmtime*() insteadof localtime*(), since for that use time zone behavior is irrelevant,and this side-steps any questions about when time zones areinitialized by localtime_r() vs localtime().Portability: gmtime_r() and localtime_r() are in POSIX but are notavailable on Windows. Windows has functions gmtime_s() andlocaltime_s() that can fulfill the same purpose, so we add some smallwrappers around them. (Note that these *_s() functions are alsodifferent from the *_s() functions in the bounds-checking extension ofC11. We are not using those here.)On MinGW, you can get the POSIX-style *_r() functions by defining_POSIX_C_SOURCE appropriately before including <time.h>. This leadsto a conflict at least in plpython because apparently _POSIX_C_SOURCEgets defined in some header there, and then our replacementdefinitions conflict with the system definitions. To avoid that sortof thing, we now always define _POSIX_C_SOURCE on MinGW and use thePOSIX-style functions here.Reviewed-by: Stepan Neretin <sncfmgg@gmail.com>Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>Reviewed-by: Thomas Munro <thomas.munro@gmail.com>Discussion:https://www.postgresql.org/message-id/flat/eba1dc75-298e-4c46-8869-48ba8aad7d70@eisentraut.org1 parent94a3373 commita2bbc58
File tree
7 files changed
+33
-7
lines changed- src
- backend/utils/adt
- include/port
- interfaces
- ecpg/pgtypeslib
- libpq
- template
7 files changed
+33
-7
lines changedLines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
268 | 268 |
| |
269 | 269 |
| |
270 | 270 |
| |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
271 | 275 |
| |
272 | 276 |
| |
273 | 277 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
826 | 826 |
| |
827 | 827 |
| |
828 | 828 |
| |
| 829 | + | |
829 | 830 |
| |
830 | 831 |
| |
831 | 832 |
| |
| |||
876 | 877 |
| |
877 | 878 |
| |
878 | 879 |
| |
879 |
| - | |
| 880 | + | |
880 | 881 |
| |
881 | 882 |
| |
882 | 883 |
| |
|
Lines changed: 13 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
420 | 420 |
| |
421 | 421 |
| |
422 | 422 |
| |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
423 | 436 |
| |
424 | 437 |
| |
425 | 438 |
| |
|
Lines changed: 7 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
949 | 949 |
| |
950 | 950 |
| |
951 | 951 |
| |
| 952 | + | |
952 | 953 |
| |
953 | 954 |
| |
954 |
| - | |
| 955 | + | |
955 | 956 |
| |
956 | 957 |
| |
957 | 958 |
| |
| |||
973 | 974 |
| |
974 | 975 |
| |
975 | 976 |
| |
| 977 | + | |
976 | 978 |
| |
977 | 979 |
| |
978 | 980 |
| |
979 |
| - | |
| 981 | + | |
980 | 982 |
| |
981 |
| - | |
| 983 | + | |
982 | 984 |
| |
983 | 985 |
| |
984 | 986 |
| |
| |||
2810 | 2812 |
| |
2811 | 2813 |
| |
2812 | 2814 |
| |
| 2815 | + | |
2813 | 2816 |
| |
2814 | 2817 |
| |
2815 |
| - | |
| 2818 | + | |
2816 | 2819 |
| |
2817 | 2820 |
| |
2818 | 2821 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
129 | 129 |
| |
130 | 130 |
| |
131 | 131 |
| |
| 132 | + | |
132 | 133 |
| |
133 | 134 |
| |
134 | 135 |
| |
135 | 136 |
| |
136 |
| - | |
| 137 | + | |
137 | 138 |
| |
138 | 139 |
| |
139 | 140 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
81 | 81 |
| |
82 | 82 |
| |
83 | 83 |
| |
| 84 | + | |
84 | 85 |
| |
85 | 86 |
| |
86 | 87 |
| |
| |||
93 | 94 |
| |
94 | 95 |
| |
95 | 96 |
| |
96 |
| - | |
| 97 | + | |
97 | 98 |
| |
98 | 99 |
| |
99 | 100 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 | 2 |
| |
| 3 | + | |
| 4 | + | |
| 5 | + | |
3 | 6 |
| |
4 | 7 |
| |
5 | 8 |
| |
|
0 commit comments
Comments
(0)