From a2d20c60cd88481989316a8cedf8bd7d1e9be94a Mon Sep 17 00:00:00 2001 From: Maximilian Schwerin Date: Thu, 27 Dec 2007 14:25:28 +0000 Subject: xmlparser: fix token buffer being too small What this patch does is replace the token buffer of static size in xml_parser_get_node with a malloced buffer. If the lexer notices, that it needs more size it just increases the size of this buffer by factor two and tries again. This may not be very elegant, but it works. node_name and property_name are dynamically-sized too. --- src/xine-utils/xmllexer.c | 15 +++++++++++-- src/xine-utils/xmllexer.h | 2 +- src/xine-utils/xmlparser.c | 52 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 60 insertions(+), 9 deletions(-) (limited to 'src/xine-utils') diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c index 047dbb1a6..a77d6654a 100644 --- a/src/xine-utils/xmllexer.c +++ b/src/xine-utils/xmllexer.c @@ -123,7 +123,10 @@ void lexer_init(const char * buf, int size) { lprintf("buffer length %d\n", size); } -int lexer_get_token(char * tok, int tok_size) { +int lexer_get_token(char ** _tok, int * _tok_size) { + char *tok = *_tok; + int tok_size = *_tok_size; + int tok_pos = 0; int state = 0; char c; @@ -455,7 +458,15 @@ int lexer_get_token(char * tok, int tok_size) { /* pb */ if (tok_pos >= tok_size) { - lprintf("token buffer is too little\n"); + *_tok_size *= 2; + *_tok = realloc (*_tok, *_tok_size); + lprintf("token buffer is too small\n"); + lprintf("increasing buffer size to %d bytes\n", *_tok_size); + if (*_tok) { + return lexer_get_token (_tok, _tok_size); + } else { + return T_ERROR; + } } else { if (lexbuf_pos >= lexbuf_size) { /* Terminate the current token */ diff --git a/src/xine-utils/xmllexer.h b/src/xine-utils/xmllexer.h index 1e646f9b5..bf9948d2d 100644 --- a/src/xine-utils/xmllexer.h +++ b/src/xine-utils/xmllexer.h @@ -51,7 +51,7 @@ /* public functions */ void lexer_init(const char * buf, int size) XINE_PROTECTED; -int lexer_get_token(char * tok, int tok_size) XINE_PROTECTED; +int lexer_get_token(char ** tok, int * tok_size) XINE_PROTECTED; char *lexer_decode_entities (const char *tok) XINE_PROTECTED; #endif diff --git a/src/xine-utils/xmlparser.c b/src/xine-utils/xmlparser.c index a5d8212d2..3cc9bc3c2 100644 --- a/src/xine-utils/xmlparser.c +++ b/src/xine-utils/xmlparser.c @@ -153,10 +153,15 @@ void xml_parser_free_tree(xml_node_t *current_node) { #define STATE_NODE 1 #define STATE_COMMENT 7 -static int xml_parser_get_node (xml_node_t *current_node, char *root_name, int rec) { - char tok[TOKEN_SIZE]; - char property_name[TOKEN_SIZE]; - char node_name[TOKEN_SIZE]; +static int xml_parser_get_node (xml_node_t *current_node, char *root_name, int rec); + +static int _xml_parser_get_node (char ** token_buffer, int * token_buffer_size, + char ** pname_buffer, int * pname_buffer_size, + char ** nname_buffer, int * nname_buffer_size, + xml_node_t *current_node, char *root_name, int rec) { + char *tok = *token_buffer; + char *property_name = *pname_buffer; + char *node_name = *nname_buffer; int state = STATE_IDLE; int res = 0; int parse_res; @@ -168,9 +173,10 @@ static int xml_parser_get_node (xml_node_t *current_node, char *root_name, int r if (rec < MAX_RECURSION) { - memset (tok, 0, TOKEN_SIZE); + memset (tok, 0, *token_buffer_size); - while ((bypass_get_token) || (res = lexer_get_token(tok, TOKEN_SIZE)) != T_ERROR) { + while ((bypass_get_token) || (res = lexer_get_token(token_buffer, token_buffer_size)) != T_ERROR) { + tok = *token_buffer; bypass_get_token = 0; lprintf("info: %d - %d : '%s'\n", state, res, tok); @@ -225,6 +231,12 @@ static int xml_parser_get_node (xml_node_t *current_node, char *root_name, int r if (xml_parser_mode == XML_PARSER_CASE_INSENSITIVE) { strtoupper(tok); } + /* make sure the buffer for the node name is big enough */ + if (token_buffer_size > nname_buffer_size) { + *nname_buffer_size = *token_buffer_size; + *nname_buffer = realloc (*nname_buffer, *nname_buffer_size); + node_name = *nname_buffer; + } strcpy(node_name, tok); state = 2; lprintf("info: current node name \"%s\"\n", node_name); @@ -291,6 +303,12 @@ static int xml_parser_get_node (xml_node_t *current_node, char *root_name, int r if (xml_parser_mode == XML_PARSER_CASE_INSENSITIVE) { strtoupper(tok); } + /* make sure the buffer for the property name is big enough */ + if (token_buffer_size > pname_buffer_size) { + *pname_buffer_size = *token_buffer_size; + *pname_buffer = realloc (*pname_buffer, *pname_buffer_size); + property_name = *pname_buffer; + } strcpy(property_name, tok); state = 5; lprintf("info: current property name \"%s\"\n", property_name); @@ -452,6 +470,28 @@ static int xml_parser_get_node (xml_node_t *current_node, char *root_name, int r } } +static int xml_parser_get_node (xml_node_t *current_node, char *root_name, int rec) +{ + int res = 0; + int token_buffer_size = TOKEN_SIZE; + int pname_buffer_size = TOKEN_SIZE; + int nname_buffer_size = TOKEN_SIZE; + char *token_buffer = xine_xmalloc (token_buffer_size); + char *pname_buffer = xine_xmalloc (pname_buffer_size); + char *nname_buffer = xine_xmalloc (nname_buffer_size); + + res = _xml_parser_get_node(&token_buffer, &token_buffer_size, + &pname_buffer, &pname_buffer_size, + &nname_buffer, &nname_buffer_size, + current_node, root_name, rec); + + free (token_buffer); + free (pname_buffer); + free (nname_buffer); + + return res; +} + int xml_parser_build_tree(xml_node_t **root_node) { xml_node_t *tmp_node; int res; -- cgit v1.2.3 From aa3d3aacdb991ad989933d71734e300535c7d350 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 30 Dec 2007 17:23:50 +0000 Subject: Dereference buffer size pointers when comparing buffer sizes. --- src/xine-utils/xmlparser.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/xine-utils') diff --git a/src/xine-utils/xmlparser.c b/src/xine-utils/xmlparser.c index 3cc9bc3c2..cc2bfe462 100644 --- a/src/xine-utils/xmlparser.c +++ b/src/xine-utils/xmlparser.c @@ -231,12 +231,12 @@ static int _xml_parser_get_node (char ** token_buffer, int * token_buffer_size, if (xml_parser_mode == XML_PARSER_CASE_INSENSITIVE) { strtoupper(tok); } - /* make sure the buffer for the node name is big enough */ - if (token_buffer_size > nname_buffer_size) { - *nname_buffer_size = *token_buffer_size; - *nname_buffer = realloc (*nname_buffer, *nname_buffer_size); - node_name = *nname_buffer; - } + /* make sure the buffer for the node name is big enough */ + if (*token_buffer_size > *nname_buffer_size) { + *nname_buffer_size = *token_buffer_size; + *nname_buffer = realloc (*nname_buffer, *nname_buffer_size); + node_name = *nname_buffer; + } strcpy(node_name, tok); state = 2; lprintf("info: current node name \"%s\"\n", node_name); @@ -303,12 +303,12 @@ static int _xml_parser_get_node (char ** token_buffer, int * token_buffer_size, if (xml_parser_mode == XML_PARSER_CASE_INSENSITIVE) { strtoupper(tok); } - /* make sure the buffer for the property name is big enough */ - if (token_buffer_size > pname_buffer_size) { - *pname_buffer_size = *token_buffer_size; - *pname_buffer = realloc (*pname_buffer, *pname_buffer_size); - property_name = *pname_buffer; - } + /* make sure the buffer for the property name is big enough */ + if (*token_buffer_size > *pname_buffer_size) { + *pname_buffer_size = *token_buffer_size; + *pname_buffer = realloc (*pname_buffer, *pname_buffer_size); + property_name = *pname_buffer; + } strcpy(property_name, tok); state = 5; lprintf("info: current property name \"%s\"\n", property_name); -- cgit v1.2.3 From 147a5017b476e4cd61aadb8e7420bc20832abfef Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Mon, 31 Dec 2007 13:29:40 +0000 Subject: Convert XML parser ABI breakage into ABI extension. Bump the soname accordingly. --- src/xine-utils/xmllexer.c | 12 ++++++++++-- src/xine-utils/xmllexer.h | 3 ++- src/xine-utils/xmlparser.c | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src/xine-utils') diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c index a77d6654a..be3bdd248 100644 --- a/src/xine-utils/xmllexer.c +++ b/src/xine-utils/xmllexer.c @@ -123,7 +123,7 @@ void lexer_init(const char * buf, int size) { lprintf("buffer length %d\n", size); } -int lexer_get_token(char ** _tok, int * _tok_size) { +int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { char *tok = *_tok; int tok_size = *_tok_size; @@ -458,12 +458,14 @@ int lexer_get_token(char ** _tok, int * _tok_size) { /* pb */ if (tok_pos >= tok_size) { + if (fixed) + return T_ERROR; *_tok_size *= 2; *_tok = realloc (*_tok, *_tok_size); lprintf("token buffer is too small\n"); lprintf("increasing buffer size to %d bytes\n", *_tok_size); if (*_tok) { - return lexer_get_token (_tok, _tok_size); + return lexer_get_token_d (_tok, _tok_size, 0); } else { return T_ERROR; } @@ -509,6 +511,12 @@ int lexer_get_token(char ** _tok, int * _tok_size) { return T_ERROR; } +/* for ABI compatibility */ +int lexer_get_token (char *tok, int tok_size) +{ + return lexer_get_token_d (&tok, &tok_size, 1); +} + static struct { char code; unsigned char namelen; diff --git a/src/xine-utils/xmllexer.h b/src/xine-utils/xmllexer.h index bf9948d2d..425d0e70a 100644 --- a/src/xine-utils/xmllexer.h +++ b/src/xine-utils/xmllexer.h @@ -51,7 +51,8 @@ /* public functions */ void lexer_init(const char * buf, int size) XINE_PROTECTED; -int lexer_get_token(char ** tok, int * tok_size) XINE_PROTECTED; +int lexer_get_token_d(char ** tok, int * tok_size, int fixed) XINE_PROTECTED; +int lexer_get_token(char * tok, int tok_size) XINE_PROTECTED; char *lexer_decode_entities (const char *tok) XINE_PROTECTED; #endif diff --git a/src/xine-utils/xmlparser.c b/src/xine-utils/xmlparser.c index cc2bfe462..14ce35c54 100644 --- a/src/xine-utils/xmlparser.c +++ b/src/xine-utils/xmlparser.c @@ -175,7 +175,7 @@ static int _xml_parser_get_node (char ** token_buffer, int * token_buffer_size, memset (tok, 0, *token_buffer_size); - while ((bypass_get_token) || (res = lexer_get_token(token_buffer, token_buffer_size)) != T_ERROR) { + while ((bypass_get_token) || (res = lexer_get_token_d(token_buffer, token_buffer_size, 0)) != T_ERROR) { tok = *token_buffer; bypass_get_token = 0; lprintf("info: %d - %d : '%s'\n", state, res, tok); -- cgit v1.2.3 From 02b3ff2b8d85f9775f6362ad08435e6b07a4b1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 2 Jan 2008 17:57:42 +0100 Subject: Make lang_locales a big static read-only table. This way there is no need to relocate all the string entries, although it does use more space on disk and probably mapped in memory. Check http://farragut.flameeyes.is-a-geek.org/articles/2008/01/01/some-more-about-arrays-of-strings for more information about string entries and PIC. --- src/xine-utils/utils.c | 300 ++++++++++++++++++++++++------------------------- 1 file changed, 150 insertions(+), 150 deletions(-) (limited to 'src/xine-utils') diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index 63d7d343b..8421b2374 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -57,10 +57,10 @@ #endif typedef struct { - char *language; /* name of the locale */ - char *encoding; /* typical encoding */ - char *spu_encoding; /* default spu encoding */ - char *modifier; + const char language[16]; /* name of the locale */ + const char encoding[16]; /* typical encoding */ + const char spu_encoding[16]; /* default spu encoding */ + const char modifier[8]; } lang_locale_t; @@ -68,172 +68,172 @@ typedef struct { * information about locales used in xine */ static const lang_locale_t lang_locales[] = { - { "af_ZA", "iso-8859-1", "iso-8859-1", NULL }, - { "ar_AE", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_BH", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_DZ", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_EG", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_IN", "utf-8", "utf-8", NULL }, - { "ar_IQ", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_JO", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_KW", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_LB", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_LY", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_MA", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_OM", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_QA", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_SA", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_SD", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_SY", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_TN", "iso-8859-6", "iso-8859-6", NULL }, - { "ar_YE", "iso-8859-6", "iso-8859-6", NULL }, - { "be_BY", "cp1251", "cp1251", NULL }, - { "bg_BG", "cp1251", "cp1251", NULL }, - { "br_FR", "iso-8859-1", "iso-88591", NULL }, - { "bs_BA", "iso-8859-2", "cp1250", NULL }, - { "ca_ES", "iso-8859-1", "iso-88591", NULL }, + { "af_ZA", "iso-8859-1", "iso-8859-1", "" }, + { "ar_AE", "iso-8859-6", "iso-8859-6", "" }, + { "ar_BH", "iso-8859-6", "iso-8859-6", "" }, + { "ar_DZ", "iso-8859-6", "iso-8859-6", "" }, + { "ar_EG", "iso-8859-6", "iso-8859-6", "" }, + { "ar_IN", "utf-8", "utf-8", "" }, + { "ar_IQ", "iso-8859-6", "iso-8859-6", "" }, + { "ar_JO", "iso-8859-6", "iso-8859-6", "" }, + { "ar_KW", "iso-8859-6", "iso-8859-6", "" }, + { "ar_LB", "iso-8859-6", "iso-8859-6", "" }, + { "ar_LY", "iso-8859-6", "iso-8859-6", "" }, + { "ar_MA", "iso-8859-6", "iso-8859-6", "" }, + { "ar_OM", "iso-8859-6", "iso-8859-6", "" }, + { "ar_QA", "iso-8859-6", "iso-8859-6", "" }, + { "ar_SA", "iso-8859-6", "iso-8859-6", "" }, + { "ar_SD", "iso-8859-6", "iso-8859-6", "" }, + { "ar_SY", "iso-8859-6", "iso-8859-6", "" }, + { "ar_TN", "iso-8859-6", "iso-8859-6", "" }, + { "ar_YE", "iso-8859-6", "iso-8859-6", "" }, + { "be_BY", "cp1251", "cp1251", "" }, + { "bg_BG", "cp1251", "cp1251", "" }, + { "br_FR", "iso-8859-1", "iso-88591", "" }, + { "bs_BA", "iso-8859-2", "cp1250", "" }, + { "ca_ES", "iso-8859-1", "iso-88591", "" }, { "ca_ES", "iso-8859-15", "iso-8859-15", "euro" }, - { "cs_CZ", "iso-8859-2", "cp1250", NULL }, - { "cy_GB", "iso-8859-14", "iso-8859-14", NULL }, - { "da_DK", "iso-8859-1", "iso-8859-1", NULL }, - { "de_AT", "iso-8859-1", "iso-8859-1", NULL }, + { "cs_CZ", "iso-8859-2", "cp1250", "" }, + { "cy_GB", "iso-8859-14", "iso-8859-14", "" }, + { "da_DK", "iso-8859-1", "iso-8859-1", "" }, + { "de_AT", "iso-8859-1", "iso-8859-1", "" }, { "de_AT", "iso-8859-15", "iso-8859-15", "euro" }, - { "de_BE", "iso-8859-1", "iso-8859-1", NULL }, + { "de_BE", "iso-8859-1", "iso-8859-1", "" }, { "de_BE", "iso-8859-15", "iso-8859-15", "euro" }, - { "de_CH", "iso-8859-1", "iso-8859-1", NULL }, - { "de_DE", "iso-8859-1", "iso-8859-1", NULL }, + { "de_CH", "iso-8859-1", "iso-8859-1", "" }, + { "de_DE", "iso-8859-1", "iso-8859-1", "" }, { "de_DE", "iso-8859-15", "iso-8859-15", "euro" }, - { "de_LU", "iso-8859-1", "iso-8859-1", NULL }, + { "de_LU", "iso-8859-1", "iso-8859-1", "" }, { "de_LU", "iso-8859-15", "iso-8859-15", "euro" }, - { "el_GR", "iso-8859-7", "iso-8859-7", NULL }, - { "en_AU", "iso-8859-1", "iso-8859-1", NULL }, - { "en_BW", "iso-8859-1", "iso-8859-1", NULL }, - { "en_CA", "iso-8859-1", "iso-8859-1", NULL }, - { "en_DK", "iso-8859-1", "iso-8859-1", NULL }, - { "en_GB", "iso-8859-1", "iso-8859-1", NULL }, - { "en_HK", "iso-8859-1", "iso-8859-1", NULL }, - { "en_IE", "iso-8859-1", "iso-8859-1", NULL }, + { "el_GR", "iso-8859-7", "iso-8859-7", "" }, + { "en_AU", "iso-8859-1", "iso-8859-1", "" }, + { "en_BW", "iso-8859-1", "iso-8859-1", "" }, + { "en_CA", "iso-8859-1", "iso-8859-1", "" }, + { "en_DK", "iso-8859-1", "iso-8859-1", "" }, + { "en_GB", "iso-8859-1", "iso-8859-1", "" }, + { "en_HK", "iso-8859-1", "iso-8859-1", "" }, + { "en_IE", "iso-8859-1", "iso-8859-1", "" }, { "en_IE", "iso-8859-15", "iso-8859-15", "euro" }, - { "en_IN", "utf-8", "utf-8", NULL }, - { "en_NZ", "iso-8859-1", "iso-8859-1", NULL }, - { "en_PH", "iso-8859-1", "iso-8859-1", NULL }, - { "en_SG", "iso-8859-1", "iso-8859-1", NULL }, - { "en_US", "iso-8859-1", "iso-8859-1", NULL }, - { "en_ZA", "iso-8859-1", "iso-8859-1", NULL }, - { "en_ZW", "iso-8859-1", "iso-8859-1", NULL }, - { "es_AR", "iso-8859-1", "iso-8859-1", NULL }, - { "es_BO", "iso-8859-1", "iso-8859-1", NULL }, - { "es_CL", "iso-8859-1", "iso-8859-1", NULL }, - { "es_CO", "iso-8859-1", "iso-8859-1", NULL }, - { "es_CR", "iso-8859-1", "iso-8859-1", NULL }, - { "es_DO", "iso-8859-1", "iso-8859-1", NULL }, - { "es_EC", "iso-8859-1", "iso-8859-1", NULL }, - { "es_ES", "iso-8859-1", "iso-8859-1", NULL }, + { "en_IN", "utf-8", "utf-8", "" }, + { "en_NZ", "iso-8859-1", "iso-8859-1", "" }, + { "en_PH", "iso-8859-1", "iso-8859-1", "" }, + { "en_SG", "iso-8859-1", "iso-8859-1", "" }, + { "en_US", "iso-8859-1", "iso-8859-1", "" }, + { "en_ZA", "iso-8859-1", "iso-8859-1", "" }, + { "en_ZW", "iso-8859-1", "iso-8859-1", "" }, + { "es_AR", "iso-8859-1", "iso-8859-1", "" }, + { "es_BO", "iso-8859-1", "iso-8859-1", "" }, + { "es_CL", "iso-8859-1", "iso-8859-1", "" }, + { "es_CO", "iso-8859-1", "iso-8859-1", "" }, + { "es_CR", "iso-8859-1", "iso-8859-1", "" }, + { "es_DO", "iso-8859-1", "iso-8859-1", "" }, + { "es_EC", "iso-8859-1", "iso-8859-1", "" }, + { "es_ES", "iso-8859-1", "iso-8859-1", "" }, { "es_ES", "iso-8859-15", "iso-8859-15", "euro" }, - { "es_GT", "iso-8859-1", "iso-8859-1", NULL }, - { "es_HN", "iso-8859-1", "iso-8859-1", NULL }, - { "es_MX", "iso-8859-1", "iso-8859-1", NULL }, - { "es_NI", "iso-8859-1", "iso-8859-1", NULL }, - { "es_PA", "iso-8859-1", "iso-8859-1", NULL }, - { "es_PE", "iso-8859-1", "iso-8859-1", NULL }, - { "es_PR", "iso-8859-1", "iso-8859-1", NULL }, - { "es_PY", "iso-8859-1", "iso-8859-1", NULL }, - { "es_SV", "iso-8859-1", "iso-8859-1", NULL }, - { "es_US", "iso-8859-1", "iso-8859-1", NULL }, - { "es_UY", "iso-8859-1", "iso-8859-1", NULL }, - { "es_VE", "iso-8859-1", "iso-8859-1", NULL }, - { "et_EE", "iso-8859-1", "iso-8859-1", NULL }, - { "eu_ES", "iso-8859-1", "iso-8859-1", NULL }, + { "es_GT", "iso-8859-1", "iso-8859-1", "" }, + { "es_HN", "iso-8859-1", "iso-8859-1", "" }, + { "es_MX", "iso-8859-1", "iso-8859-1", "" }, + { "es_NI", "iso-8859-1", "iso-8859-1", "" }, + { "es_PA", "iso-8859-1", "iso-8859-1", "" }, + { "es_PE", "iso-8859-1", "iso-8859-1", "" }, + { "es_PR", "iso-8859-1", "iso-8859-1", "" }, + { "es_PY", "iso-8859-1", "iso-8859-1", "" }, + { "es_SV", "iso-8859-1", "iso-8859-1", "" }, + { "es_US", "iso-8859-1", "iso-8859-1", "" }, + { "es_UY", "iso-8859-1", "iso-8859-1", "" }, + { "es_VE", "iso-8859-1", "iso-8859-1", "" }, + { "et_EE", "iso-8859-1", "iso-8859-1", "" }, + { "eu_ES", "iso-8859-1", "iso-8859-1", "" }, { "eu_ES", "iso-8859-15", "iso-8859-15", "euro" }, - { "fa_IR", "utf-8", "utf-8", NULL }, - { "fi_FI", "iso-8859-1", "iso-8859-1", NULL }, + { "fa_IR", "utf-8", "utf-8", "" }, + { "fi_FI", "iso-8859-1", "iso-8859-1", "" }, { "fi_FI", "iso-8859-15", "iso-8859-15", "euro" }, - { "fo_FO", "iso-8859-1", "iso-8859-1", NULL }, - { "fr_BE", "iso-8859-1", "iso-8859-1", NULL }, + { "fo_FO", "iso-8859-1", "iso-8859-1", "" }, + { "fr_BE", "iso-8859-1", "iso-8859-1", "" }, { "fr_BE", "iso-8859-15", "iso-8859-15", "euro" }, - { "fr_CA", "iso-8859-1", "iso-8859-1", NULL }, - { "fr_CH", "iso-8859-1", "iso-8859-1", NULL }, - { "fr_FR", "iso-8859-1", "iso-8859-1", NULL }, + { "fr_CA", "iso-8859-1", "iso-8859-1", "" }, + { "fr_CH", "iso-8859-1", "iso-8859-1", "" }, + { "fr_FR", "iso-8859-1", "iso-8859-1", "" }, { "fr_FR", "iso-8859-15", "iso-8859-15", "euro" }, - { "fr_LU", "iso-8859-1", "iso-8859-1", NULL }, + { "fr_LU", "iso-8859-1", "iso-8859-1", "" }, { "fr_LU", "iso-8859-15", "iso-8859-15", "euro" }, - { "ga_IE", "iso-8859-1", "iso-8859-1", NULL }, + { "ga_IE", "iso-8859-1", "iso-8859-1", "" }, { "ga_IE", "iso-8859-15", "iso-8859-15", "euro" }, - { "gl_ES", "iso-8859-1", "iso-8859-1", NULL }, + { "gl_ES", "iso-8859-1", "iso-8859-1", "" }, { "gl_ES", "iso-8859-15", "iso-8859-15", "euro" }, - { "gv_GB", "iso-8859-1", "iso-8859-1", NULL }, - { "he_IL", "iso-8859-8", "iso-8859-8", NULL }, - { "hi_IN", "utf-8", "utf-8", NULL }, - { "hr_HR", "iso-8859-2", "cp1250", NULL }, - { "hu_HU", "iso-8859-2", "cp1250", NULL }, - { "id_ID", "iso-8859-1", "iso-8859-1", NULL }, - { "is_IS", "iso-8859-1", "iso-8859-1", NULL }, - { "it_CH", "iso-8859-1", "iso-8859-1", NULL }, - { "it_IT", "iso-8859-1", "iso-8859-1", NULL }, + { "gv_GB", "iso-8859-1", "iso-8859-1", "" }, + { "he_IL", "iso-8859-8", "iso-8859-8", "" }, + { "hi_IN", "utf-8", "utf-8", "" }, + { "hr_HR", "iso-8859-2", "cp1250", "" }, + { "hu_HU", "iso-8859-2", "cp1250", "" }, + { "id_ID", "iso-8859-1", "iso-8859-1", "" }, + { "is_IS", "iso-8859-1", "iso-8859-1", "" }, + { "it_CH", "iso-8859-1", "iso-8859-1", "" }, + { "it_IT", "iso-8859-1", "iso-8859-1", "" }, { "it_IT", "iso-8859-15", "iso-8859-15", "euro" }, - { "iw_IL", "iso-8859-8", "iso-8859-8", NULL }, - { "ja_JP", "euc-jp", "euc-jp", NULL }, - { "ja_JP", "ujis", "ujis", NULL }, - { "japanese", "euc", "euc", NULL }, - { "ka_GE", "georgian-ps", "georgian-ps", NULL }, - { "kl_GL", "iso-8859-1", "iso-8859-1", NULL }, - { "ko_KR", "euc-kr", "euc-kr", NULL }, - { "ko_KR", "utf-8", "utf-8", NULL }, - { "korean", "euc", "euc", NULL }, - { "kw_GB", "iso-8859-1", "iso-8859-1", NULL }, - { "lt_LT", "iso-8859-13", "iso-8859-13", NULL }, - { "lv_LV", "iso-8859-13", "iso-8859-13", NULL }, - { "mi_NZ", "iso-8859-13", "iso-8859-13", NULL }, - { "mk_MK", "iso-8859-5", "cp1251", NULL }, - { "mr_IN", "utf-8", "utf-8", NULL }, - { "ms_MY", "iso-8859-1", "iso-8859-1", NULL }, - { "mt_MT", "iso-8859-3", "iso-8859-3", NULL }, - { "nb_NO", "ISO-8859-1", "ISO-8859-1", NULL }, - { "nl_BE", "iso-8859-1", "iso-8859-1", NULL }, + { "iw_IL", "iso-8859-8", "iso-8859-8", "" }, + { "ja_JP", "euc-jp", "euc-jp", "" }, + { "ja_JP", "ujis", "ujis", "" }, + { "japanese", "euc", "euc", "" }, + { "ka_GE", "georgian-ps", "georgian-ps", "" }, + { "kl_GL", "iso-8859-1", "iso-8859-1", "" }, + { "ko_KR", "euc-kr", "euc-kr", "" }, + { "ko_KR", "utf-8", "utf-8", "" }, + { "korean", "euc", "euc", "" }, + { "kw_GB", "iso-8859-1", "iso-8859-1", "" }, + { "lt_LT", "iso-8859-13", "iso-8859-13", "" }, + { "lv_LV", "iso-8859-13", "iso-8859-13", "" }, + { "mi_NZ", "iso-8859-13", "iso-8859-13", "" }, + { "mk_MK", "iso-8859-5", "cp1251", "" }, + { "mr_IN", "utf-8", "utf-8", "" }, + { "ms_MY", "iso-8859-1", "iso-8859-1", "" }, + { "mt_MT", "iso-8859-3", "iso-8859-3", "" }, + { "nb_NO", "ISO-8859-1", "ISO-8859-1", "" }, + { "nl_BE", "iso-8859-1", "iso-8859-1", "" }, { "nl_BE", "iso-8859-15", "iso-8859-15", "euro" }, - { "nl_NL", "iso-8859-1", "iso-8859-1", NULL }, + { "nl_NL", "iso-8859-1", "iso-8859-1", "" }, { "nl_NL", "iso-8859-15", "iso-8859-15", "euro" }, - { "nn_NO", "iso-8859-1", "iso-8859-1", NULL }, - { "no_NO", "iso-8859-1", "iso-8859-1", NULL }, - { "oc_FR", "iso-8859-1", "iso-8859-1", NULL }, - { "pl_PL", "iso-8859-2", "cp1250", NULL }, - { "pt_BR", "iso-8859-1", "iso-8859-1", NULL }, - { "pt_PT", "iso-8859-1", "iso-8859-1", NULL }, + { "nn_NO", "iso-8859-1", "iso-8859-1", "" }, + { "no_NO", "iso-8859-1", "iso-8859-1", "" }, + { "oc_FR", "iso-8859-1", "iso-8859-1", "" }, + { "pl_PL", "iso-8859-2", "cp1250", "" }, + { "pt_BR", "iso-8859-1", "iso-8859-1", "" }, + { "pt_PT", "iso-8859-1", "iso-8859-1", "" }, { "pt_PT", "iso-8859-15", "iso-8859-15", "euro" }, - { "ro_RO", "iso-8859-2", "cp1250", NULL }, - { "ru_RU", "iso-8859-5", "cp1251", NULL }, - { "ru_RU", "koi8-r", "cp1251", NULL }, - { "ru_UA", "koi8-u", "cp1251", NULL }, - { "se_NO", "utf-8", "utf-8", NULL }, - { "sk_SK", "iso-8859-2", "cp1250", NULL }, - { "sl_SI", "iso-8859-2", "cp1250", NULL }, - { "sq_AL", "iso-8859-1", "iso-8859-1", NULL }, - { "sr_YU", "iso-8859-2", "cp1250", NULL }, + { "ro_RO", "iso-8859-2", "cp1250", "" }, + { "ru_RU", "iso-8859-5", "cp1251", "" }, + { "ru_RU", "koi8-r", "cp1251", "" }, + { "ru_UA", "koi8-u", "cp1251", "" }, + { "se_NO", "utf-8", "utf-8", "" }, + { "sk_SK", "iso-8859-2", "cp1250", "" }, + { "sl_SI", "iso-8859-2", "cp1250", "" }, + { "sq_AL", "iso-8859-1", "iso-8859-1", "" }, + { "sr_YU", "iso-8859-2", "cp1250", "" }, { "sr_YU", "iso-8859-5", "cp1251", "cyrillic" }, - { "sv_FI", "iso-8859-1", "iso-8859-1", NULL }, + { "sv_FI", "iso-8859-1", "iso-8859-1", "" }, { "sv_FI", "iso-8859-15", "iso-8859-15", "euro" }, - { "sv_SE", "iso-8859-1", "iso-8859-1", NULL }, - { "ta_IN", "utf-8", "utf-8", NULL }, - { "te_IN", "utf-8", "utf-8", NULL }, - { "tg_TJ", "koi8-t", "cp1251", NULL }, - { "th_TH", "tis-620", "tis-620", NULL }, - { "tl_PH", "iso-8859-1", "iso-8859-1", NULL }, - { "tr_TR", "iso-8859-9", "iso-8859-9", NULL }, - { "uk_UA", "koi8-u", "cp1251", NULL }, - { "ur_PK", "utf-8", "utf-8", NULL }, - { "uz_UZ", "iso-8859-1", "iso-8859-1", NULL }, - { "vi_VN", "tcvn", "tcvn", NULL }, - { "vi_VN", "utf-8", "utf-8", NULL }, - { "wa_BE", "iso-8859-1", "iso-8859-1", NULL }, + { "sv_SE", "iso-8859-1", "iso-8859-1", "" }, + { "ta_IN", "utf-8", "utf-8", "" }, + { "te_IN", "utf-8", "utf-8", "" }, + { "tg_TJ", "koi8-t", "cp1251", "" }, + { "th_TH", "tis-620", "tis-620", "" }, + { "tl_PH", "iso-8859-1", "iso-8859-1", "" }, + { "tr_TR", "iso-8859-9", "iso-8859-9", "" }, + { "uk_UA", "koi8-u", "cp1251", "" }, + { "ur_PK", "utf-8", "utf-8", "" }, + { "uz_UZ", "iso-8859-1", "iso-8859-1", "" }, + { "vi_VN", "tcvn", "tcvn", "" }, + { "vi_VN", "utf-8", "utf-8", "" }, + { "wa_BE", "iso-8859-1", "iso-8859-1", "" }, { "wa_BE", "iso-8859-15", "iso-8859-15", "euro" }, - { "yi_US", "cp1255", "cp1255", NULL }, - { "zh_CN", "gb18030", "gb18030", NULL }, - { "zh_CN", "gb2312", "gb2312", NULL }, - { "zh_CN", "gbk", "gbk", NULL }, - { "zh_HK", "big5-hkscs", "big5-hkscs", NULL }, - { "zh_TW", "big-5", "big-5", NULL }, - { "zh_TW", "euc-tw", "euc-tw", NULL }, - { NULL, NULL, NULL, NULL } + { "yi_US", "cp1255", "cp1255", "" }, + { "zh_CN", "gb18030", "gb18030", "" }, + { "zh_CN", "gb2312", "gb2312", "" }, + { "zh_CN", "gbk", "gbk", "" }, + { "zh_HK", "big5-hkscs", "big5-hkscs", "" }, + { "zh_TW", "big-5", "big-5", "" }, + { "zh_TW", "euc-tw", "euc-tw", "" }, + { "" } }; @@ -544,7 +544,7 @@ static const lang_locale_t *_get_first_lang_locale(const char *lcal) { else lang_len = strlen(lcal); - while(llocale->language) { + while(*(llocale->language)) { if(!strncmp(lcal, llocale->language, lang_len)) { if ((!mod && !llocale->modifier) || (mod && llocale->modifier && !strcmp(mod, llocale->modifier))) return llocale; -- cgit v1.2.3 From 8fbd00a2a9d6ccdec146a467b0ee4da9d319415a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 2 Jan 2008 19:01:17 +0100 Subject: The name of the memcpy method is constant. Changing this to a character array increase code size, has to be evaluated. --- src/xine-utils/memcpy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/xine-utils') diff --git a/src/xine-utils/memcpy.c b/src/xine-utils/memcpy.c index 15b0b228b..fc42f3399 100644 --- a/src/xine-utils/memcpy.c +++ b/src/xine-utils/memcpy.c @@ -383,7 +383,7 @@ static void *linux_kernel_memcpy(void *to, const void *from, size_t len) { #endif /* ARCH_X86 */ static struct { - char *const name; + const char *const name; void *(*const function)(void *to, const void *from, size_t len); uint64_t time; /* This type could be used for non-MSC build too! */ -- cgit v1.2.3 From a2a95425350da93551388acdca8a00818a34c317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Thu, 3 Jan 2008 01:38:06 +0100 Subject: Make memcpy_method a static constant structure, and replace the name string with an array of characters. Move timing results to a different static array, to reduce the amount of data that would go to .data section. --- src/xine-utils/memcpy.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'src/xine-utils') diff --git a/src/xine-utils/memcpy.c b/src/xine-utils/memcpy.c index fc42f3399..45009d23c 100644 --- a/src/xine-utils/memcpy.c +++ b/src/xine-utils/memcpy.c @@ -382,30 +382,29 @@ static void *linux_kernel_memcpy(void *to, const void *from, size_t len) { #endif /* _MSC_VER */ #endif /* ARCH_X86 */ -static struct { - const char *const name; +static const struct { + const char name[16]; void *(*const function)(void *to, const void *from, size_t len); - uint64_t time; /* This type could be used for non-MSC build too! */ - uint32_t cpu_require; } memcpy_method[] = { - { NULL, NULL, 0, 0 }, - { "libc memcpy()", memcpy, 0, 0 }, + { "", NULL, 0 }, + { "libc", memcpy, 0 }, #if (defined(ARCH_X86) || defined(ARCH_X86_64)) && !defined(_MSC_VER) - { "linux kernel memcpy()", linux_kernel_memcpy, 0, 0 }, - { "MMX optimized memcpy()", mmx_memcpy, 0, MM_MMX }, - { "MMXEXT optimized memcpy()", mmx2_memcpy, 0, MM_MMXEXT }, - { "SSE optimized memcpy()", sse_memcpy, 0, MM_MMXEXT|MM_SSE }, + { "linux kernel", linux_kernel_memcpy, 0 }, + { "MMX ", mmx_memcpy, MM_MMX }, + { "MMXEXT", mmx2_memcpy, MM_MMXEXT }, + { "SSE", sse_memcpy, MM_MMXEXT|MM_SSE }, #endif /* ARCH_X86 */ #if defined (ARCH_PPC) && !defined (HOST_OS_DARWIN) - { "ppcasm_memcpy()", ppcasm_memcpy, 0, 0 }, - { "ppcasm_cacheable_memcpy()", ppcasm_cacheable_memcpy, 0, MM_ACCEL_PPC_CACHE32 }, + { "ppcasm", ppcasm_memcpy, 0 }, + { "ppcasm_cached", ppcasm_cacheable_memcpy, MM_ACCEL_PPC_CACHE32 }, #endif /* ARCH_PPC && !HOST_OS_DARWIN */ - { NULL, NULL, 0, 0 } }; +static uint64_t memcpy_timing[sizeof(memcpy_method)/sizeof(memcpy_method[0])] = { 0, }; + #if (defined(ARCH_X86) || defined(ARCH_X86_64)) && defined(HAVE_SYS_TIMES_H) static int64_t rdtsc(int config_flags) { @@ -446,7 +445,7 @@ static void update_fast_memcpy(void *user_data, xine_cfg_entry_t *entry) { if (method != 0 && (config_flags & memcpy_method[method].cpu_require) == memcpy_method[method].cpu_require ) { - lprintf("using %s\n", memcpy_method[method].name ); + lprintf("using %s memcpy()\n", memcpy_method[method].name ); xine_fast_memcpy = memcpy_method[method].function; return; } else { @@ -487,7 +486,7 @@ void xine_probe_fast_memcpy(xine_t *xine) if( best != 0 && (config_flags & memcpy_method[best].cpu_require) == memcpy_method[best].cpu_require ) { - lprintf("using %s\n", memcpy_method[best].name ); + lprintf("using %s memcpy()\n", memcpy_method[best].name ); xine_fast_memcpy = memcpy_method[best].function; return; } @@ -509,7 +508,7 @@ void xine_probe_fast_memcpy(xine_t *xine) memset(buf1,0,BUFSIZE); memset(buf2,0,BUFSIZE); - for(i=1; memcpy_method[i].name; i++) + for(i = 1; i < sizeof(memcpy_method)/sizeof(memcpy_method[0]); i++) { if( (config_flags & memcpy_method[i].cpu_require) != memcpy_method[i].cpu_require ) @@ -522,11 +521,11 @@ void xine_probe_fast_memcpy(xine_t *xine) } t = rdtsc(config_flags) - t; - memcpy_method[i].time = t; + memcpy_timing[i] = t; - xprintf(xine, XINE_VERBOSITY_LOG, "\t%s : %" PRIu64 "\n", memcpy_method[i].name, t); + xprintf(xine, XINE_VERBOSITY_LOG, "\t%s memcpy() : %" PRIu64 "\n", memcpy_method[i].name, t); - if( best == 0 || t < memcpy_method[best].time ) + if( best == 0 || t < memcpy_timing[best] ) best = i; } -- cgit v1.2.3