Commit 795a1798 authored by vasil's avatar vasil

branches/zip:

Add const qualifier to the value returned by ha_storage_put().
It must not be changed as this will invalidate the hash.
parent 20d7ea98
...@@ -22,7 +22,7 @@ Created September 22, 2007 Vasil Dimov ...@@ -22,7 +22,7 @@ Created September 22, 2007 Vasil Dimov
Retrieves a data from a storage. If it is present, a pointer to the Retrieves a data from a storage. If it is present, a pointer to the
stored copy of data is returned, otherwise NULL is returned. */ stored copy of data is returned, otherwise NULL is returned. */
static static
void* const void*
ha_storage_get( ha_storage_get(
/*===========*/ /*===========*/
ha_storage_t* storage, /* in: hash storage */ ha_storage_t* storage, /* in: hash storage */
...@@ -62,7 +62,7 @@ same data chunk is already present, then pointer to it is returned. ...@@ -62,7 +62,7 @@ same data chunk is already present, then pointer to it is returned.
Data chunks are considered to be equal if len1 == len2 and Data chunks are considered to be equal if len1 == len2 and
memcmp(data1, data2, len1) == 0. */ memcmp(data1, data2, len1) == 0. */
void* const void*
ha_storage_put( ha_storage_put(
/*===========*/ /*===========*/
ha_storage_t* storage, /* in/out: hash storage */ ha_storage_t* storage, /* in/out: hash storage */
...@@ -71,7 +71,7 @@ ha_storage_put( ...@@ -71,7 +71,7 @@ ha_storage_put(
{ {
void* raw; void* raw;
ha_storage_node_t* node; ha_storage_node_t* node;
void* data_copy; const void* data_copy;
ulint fold; ulint fold;
/* check if data chunk is already present */ /* check if data chunk is already present */
...@@ -91,7 +91,7 @@ ha_storage_put( ...@@ -91,7 +91,7 @@ ha_storage_put(
node = (ha_storage_node_t*) raw; node = (ha_storage_node_t*) raw;
data_copy = (byte*) raw + sizeof(*node); data_copy = (byte*) raw + sizeof(*node);
memcpy(data_copy, data, data_len); memcpy((byte*) raw + sizeof(*node), data, data_len);
node->data_len = data_len; node->data_len = data_len;
node->data = data_copy; node->data = data_copy;
...@@ -107,5 +107,7 @@ ha_storage_put( ...@@ -107,5 +107,7 @@ ha_storage_put(
fold, /* key */ fold, /* key */
node); /* add this data to the hash */ node); /* add this data to the hash */
/* the output should not be changed because it will spoil the
hash table */
return(data_copy); return(data_copy);
} }
...@@ -41,7 +41,7 @@ same string is already present, then pointer to it is returned. ...@@ -41,7 +41,7 @@ same string is already present, then pointer to it is returned.
Strings are considered to be equal if strcmp(str1, str2) == 0. */ Strings are considered to be equal if strcmp(str1, str2) == 0. */
#define ha_storage_put_str(storage, str) \ #define ha_storage_put_str(storage, str) \
ha_storage_put((storage), (str), strlen(str) + 1) ((const char*) ha_storage_put((storage), (str), strlen(str) + 1))
/*********************************************************************** /***********************************************************************
Copies data into the storage and returns a pointer to the copy. If the Copies data into the storage and returns a pointer to the copy. If the
...@@ -49,7 +49,7 @@ same data chunk is already present, then pointer to it is returned. ...@@ -49,7 +49,7 @@ same data chunk is already present, then pointer to it is returned.
Data chunks are considered to be equal if len1 == len2 and Data chunks are considered to be equal if len1 == len2 and
memcmp(data1, data2, len1) == 0. */ memcmp(data1, data2, len1) == 0. */
void* const void*
ha_storage_put( ha_storage_put(
/*===========*/ /*===========*/
ha_storage_t* storage, /* in/out: hash storage */ ha_storage_t* storage, /* in/out: hash storage */
......
...@@ -24,7 +24,7 @@ struct ha_storage_struct { ...@@ -24,7 +24,7 @@ struct ha_storage_struct {
typedef struct ha_storage_node_struct ha_storage_node_t; typedef struct ha_storage_node_struct ha_storage_node_t;
struct ha_storage_node_struct { struct ha_storage_node_struct {
ulint data_len;/* length of the data */ ulint data_len;/* length of the data */
void* data; /* pointer to data */ const void* data; /* pointer to data */
ha_storage_node_t* next; /* next node in hash chain */ ha_storage_node_t* next; /* next node in hash chain */
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment