Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Improvements to the problib(3) API:



details:   https://anonhg.NetBSD.org/src/rev/7e970014f0e8
branches:  trunk
changeset: 934088:7e970014f0e8
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Jun 06 21:25:59 2020 +0000

description:
Improvements to the problib(3) API:

==> Provide a much more complete set of setters and getters for different
    value types in the prop_array_util(3) and prop_dictionary_util(3)
    functions.

==> Overhaul the prop_data(3), prop_number(3), and prop_string(3) APIs
    to be easier to use and less awkwardly named,  Deprecate the old
    awkward names, and produce link-time warnings when they are referenced.

==> Deprecate mutable prop_data(3) and prop_string(3) objects.  The old
    APIs that support them still exist, but will now produce link-time
    warnings when used.

==> When the new prop_string(3) API is used, strings are internally
    de-duplicated as a memory footprint optimization.

==> Provide a rich set of bounds-checked gettter functions in and a
    corresponding set of convenience setters in the prop_number(3) API.

==> Add a new prop_bool_value(3) function that is equivalent to
    prop_bool_true(3), but aligned with the new "value" routines in
    prop_data(3), prop_string(3), and prop_number(3).

diffstat:

 common/include/prop/prop_array.h          |  109 +++-
 common/include/prop/prop_bool.h           |    3 +-
 common/include/prop/prop_data.h           |   18 +-
 common/include/prop/prop_dictionary.h     |   86 ++-
 common/include/prop/prop_number.h         |   43 +-
 common/include/prop/prop_string.h         |   32 +-
 common/lib/libprop/prop_array.3           |    5 +-
 common/lib/libprop/prop_array_util.3      |  325 ++++++++--
 common/lib/libprop/prop_array_util.c      |  489 +++++++++------
 common/lib/libprop/prop_bool.3            |   15 +-
 common/lib/libprop/prop_bool.c            |   16 +-
 common/lib/libprop/prop_data.3            |   76 +-
 common/lib/libprop/prop_data.c            |  199 ++++--
 common/lib/libprop/prop_dictionary.3      |   12 +-
 common/lib/libprop/prop_dictionary.c      |   21 +-
 common/lib/libprop/prop_dictionary_util.3 |  166 ++++-
 common/lib/libprop/prop_dictionary_util.c |  378 +++++++----
 common/lib/libprop/prop_number.3          |  185 ++++-
 common/lib/libprop/prop_number.c          |  157 ++++-
 common/lib/libprop/prop_object.3          |    4 +-
 common/lib/libprop/prop_object_impl.h     |   12 +-
 common/lib/libprop/prop_string.3          |  167 ++---
 common/lib/libprop/prop_string.c          |  417 ++++++++++---
 common/lib/libprop/proplib.3              |    7 +-
 distrib/sets/lists/base/shl.mi            |    6 +-
 distrib/sets/lists/comp/mi                |  544 +++++++++++++++---
 distrib/sets/lists/tests/mi               |    5 +-
 lib/libprop/Makefile                      |  195 ++++-
 lib/libprop/shlib_version                 |    4 +-
 tests/lib/libprop/Makefile                |    4 +-
 tests/lib/libprop/t_basic.c               |  203 ------
 tests/lib/libprop/t_proplib.c             |  897 ++++++++++++++++++++++++++++++
 32 files changed, 3588 insertions(+), 1212 deletions(-)

diffs (truncated from 6615 to 300 lines):

