Use less error prone string list, map or multimap pointer types

Use pointers to incomplete struct types. If an argument of a not suitable
type is passed to a function of any string collection,
C compiler will warn:
  warning: passing argument 1 of <func> from incompatible pointer type
C++ compiler will raise an error, for example:
  error: cannot convert 'cef_string_list_t' ... to 'cef_string_multimap_t'

With the previously used `void*` pointer types, such errors in a code were not
diagnosed.
This commit is contained in:
Sergey Markelov 2023-04-13 16:06:02 +00:00 committed by Marshall Greenblatt
parent f90d5bc49e
commit c3648f42b2
6 changed files with 7 additions and 7 deletions

View File

@ -41,7 +41,7 @@ extern "C" {
/// ///
/// CEF string maps are a set of key/value string pairs. /// CEF string maps are a set of key/value string pairs.
/// ///
typedef void* cef_string_list_t; typedef struct _cef_string_list_t* cef_string_list_t;
/// ///
/// Allocate a new string map. /// Allocate a new string map.

View File

@ -41,7 +41,7 @@ extern "C" {
/// ///
/// CEF string maps are a set of key/value string pairs. /// CEF string maps are a set of key/value string pairs.
/// ///
typedef void* cef_string_map_t; typedef struct _cef_string_map_t* cef_string_map_t;
/// ///
/// Allocate a new string map. /// Allocate a new string map.

View File

@ -42,7 +42,7 @@ extern "C" {
/// CEF string multimaps are a set of key/value string pairs. /// CEF string multimaps are a set of key/value string pairs.
/// More than one value can be assigned to a single key. /// More than one value can be assigned to a single key.
/// ///
typedef void* cef_string_multimap_t; typedef struct _cef_string_multimap_t* cef_string_multimap_t;
/// ///
/// Allocate a new string multimap. /// Allocate a new string multimap.

View File

@ -13,7 +13,7 @@ using StringList = std::vector<CefString>;
} // namespace } // namespace
CEF_EXPORT cef_string_list_t cef_string_list_alloc() { CEF_EXPORT cef_string_list_t cef_string_list_alloc() {
return new StringList; return reinterpret_cast<cef_string_list_t>(new StringList);
} }
CEF_EXPORT size_t cef_string_list_size(cef_string_list_t list) { CEF_EXPORT size_t cef_string_list_size(cef_string_list_t list) {
@ -58,5 +58,5 @@ CEF_EXPORT void cef_string_list_free(cef_string_list_t list) {
CEF_EXPORT cef_string_list_t cef_string_list_copy(cef_string_list_t list) { CEF_EXPORT cef_string_list_t cef_string_list_copy(cef_string_list_t list) {
DCHECK(list); DCHECK(list);
StringList* impl = reinterpret_cast<StringList*>(list); StringList* impl = reinterpret_cast<StringList*>(list);
return new StringList(*impl); return reinterpret_cast<cef_string_list_t>(new StringList(*impl));
} }

View File

@ -13,7 +13,7 @@ using StringMap = std::map<CefString, CefString>;
} // namespace } // namespace
CEF_EXPORT cef_string_map_t cef_string_map_alloc() { CEF_EXPORT cef_string_map_t cef_string_map_alloc() {
return new StringMap; return reinterpret_cast<cef_string_map_t>(new StringMap);
} }
CEF_EXPORT size_t cef_string_map_size(cef_string_map_t map) { CEF_EXPORT size_t cef_string_map_size(cef_string_map_t map) {

View File

@ -13,7 +13,7 @@ using StringMultimap = std::multimap<CefString, CefString>;
} // namespace } // namespace
CEF_EXPORT cef_string_multimap_t cef_string_multimap_alloc() { CEF_EXPORT cef_string_multimap_t cef_string_multimap_alloc() {
return new StringMultimap; return reinterpret_cast<cef_string_multimap_t>(new StringMultimap);
} }
CEF_EXPORT size_t cef_string_multimap_size(cef_string_multimap_t map) { CEF_EXPORT size_t cef_string_multimap_size(cef_string_multimap_t map) {