Skip to content

Commit

Permalink
CLN: fix build warning for use of strdup in ultrajson
Browse files Browse the repository at this point in the history
When building with `-std=c99` on Linux this gives a warning:

```
[2/3] Compiling C object pandas/_libs/json.cpython-310-x86_64-linux-gnu.so.p/src_ujson_lib_ultrajsonenc.c.o
../pandas/_libs/src/ujson/lib/ultrajsonenc.c: In function 'JSON_EncodeObject':
../pandas/_libs/src/ujson/lib/ultrajsonenc.c:1180:18: warning: implicit declaration of function 'strdup'; did you mean 'strcmp'? [-Wimplicit-function-declaration]
 1180 |         locale = strdup(locale);
      |                  ^~~~~~
      |                  strcmp
../pandas/_libs/src/ujson/lib/ultrajsonenc.c:1180:16: warning: assignment to 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
 1180 |         locale = strdup(locale);
```

And for the MSVC build in CI the warnings look like:
```
building 'pandas._libs.json' extension
creating build\temp.win-amd64-cpython-310\Release\pandas\_libs\src\ujson
creating build\temp.win-amd64-cpython-310\Release\pandas\_libs\src\ujson\lib
creating build\temp.win-amd64-cpython-310\Release\pandas\_libs\src\ujson\python
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.33.31629\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DNPY_NO_DEPRECATED_API=0 -Ipandas/_libs/src/ujson/python -Ipandas/_libs/src/ujson/lib -Ipandas/_libs/src/datetime -IC:\Users\runneradmin\micromamba\envs\test\lib\site-packages\numpy\core\include -IC:\Users\runneradmin\micromamba\envs\test\include -IC:\Users\runneradmin\micromamba\envs\test\Include "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.33.31629\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.33.31629\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tcpandas/_libs/src/ujson/lib/ultrajsondec.c /Fobuild\temp.win-amd64-cpython-310\Release\pandas/_libs/src/ujson/lib/ultrajsondec.obj -D_GNU_SOURCE
ultrajsondec.c
pandas/_libs/src/ujson/lib/ultrajsondec.c(1178): warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details.
```

Note that on POSIX defining the `_XOPEN_SOURCE` macro to 500 is enough
to make `strdup` available, however on macOS it seems to need 600.
  • Loading branch information
rgommers committed Sep 20, 2022
1 parent c68a96f commit 7470e11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pandas/_libs/src/headers/portable.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#ifndef _PANDAS_PORTABLE_H_
#define _PANDAS_PORTABLE_H_

// To get `strdup` from strings.h
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif

#include <string.h>

#if defined(_MSC_VER)
#define strcasecmp( s1, s2 ) _stricmp( s1, s2 )
#define strdup _strdup
#endif

// GH-23516 - works around locale perf issues
Expand Down
1 change: 1 addition & 0 deletions pandas/_libs/src/ujson/lib/ultrajson.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ tree doesn't have cyclic references.

#include <stdio.h>
#include <wchar.h>
#include "../../headers/portable.h"

// Don't output any extra whitespaces when encoding
#define JSON_NO_EXTRA_WHITESPACE
Expand Down

0 comments on commit 7470e11

Please sign in to comment.