diff -r 38e472378187 -r 7e970014f0e8 common/include/prop/prop_array.h
--- a/common/include/prop/prop_array.h  Sat Jun 06 20:38:00 2020 +0000
+++ b/common/include/prop/prop_array.h  Sat Jun 06 21:25:59 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: prop_array.h,v 1.16 2017/01/29 02:07:44 christos Exp $    */
+/*     $NetBSD: prop_array.h,v 1.17 2020/06/06 21:25:59 thorpej Exp $    */
 
 /*-
- * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 2006, 2009, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -101,6 +101,60 @@
 bool           prop_array_set_bool(prop_array_t, unsigned int,
                                         bool);
 
+bool           prop_array_get_schar(prop_array_t, unsigned int,
+                                        signed char *);
+bool           prop_array_get_uchar(prop_array_t, unsigned int,
+                                        unsigned char *);
+bool           prop_array_set_schar(prop_array_t, unsigned int,
+                                        signed char);
+bool           prop_array_set_uchar(prop_array_t, unsigned int,
+                                        unsigned char);
+
+bool           prop_array_get_short(prop_array_t, unsigned int,
+                                        short *);
+bool           prop_array_get_ushort(prop_array_t, unsigned int,
+                                        unsigned short *);
+bool           prop_array_set_short(prop_array_t, unsigned int,
+                                        short);
+bool           prop_array_set_ushort(prop_array_t, unsigned int,
+                                        unsigned short);
+
+bool           prop_array_get_int(prop_array_t, unsigned int,
+                                        int *);
+bool           prop_array_get_uint(prop_array_t, unsigned int,
+                                        unsigned int *);
+bool           prop_array_set_int(prop_array_t, unsigned int,
+                                        int);
+bool           prop_array_set_uint(prop_array_t, unsigned int,
+                                        unsigned int);
+
+bool           prop_array_get_long(prop_array_t, unsigned int,
+                                        long *);
+bool           prop_array_get_ulong(prop_array_t, unsigned int,
+                                        unsigned long *);
+bool           prop_array_set_long(prop_array_t, unsigned int,
+                                        long);
+bool           prop_array_set_ulong(prop_array_t, unsigned int,
+                                        unsigned long);
+
+bool           prop_array_get_longlong(prop_array_t, unsigned int,
+                                        long long *);
+bool           prop_array_get_ulonglong(prop_array_t, unsigned int,
+                                        unsigned long long *);
+bool           prop_array_set_longlong(prop_array_t, unsigned int,
+                                        long long);
+bool           prop_array_set_ulonglong(prop_array_t, unsigned int,
+                                        unsigned long long);
+
+bool           prop_array_get_intptr(prop_array_t, unsigned int,
+                                        intptr_t *);
+bool           prop_array_get_uintptr(prop_array_t, unsigned int,
+                                        uintptr_t *);
+bool           prop_array_set_intptr(prop_array_t, unsigned int,
+                                        intptr_t);
+bool           prop_array_set_uintptr(prop_array_t, unsigned int,
+                                        uintptr_t);
+
 bool           prop_array_get_int8(prop_array_t, unsigned int,
                                         int8_t *);
 bool           prop_array_get_uint8(prop_array_t, unsigned int,
@@ -137,6 +191,29 @@
 bool           prop_array_set_uint64(prop_array_t, unsigned int,
                                           uint64_t);
 
+bool           prop_array_set_and_rel(prop_array_t, unsigned int,
+                                      prop_object_t);
+
+bool           prop_array_add_bool(prop_array_t, bool);
+
+bool           prop_array_add_schar(prop_array_t, signed char);
+bool           prop_array_add_uchar(prop_array_t, unsigned char);
+
+bool           prop_array_add_short(prop_array_t, short);
+bool           prop_array_add_ushort(prop_array_t, unsigned short);
+
+bool           prop_array_add_int(prop_array_t, int);
+bool           prop_array_add_uint(prop_array_t, unsigned int);
+
+bool           prop_array_add_long(prop_array_t, long);
+bool           prop_array_add_ulong(prop_array_t, unsigned long);
+
+bool           prop_array_add_longlong(prop_array_t, long long);
+bool           prop_array_add_ulonglong(prop_array_t, unsigned long long);
+
+bool           prop_array_add_intptr(prop_array_t, intptr_t);
+bool           prop_array_add_uintptr(prop_array_t, uintptr_t);
+
 bool           prop_array_add_int8(prop_array_t, int8_t);
 bool           prop_array_add_uint8(prop_array_t, uint8_t);
 
@@ -149,6 +226,31 @@
 bool           prop_array_add_int64(prop_array_t, int64_t);
 bool           prop_array_add_uint64(prop_array_t, uint64_t);
 
+bool           prop_array_get_string(prop_array_t, unsigned int,
+                                               const char **);
+bool           prop_array_set_string(prop_array_t, unsigned int,
+                                               const char *);
+bool           prop_array_add_string(prop_array_t, const char *);
+bool           prop_array_set_string_nocopy(prop_array_t, unsigned int,
+                                               const char *);
+bool           prop_array_add_string_nocopy(prop_array_t, const char *);
+
+bool           prop_array_get_data(prop_array_t, unsigned int,
+                                       const void **, size_t *);
+bool           prop_array_set_data(prop_array_t, unsigned int,
+                                       const void *, size_t);
+bool           prop_array_add_data(prop_array_t,
+                                       const void *, size_t);
+bool           prop_array_set_data_nocopy(prop_array_t, unsigned int,
+                                       const void *, size_t);
+bool           prop_array_add_data_nocopy(prop_array_t,
+                                       const void *, size_t);
+
+bool           prop_array_add_and_rel(prop_array_t, prop_object_t);
+
+
+/* Deprecated functions. */
+
 bool           prop_array_add_cstring(prop_array_t, const char *);
 bool           prop_array_get_cstring(prop_array_t, unsigned int,
                                             char **);
