remove tag string
This commit is contained in:
@@ -106,11 +106,6 @@ heim_base_atomic_dec(heim_base_atomic_type *x)
|
||||
/* tagged strings/object/XXX */
|
||||
#define heim_base_is_tagged(x) (((uintptr_t)(x)) & 0x3)
|
||||
|
||||
#define heim_base_is_tagged_string(x) ((((uintptr_t)(x)) & 0x3) == 2)
|
||||
#define heim_base_make_tagged_string_ptr(x) ((heim_object_t)(((uintptr_t)(x)) | 2))
|
||||
#define heim_base_tagged_string_ptr(x) ((char *)(((uintptr_t)(x)) & (~3)))
|
||||
|
||||
|
||||
#define heim_base_is_tagged_object(x) ((((uintptr_t)(x)) & 0x3) == 1)
|
||||
#define heim_base_make_tagged_object(x, tid) \
|
||||
((heim_object_t)((((uintptr_t)(x)) << 5) | ((tid) << 2) | 0x1))
|
||||
|
@@ -146,7 +146,6 @@ void heim_dict_delete_key(heim_dict_t, heim_object_t);
|
||||
typedef struct heim_string_data *heim_string_t;
|
||||
|
||||
heim_string_t heim_string_create(const char *);
|
||||
heim_string_t heim_string_create_with_static(const char *);
|
||||
heim_tid_t heim_string_get_type_id(void);
|
||||
const char * heim_string_get_utf8(heim_string_t);
|
||||
|
||||
|
@@ -44,31 +44,20 @@ string_dealloc(void *ptr)
|
||||
static int
|
||||
string_cmp(void *a, void *b)
|
||||
{
|
||||
if (heim_base_is_tagged_string(a))
|
||||
a = heim_base_tagged_string_ptr(a);
|
||||
if (heim_base_is_tagged_string(b))
|
||||
b = heim_base_tagged_string_ptr(b);
|
||||
|
||||
return strcmp(a, b);
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
string_hash(void *ptr)
|
||||
{
|
||||
const char *s;
|
||||
const char *s = ptr;
|
||||
unsigned long n;
|
||||
|
||||
if (heim_base_is_tagged_string(ptr))
|
||||
s = heim_base_tagged_string_ptr(ptr);
|
||||
else
|
||||
s = ptr;
|
||||
|
||||
for (n = 0; *s; ++s)
|
||||
n += *s;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
struct heim_type_data _heim_string_object = {
|
||||
HEIM_TID_STRING,
|
||||
"string-object",
|
||||
@@ -99,26 +88,6 @@ heim_string_create(const char *string)
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a string object from a strings allocated in the text segment.
|
||||
*
|
||||
* Note that static string object wont be auto released with
|
||||
* heim_auto_release(), the allocation policy of the string must
|
||||
* be manged separately from the returned object. This make this
|
||||
* function not very useful for strings in allocated from heap or
|
||||
* stack. In that case you should use heim_string_create().
|
||||
*
|
||||
* @param string the string to create, must be an utf8 string
|
||||
*
|
||||
* @return string object
|
||||
*/
|
||||
|
||||
heim_string_t
|
||||
heim_string_create_with_static(const char *string)
|
||||
{
|
||||
return heim_base_make_tagged_string_ptr(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type ID of string objects
|
||||
*
|
||||
|
@@ -34,6 +34,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "heimbase.h"
|
||||
#include "heimbasepriv.h"
|
||||
@@ -103,9 +104,6 @@ test_auto_release(void)
|
||||
s1 = heim_string_create("hejsan");
|
||||
heim_auto_release(s1);
|
||||
|
||||
s1 = heim_string_create_with_static("hejsan");
|
||||
heim_auto_release(s1);
|
||||
|
||||
n1 = heim_number_create(1);
|
||||
heim_auto_release(n1);
|
||||
|
||||
@@ -120,6 +118,25 @@ test_auto_release(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
test_string(void)
|
||||
{
|
||||
heim_string_t s1, s2;
|
||||
const char *string = "hejsan";
|
||||
|
||||
s1 = heim_string_create(string);
|
||||
s2 = heim_string_create(string);
|
||||
|
||||
if (heim_cmp(s1, s2) != 0)
|
||||
errx(1, "the same string is not the same");
|
||||
|
||||
|
||||
heim_release(s1);
|
||||
heim_release(s2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@@ -128,6 +145,7 @@ main(int argc, char **argv)
|
||||
res |= test_memory();
|
||||
res |= test_dict();
|
||||
res |= test_auto_release();
|
||||
res |= test_string();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@@ -22,7 +22,6 @@ HEIMDAL_BASE_1.0 {
|
||||
heim_string_create;
|
||||
heim_string_get_utf8;
|
||||
heim_number_create;
|
||||
heim_string_create_with_static;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
Reference in New Issue
Block a user