From 25a79a1ba8e092efc371070b9f7ceceabcb2a5e5 Mon Sep 17 00:00:00 2001 From: Love Hornquist Astrand Date: Sun, 12 Dec 2010 12:29:09 -0800 Subject: [PATCH] remove tag string --- base/baselocl.h | 5 ----- base/heimbase.h | 1 - base/string.c | 33 +-------------------------------- base/test_base.c | 24 +++++++++++++++++++++--- base/version-script.map | 1 - 5 files changed, 22 insertions(+), 42 deletions(-) diff --git a/base/baselocl.h b/base/baselocl.h index 5f157264c..b3c81b946 100644 --- a/base/baselocl.h +++ b/base/baselocl.h @@ -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)) diff --git a/base/heimbase.h b/base/heimbase.h index 17eb12ea5..d1ca5aa89 100644 --- a/base/heimbase.h +++ b/base/heimbase.h @@ -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); diff --git a/base/string.c b/base/string.c index 414a9161f..11e884115 100644 --- a/base/string.c +++ b/base/string.c @@ -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 * diff --git a/base/test_base.c b/base/test_base.c index 8a2921dfd..5355907c7 100644 --- a/base/test_base.c +++ b/base/test_base.c @@ -34,6 +34,7 @@ */ #include +#include #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; } diff --git a/base/version-script.map b/base/version-script.map index 9886943df..617d4be96 100644 --- a/base/version-script.map +++ b/base/version-script.map @@ -22,7 +22,6 @@ HEIMDAL_BASE_1.0 { heim_string_create; heim_string_get_utf8; heim_number_create; - heim_string_create_with_static; local: *; };