@@ -162,9 +264,6 @@
 bool           prop_array_set_cstring_nocopy(prop_array_t,
                                                   unsigned int,
                                                   const char *);
-
-bool           prop_array_add_and_rel(prop_array_t, prop_object_t);
-
 __END_DECLS
 
 #endif /* _PROPLIB_PROP_ARRAY_H_ */
diff -r 38e472378187 -r 7e970014f0e8 common/include/prop/prop_bool.h
--- a/common/include/prop/prop_bool.h   Sat Jun 06 20:38:00 2020 +0000
+++ b/common/include/prop/prop_bool.h   Sat Jun 06 21:25:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_bool.h,v 1.4 2008/04/28 20:22:51 martin Exp $     */
+/*     $NetBSD: prop_bool.h,v 1.5 2020/06/06 21:25:59 thorpej Exp $    */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -41,6 +41,7 @@
 prop_bool_t    prop_bool_copy(prop_bool_t);
 
 bool           prop_bool_true(prop_bool_t);
+bool           prop_bool_value(prop_bool_t);
 
 bool           prop_bool_equals(prop_bool_t, prop_bool_t);
 __END_DECLS
diff -r 38e472378187 -r 7e970014f0e8 common/include/prop/prop_data.h
--- a/common/include/prop/prop_data.h   Sat Jun 06 20:38:00 2020 +0000
+++ b/common/include/prop/prop_data.h   Sat Jun 06 21:25:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_data.h,v 1.3 2008/04/28 20:22:51 martin Exp $     */
+/*     $NetBSD: prop_data.h,v 1.4 2020/06/06 21:25:59 thorpej Exp $    */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -37,18 +37,26 @@
 typedef struct _prop_data *prop_data_t;
 
 __BEGIN_DECLS
-prop_data_t    prop_data_create_data(const void *, size_t);
-prop_data_t    prop_data_create_data_nocopy(const void *, size_t);
+prop_data_t    prop_data_create_copy(const void *, size_t);
+prop_data_t    prop_data_create_nocopy(const void *, size_t);
 
 prop_data_t    prop_data_copy(prop_data_t);
 
 size_t         prop_data_size(prop_data_t);
 
-void *         prop_data_data(prop_data_t);
-const void *   prop_data_data_nocopy(prop_data_t);
+const void *   prop_data_value(prop_data_t);
+bool           prop_data_copy_value(prop_data_t, void *, size_t);
 
 bool           prop_data_equals(prop_data_t, prop_data_t);
 bool           prop_data_equals_data(prop_data_t, const void *, size_t);
+
+
+/* Deprecated functions. */
+prop_data_t    prop_data_create_data(const void *, size_t);
+prop_data_t    prop_data_create_data_nocopy(const void *, size_t);
+
+void *         prop_data_data(prop_data_t);
+const void *   prop_data_data_nocopy(prop_data_t);
 __END_DECLS
 
 #endif /* _PROPLIB_PROP_DATA_H_ */
