From d4c5d2b9f2f3bb61a11e5d579d37d11a077452df Mon Sep 17 00:00:00 2001 From: englebass Date: Wed, 27 Jan 2010 20:48:27 +0000 Subject: [PATCH] Add EINA_MAGIC to strbuf git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@45651 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/include/eina_private.h | 1 + src/lib/eina_main.c | 4 +++- src/lib/eina_strbuf.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/include/eina_private.h b/src/include/eina_private.h index e3ba452..c3b7b0d 100644 --- a/src/include/eina_private.h +++ b/src/include/eina_private.h @@ -80,6 +80,7 @@ #define EINA_MAGIC_MATRIXSPARSE_CELL_ITERATOR 0x98761248 #define EINA_MAGIC_MATRIXSPARSE_CELL_ACCESSOR 0x98761249 +#define EINA_MAGIC_STRBUF 0x98761250 /* undef the following, we want out version */ diff --git a/src/lib/eina_main.c b/src/lib/eina_main.c index cf469a0..d3a8f59 100644 --- a/src/lib/eina_main.c +++ b/src/lib/eina_main.c @@ -96,6 +96,7 @@ S(convert); S(counter); S(benchmark); S(rectangle); +S(strbuf); #undef S struct eina_desc_setup @@ -122,7 +123,8 @@ static const struct eina_desc_setup _eina_desc_setup[] = { S(convert), S(counter), S(benchmark), - S(rectangle) + S(rectangle), + S(strbuf) #undef S }; static const size_t _eina_desc_setup_len = sizeof(_eina_desc_setup) / sizeof(_eina_desc_setup[0]); diff --git a/src/lib/eina_strbuf.c b/src/lib/eina_strbuf.c index edab7db..199afca 100644 --- a/src/lib/eina_strbuf.c +++ b/src/lib/eina_strbuf.c @@ -7,12 +7,25 @@ # include "config.h" #endif +#include "eina_private.h" #include "eina_str.h" #include "eina_strbuf.h" +#include "eina_magic.h" #include #include +static const char EINA_MAGIC_STRBUF_STR[] = "Eina Strbuf"; + +#define EINA_MAGIC_CHECK_STRBUF(d, ...) \ + do { \ + if (!EINA_MAGIC_CHECK((d), EINA_MAGIC_STRBUF)) \ + { \ + EINA_MAGIC_FAIL((d), EINA_MAGIC_STRBUF); \ + return __VA_ARGS__; \ + } \ + } while (0); + #define EINA_STRBUF_INIT_SIZE 32 #define EINA_STRBUF_INIT_STEP 32 #define EINA_STRBUF_MAX_STEP 4096 @@ -23,10 +36,25 @@ struct _Eina_Strbuf size_t len; size_t size; size_t step; + + EINA_MAGIC }; static int _eina_strbuf_resize(Eina_Strbuf *buf, size_t size); +Eina_Bool +eina_strbuf_init(void) +{ + eina_magic_string_static_set(EINA_MAGIC_STRBUF, EINA_MAGIC_STRBUF_STR); + return EINA_TRUE; +} + +Eina_Bool +eina_strbuf_shutdown(void) +{ + return EINA_TRUE; +} + /** * Create a new string buffer */ @@ -37,6 +65,7 @@ eina_strbuf_new(void) buf = malloc(sizeof(Eina_Strbuf)); if (!buf) return NULL; + EINA_MAGIC_SET(buf, EINA_MAGIC_STRBUF); buf->len = 0; buf->size = EINA_STRBUF_INIT_SIZE; @@ -55,6 +84,7 @@ eina_strbuf_new(void) EAPI void eina_strbuf_free(Eina_Strbuf *buf) { + EINA_MAGIC_CHECK_STRBUF(buf); free(buf->buf); free(buf); } @@ -70,6 +100,8 @@ eina_strbuf_append(Eina_Strbuf *buf, const char *str) size_t l; size_t off = 0; + EINA_MAGIC_CHECK_STRBUF(buf); + l = eina_strlcpy(buf->buf + buf->len, str, buf->size - buf->len); while (l > buf->size - buf->len) @@ -99,6 +131,8 @@ eina_strbuf_insert(Eina_Strbuf *buf, const char *str, size_t pos) { size_t len; + EINA_MAGIC_CHECK_STRBUF(buf); + if (pos >= buf->len) { eina_strbuf_append(buf, str); @@ -127,6 +161,8 @@ eina_strbuf_insert(Eina_Strbuf *buf, const char *str, size_t pos) EAPI void eina_strbuf_append_char(Eina_Strbuf *buf, char c) { + EINA_MAGIC_CHECK_STRBUF(buf); + if (buf->len >= buf->size - 1) { buf->size += buf->step; @@ -149,6 +185,8 @@ eina_strbuf_append_char(Eina_Strbuf *buf, char c) EAPI const char * eina_strbuf_string_get(Eina_Strbuf *buf) { + EINA_MAGIC_CHECK_STRBUF(buf, NULL); + return buf->buf; } @@ -159,6 +197,8 @@ eina_strbuf_string_get(Eina_Strbuf *buf) EAPI size_t eina_strbuf_length_get(Eina_Strbuf *buf) { + EINA_MAGIC_CHECK_STRBUF(buf, 0); + return buf->len; } @@ -175,6 +215,8 @@ EAPI int eina_strbuf_replace(Eina_Strbuf *buf, const char *str, const char *with, unsigned int n) { + EINA_MAGIC_CHECK_STRBUF(buf, 0); + size_t len1, len2; char *spos; size_t pos; @@ -222,6 +264,8 @@ eina_strbuf_replace(Eina_Strbuf *buf, const char *str, const char *with, EAPI int eina_strbuf_replace_all(Eina_Strbuf *buf, const char *str, const char *with) { + EINA_MAGIC_CHECK_STRBUF(buf, 0); + size_t len1, len2, len; char *tmp_buf = NULL; char *spos; -- 2.7.4