Commit 8c08ad9
committed
Fix libbson deprecated API warning with version compatibility
During compilation of cachedb_mongodb module, numerous deprecation
warnings appear on systems with mongo-c-driver >= 1.29.0:
```
Compiling cachedb_mongodb_dbase.c
gcc -fPIC -DPIC -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-complain-wrong-lang -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -DMOD_NAME='cachedb_mongodb' -DPKG_MALLOC -DSHM_MMAP -DUSE_MCAST -DDISABLE_NAGLE -DSTATISTICS -DHAVE_RESOLV_RES -DF_MALLOC -DQ_MALLOC -DHP_MALLOC -DDBG_MALLOC -DF_PARALLEL_MALLOC -DHAVE_STDATOMIC -DHAVE_GENERICS -DNAME='"opensips"' -DVERSION='"3.6.2"' -DARCH='"x86_64"' -DOS='"linux"' -DCOMPILER='"gcc 15"' -D__CPU_x86_64 -D__OS_linux -D__SMP_yes -DCFG_DIR='"/etc/opensips/"' -DVERSIONTYPE='"git"' -DTHISREVISION='"994bcd690"' -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H -DHAVE_TIMEGM -DHAVE_EPOLL -DHAVE_SIGIO_RT -DHAVE_SELECT -I/usr/include/json-c -I/usr/include/json-c -DJSON_PKG_MAJOR=0 -DJSON_PKG_MINOR=18 -DJSON_PKG_MICRO=0 -DUTF8PROC_EXPORTS -I/usr/include/libmongoc-1.0 -I/usr/include/libbson-1.0 -c cachedb_mongodb_dbase.c -o cachedb_mongodb_dbase.o
cachedb_mongodb_dbase.c: In function ‘mongo_con_set’:
cachedb_mongodb_dbase.c:315:9: warning: ‘bson_as_json’ is deprecated: Use bson_as_legacy_extended_json instead [-Wdeprecated-declarations]
315 | dbg_bson("query: ", query);
| ^~~~~~~~
In file included from /usr/include/libmongoc-1.0/mongoc/mongoc.h:22,
from /usr/include/libmongoc-1.0/mongoc.h:18,
from cachedb_mongodb_dbase.h:30,
from cachedb_mongodb_dbase.c:22:
/usr/include/libbson-1.0/bson/bson.h:535:1: note: declared here
535 | bson_as_json (const bson_t *bson, size_t *length) BSON_GNUC_DEPRECATED_FOR (bson_as_legacy_extended_json);
| ^~~~~~~~~~~~
```
The MongoDB C driver (libbson) deprecated bson_as_json() in version
1.29.0 (October 2024) in favor of bson_as_legacy_extended_json() to
clarify which JSON format is being produced (legacy vs. canonical
extended JSON).
We added compatibility macro at the top of cachedb_mongodb_dbase.c - for
mongo-c-driver < 1.29.0, define bson_as_legacy_extended_json as an alias
to bson_as_json, allowing the code to use the new API name while
maintaining backward compatibility.
This change maintains compatibility with all mongo-c-driver versions.
The new function name is used on >= 1.29.0, while older versions
transparently use the original bson_as_json() through the macro alias.
No behavioral changes - the replacement is functionally identical and
produces the same JSON output format. The new name simply makes it
explicit that the legacy extended JSON format is being used.
Note: mongo-c-driver 1.29.0 was released in October 2024. Many LTS
distributions still ship earlier versions (e.g., RHEL 8/9, Ubuntu
20.04/22.04, Debian 11/12), making the compatibility macro necessary.
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
Assisted-by: Claude (Anthropic) <https://claude.ai>1 parent b7e02bb commit 8c08ad9
1 file changed
Lines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
47 | | - | |
| 51 | + | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| |||
1309 | 1313 | | |
1310 | 1314 | | |
1311 | 1315 | | |
1312 | | - | |
| 1316 | + | |
1313 | 1317 | | |
1314 | | - | |
| 1318 | + | |
1315 | 1319 | | |
1316 | | - | |
| 1320 | + | |
1317 | 1321 | | |
1318 | 1322 | | |
1319 | 1323 | | |
| |||
0 commit comments