diff -r 38e472378187 -r 7e970014f0e8 common/include/prop/prop_dictionary.h
--- a/common/include/prop/prop_dictionary.h     Sat Jun 06 20:38:00 2020 +0000
+++ b/common/include/prop/prop_dictionary.h     Sat Jun 06 21:25:59 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: prop_dictionary.h,v 1.16 2017/01/29 00:16:19 christos Exp $    */
+/*     $NetBSD: prop_dictionary.h,v 1.17 2020/06/06 21:25:59 thorpej Exp $     */
 
 /*-
- * Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 2006, 2009, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -77,7 +77,7 @@
                                                    const char *);
 prop_dictionary_t prop_dictionary_internalize_from_file(const char *);
 
-const char *   prop_dictionary_keysym_cstring_nocopy(prop_dictionary_keysym_t);
+const char *   prop_dictionary_keysym_value(prop_dictionary_keysym_t);
 
 bool           prop_dictionary_keysym_equals(prop_dictionary_keysym_t,
                                              prop_dictionary_keysym_t);
@@ -125,11 +125,66 @@
  */
 bool           prop_dictionary_get_dict(prop_dictionary_t, const char *,
                                         prop_dictionary_t *);
+
 bool           prop_dictionary_get_bool(prop_dictionary_t, const char *,
                                         bool *);
 bool           prop_dictionary_set_bool(prop_dictionary_t, const char *,
                                         bool);
 
+bool           prop_dictionary_get_schar(prop_dictionary_t, const char *,
+                                         signed char *);
+bool           prop_dictionary_get_uchar(prop_dictionary_t, const char *,
+                                         unsigned char *);
+bool           prop_dictionary_set_schar(prop_dictionary_t, const char *,
+                                         signed char);
+bool           prop_dictionary_set_uchar(prop_dictionary_t, const char *,
+                                         unsigned char);
+
+bool           prop_dictionary_get_short(prop_dictionary_t, const char *,
+                                         short *);
+bool           prop_dictionary_get_ushort(prop_dictionary_t, const char *,
+                                          unsigned short *);
+bool           prop_dictionary_set_short(prop_dictionary_t, const char *,
+                                         short);
+bool           prop_dictionary_set_ushort(prop_dictionary_t, const char *,
+                                          unsigned short);
+
+bool           prop_dictionary_get_int(prop_dictionary_t, const char *,
+                                       int *);
+bool           prop_dictionary_get_uint(prop_dictionary_t, const char *,
+                                        unsigned int *);
+bool           prop_dictionary_set_int(prop_dictionary_t, const char *,
+                                       int);
+bool           prop_dictionary_set_uint(prop_dictionary_t, const char *,
+                                        unsigned int);
+
+bool           prop_dictionary_get_long(prop_dictionary_t, const char *,
+                                        long *);
+bool           prop_dictionary_get_ulong(prop_dictionary_t, const char *,
+                                         unsigned long *);
+bool           prop_dictionary_set_long(prop_dictionary_t, const char *,
+                                        long);
+bool           prop_dictionary_set_ulong(prop_dictionary_t, const char *,
+                                         unsigned long);
+
+bool           prop_dictionary_get_longlong(prop_dictionary_t, const char *,
+                                            long long *);
+bool           prop_dictionary_get_ulonglong(prop_dictionary_t, const char *,
+                                             unsigned long long *);
+bool           prop_dictionary_set_longlong(prop_dictionary_t, const char *,
+                                            long long);
+bool           prop_dictionary_set_ulonglong(prop_dictionary_t, const char *,
+                                             unsigned long long);
+
+bool           prop_dictionary_get_intptr(prop_dictionary_t, const char *,
+                                          intptr_t *);
+bool           prop_dictionary_get_uintptr(prop_dictionary_t, const char *,
+                                           uintptr_t *);
+bool           prop_dictionary_set_intptr(prop_dictionary_t, const char *,
+                                          intptr_t);
+bool           prop_dictionary_set_uintptr(prop_dictionary_t, const char *,
+                                           uintptr_t);
+
 bool           prop_dictionary_get_int8(prop_dictionary_t, const char *,
                                         int8_t *);
 bool           prop_dictionary_get_uint8(prop_dictionary_t, const char *,
@@ -166,6 +221,26 @@
 bool           prop_dictionary_set_uint64(prop_dictionary_t, const char *,
                                           uint64_t);
 
+bool           prop_dictionary_get_string(prop_dictionary_t, const char *,
+                                          const char **cpp);
+bool           prop_dictionary_set_string(prop_dictionary_t, const char *,
+                                          const char *);



Home | Main Index | Thread Index | Old Index