add description
This commit is contained in:
@@ -63,6 +63,7 @@ struct heim_type_data array_object = {
|
||||
array_dealloc,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@@ -42,6 +42,7 @@ struct heim_type_data _heim_bool_object = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@@ -80,7 +80,8 @@ struct heim_type_data _heim_data_object = {
|
||||
data_dealloc,
|
||||
NULL,
|
||||
data_cmp,
|
||||
data_hash
|
||||
data_hash,
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
|
@@ -94,6 +94,7 @@ struct heim_type_data db_object = {
|
||||
db_dealloc,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@@ -71,6 +71,7 @@ struct heim_type_data dict_object = {
|
||||
dict_dealloc,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@@ -72,7 +72,8 @@ struct heim_type_data _heim_error_object = {
|
||||
error_dealloc,
|
||||
NULL,
|
||||
error_cmp,
|
||||
error_hash
|
||||
error_hash,
|
||||
NULL
|
||||
};
|
||||
|
||||
heim_error_t
|
||||
|
@@ -138,6 +138,20 @@ heim_release(void *ptr)
|
||||
heim_abort("over release");
|
||||
}
|
||||
|
||||
/**
|
||||
* If used require wrapped in autorelease pool
|
||||
*/
|
||||
|
||||
heim_string_t
|
||||
heim_description(heim_object_t ptr)
|
||||
{
|
||||
struct heim_base *p = PTR2BASE(ptr);
|
||||
if (p->isa->desc == NULL)
|
||||
return heim_auto_release(heim_string_ref_create(p->isa->name, NULL));
|
||||
return heim_auto_release(p->isa->desc(ptr));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_heim_make_permanent(heim_object_t ptr)
|
||||
{
|
||||
@@ -254,6 +268,7 @@ struct heim_type_data memory_object = {
|
||||
memory_dealloc,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -290,7 +305,8 @@ _heim_create_type(const char *name,
|
||||
heim_type_dealloc dealloc,
|
||||
heim_type_copy copy,
|
||||
heim_type_cmp cmp,
|
||||
heim_type_hash hash)
|
||||
heim_type_hash hash,
|
||||
heim_type_description desc)
|
||||
{
|
||||
heim_type_t type;
|
||||
|
||||
@@ -305,6 +321,7 @@ _heim_create_type(const char *name,
|
||||
type->copy = copy;
|
||||
type->cmp = cmp;
|
||||
type->hash = hash;
|
||||
type->desc = desc;
|
||||
|
||||
return type;
|
||||
}
|
||||
@@ -509,7 +526,8 @@ static struct heim_type_data _heim_autorel_object = {
|
||||
autorel_dealloc,
|
||||
NULL,
|
||||
autorel_cmp,
|
||||
autorel_hash
|
||||
autorel_hash,
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -548,7 +566,7 @@ heim_auto_release_create(void)
|
||||
* @param ptr object
|
||||
*/
|
||||
|
||||
void
|
||||
heim_object_t
|
||||
heim_auto_release(heim_object_t ptr)
|
||||
{
|
||||
struct heim_base *p = PTR2BASE(ptr);
|
||||
@@ -556,7 +574,7 @@ heim_auto_release(heim_object_t ptr)
|
||||
heim_auto_release_t ar;
|
||||
|
||||
if (ptr == NULL || heim_base_is_tagged(ptr))
|
||||
return;
|
||||
return ptr;
|
||||
|
||||
/* drop from old pool */
|
||||
if ((ar = p->autorelpool) != NULL) {
|
||||
@@ -573,6 +591,8 @@ heim_auto_release(heim_object_t ptr)
|
||||
HEIM_TAILQ_INSERT_HEAD(&ar->pool, p, autorel);
|
||||
p->autorelpool = ar;
|
||||
HEIMDAL_MUTEX_unlock(&ar->pool_mutex);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -177,6 +177,7 @@ heim_string_t heim_string_ref_create(const char *, heim_string_free_f_t);
|
||||
heim_string_t heim_string_create_with_bytes(const void *, size_t);
|
||||
heim_string_t heim_string_ref_create_with_bytes(const void *, size_t,
|
||||
heim_string_free_f_t);
|
||||
heim_string_t heim_string_create_with_format(const char *, ...);
|
||||
heim_tid_t heim_string_get_type_id(void);
|
||||
const char * heim_string_get_utf8(heim_string_t);
|
||||
|
||||
@@ -336,7 +337,7 @@ typedef struct heim_auto_release * heim_auto_release_t;
|
||||
|
||||
heim_auto_release_t heim_auto_release_create(void);
|
||||
void heim_auto_release_drain(heim_auto_release_t);
|
||||
void heim_auto_release(heim_object_t);
|
||||
heim_object_t heim_auto_release(heim_object_t);
|
||||
|
||||
/*
|
||||
* JSON
|
||||
@@ -362,6 +363,13 @@ heim_string_t heim_serialize(heim_object_t, heim_json_flags_t flags,
|
||||
heim_error_t *);
|
||||
|
||||
|
||||
/*
|
||||
* Debug
|
||||
*/
|
||||
|
||||
heim_string_t
|
||||
heim_description(heim_object_t ptr);
|
||||
|
||||
/*
|
||||
* Binary search.
|
||||
*
|
||||
|
@@ -37,6 +37,7 @@ typedef void (*heim_type_init)(void *);
|
||||
typedef heim_object_t (*heim_type_copy)(void *);
|
||||
typedef int (*heim_type_cmp)(void *, void *);
|
||||
typedef unsigned long (*heim_type_hash)(void *);
|
||||
typedef heim_string_t (*heim_type_description)(void *);
|
||||
|
||||
typedef struct heim_type_data *heim_type_t;
|
||||
|
||||
@@ -69,6 +70,7 @@ struct heim_type_data {
|
||||
heim_type_copy copy;
|
||||
heim_type_cmp cmp;
|
||||
heim_type_hash hash;
|
||||
heim_type_description desc;
|
||||
};
|
||||
|
||||
heim_type_t _heim_get_isa(heim_object_t);
|
||||
@@ -79,7 +81,8 @@ _heim_create_type(const char *name,
|
||||
heim_type_dealloc dealloc,
|
||||
heim_type_copy copy,
|
||||
heim_type_cmp cmp,
|
||||
heim_type_hash hash);
|
||||
heim_type_hash hash,
|
||||
heim_type_description desc);
|
||||
|
||||
heim_object_t
|
||||
_heim_alloc_object(heim_type_t type, size_t size);
|
||||
|
@@ -42,6 +42,7 @@ struct heim_type_data _heim_null_object = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@@ -73,7 +73,8 @@ struct heim_type_data _heim_number_object = {
|
||||
number_dealloc,
|
||||
NULL,
|
||||
number_cmp,
|
||||
number_hash
|
||||
number_hash,
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
|
@@ -91,7 +91,8 @@ struct heim_type_data _heim_string_object = {
|
||||
string_dealloc,
|
||||
NULL,
|
||||
string_cmp,
|
||||
string_hash
|
||||
string_hash,
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -158,6 +159,45 @@ heim_string_create_with_bytes(const void *data, size_t len)
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
static void
|
||||
string_free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a string object using a format string
|
||||
*
|
||||
* @param fmt format string
|
||||
* @param ...
|
||||
*
|
||||
* @return string object
|
||||
*/
|
||||
|
||||
heim_string_t
|
||||
heim_string_create_with_format(const char *fmt, ...)
|
||||
{
|
||||
heim_string_t s;
|
||||
char *str = NULL;
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = vasprintf(&str, fmt, ap);
|
||||
va_end(ap);
|
||||
if (ret < 0 || str == NULL)
|
||||
return NULL;
|
||||
|
||||
s = heim_string_ref_create(str, string_dealloc);
|
||||
if (s == NULL)
|
||||
free(str);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type ID of string objects
|
||||
*
|
||||
|
Reference in New Issue
Block a user