@@ -347,15 +347,21 @@ JSON_C_CONST_FUNCTION(JSON_EXPORT size_t json_c_object_sizeof(void));
347347
348348/** Add an object field to a json_object of type json_type_object
349349 *
350- * The reference count will *not* be incremented. This is to make adding
351- * fields to objects in code more compact. If you want to retain a reference
352- * to an added object, independent of the lifetime of obj, you must wrap the
353- * passed object with json_object_get.
350+ * The reference count of `val` will *not* be incremented, in effect
351+ * transferring ownership that object to `obj`, and thus `val` will be
352+ * freed when `obj` is. (i.e. through `json_object_put(obj)`)
353+ *
354+ * If you want to retain a reference to the added object, independent
355+ * of the lifetime of obj, you must increment the refcount with
356+ * `json_object_get(val)` (and later release it with json_object_put()).
357+ *
358+ * Since ownership transfers to `obj`, you must make sure
359+ * that you do in fact have ownership over `val`. For instance,
360+ * json_object_new_object() will give you ownership until you transfer it,
361+ * whereas json_object_object_get() does not.
354362 *
355- * Upon calling this, the ownership of val transfers to obj. Thus you must
356- * make sure that you do in fact have ownership over this object. For instance,
357- * json_object_new_object will give you ownership until you transfer it,
358- * whereas json_object_object_get does not.
363+ * Any previous object stored under `key` in `obj` will have its refcount
364+ * decremented, and be freed normally if that drops to zero.
359365 *
360366 * @param obj the json_object instance
361367 * @param key the object field name (a private copy will be duplicated)
@@ -378,7 +384,7 @@ JSON_EXPORT int json_object_object_add(struct json_object *obj, const char *key,
378384 * @param key the object field name (a private copy will be duplicated)
379385 * @param val a json_object or NULL member to associate with the given field
380386 * @param opts process-modifying options. To specify multiple options, use
381- * arithmetic or (OPT1|OPT2)
387+ * (OPT1|OPT2)
382388 */
383389JSON_EXPORT int json_object_object_add_ex (struct json_object * obj , const char * const key ,
384390 struct json_object * const val , const unsigned opts );
0 commit comments