Author: petdance
Date: Fri May 25 18:53:05 2007
New Revision: 18643
Modified:
trunk/include/parrot/charset.h
trunk/include/parrot/hash.h
trunk/include/parrot/string_funcs.h
trunk/src/hash.c
trunk/src/objects.c
trunk/src/string.c
Log:
Lots of consting. Many typedefs of function pointers need to get their
consting in order
Modified: trunk/include/parrot/charset.h
==============================================================================
--- trunk/include/parrot/charset.h (original)
+++ trunk/include/parrot/charset.h Fri May 25 18:53:05 2007
@@ -49,7 +49,7 @@
typedef void (*charset_upcase_first_t)(Interp *, STRING *source_string);
typedef void (*charset_downcase_first_t)(Interp *, STRING *source_string);
typedef void (*charset_titlecase_first_t)(Interp *, STRING *source_string);
-typedef INTVAL (*charset_compare_t)(Interp *, STRING *lhs, STRING *rhs);
+typedef INTVAL (*charset_compare_t)(Interp *, const STRING *lhs, const STRING
*rhs);
typedef INTVAL (*charset_index_t)(Interp *, STRING *source_string, STRING
*search_string, UINTVAL offset);
typedef INTVAL (*charset_rindex_t)(Interp *, STRING *source_string, STRING
*search_string, UINTVAL offset);
typedef UINTVAL (*charset_validate_t)(Interp *, STRING *source_string);
Modified: trunk/include/parrot/hash.h
==============================================================================
--- trunk/include/parrot/hash.h (original)
+++ trunk/include/parrot/hash.h Fri May 25 18:53:05 2007
@@ -38,7 +38,7 @@
typedef UINTVAL BucketIndex;
#define INITBucketIndex ((BucketIndex)-2)
-typedef int (*hash_comp_fn)(Parrot_Interp, void*, void*);
+typedef int (*hash_comp_fn)(Parrot_Interp, const void*const, const
void*const);
typedef void (*hash_mark_key_fn)(Parrot_Interp, PObj *);
typedef size_t (*hash_hash_key_fn)(Parrot_Interp, void*, size_t seed);
Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h (original)
+++ trunk/include/parrot/string_funcs.h Fri May 25 18:53:05 2007
@@ -40,7 +40,7 @@
PARROT_API STRING *string_printf(Interp *interp,
const char *format, ...);
PARROT_API INTVAL string_compare(Interp *, STRING *, STRING *);
-PARROT_API INTVAL string_equal(Interp *, STRING *, STRING *);
+PARROT_API INTVAL string_equal(Interp *, const STRING *a, const STRING *b);
PARROT_API INTVAL string_bool(Interp *, const STRING *);
PARROT_API STRING *string_increment(Interp *, const STRING *);
PARROT_API const char *Parrot_string_cstring(Interp *, const STRING *);
Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c (original)
+++ trunk/src/hash.c Fri May 25 18:53:05 2007
@@ -53,7 +53,7 @@
static size_t
key_hash_STRING(Interp *interp, STRING *value, size_t seed)
{
- STRING *s = value;
+ STRING * const s = value;
if (s->hashval) {
return s->hashval;
@@ -74,9 +74,9 @@
*/
static int
-STRING_compare(Parrot_Interp interp, void *search_key, void *bucket_key)
+STRING_compare(Parrot_Interp interp, const void *search_key, const void
*bucket_key)
{
- return string_equal(interp, (STRING *)search_key, (STRING *)bucket_key);
+ return string_equal(interp, (const STRING *)search_key, (const STRING
*)bucket_key);
}
/*
@@ -91,7 +91,7 @@
*/
static int
-pointer_compare(Parrot_Interp interp, void *a, void *b) {
+pointer_compare(Parrot_Interp interp, const void * const a, const void * const
b) {
return a != b;
}
@@ -783,7 +783,7 @@
HashBucket *
parrot_hash_get_bucket(Interp *interp, Hash *hash, void *key)
{
- UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed);
+ const UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed);
HashBucket *bucket = hash->bi[hashval & hash->mask];
while (bucket) {
/* store hash_val or not */
@@ -808,7 +808,7 @@
void *
parrot_hash_get(Interp *interp, Hash *hash, void *key)
{
- HashBucket *bucket = parrot_hash_get_bucket(interp, hash, key);
+ const HashBucket * const bucket = parrot_hash_get_bucket(interp, hash,
key);
return bucket ? bucket->value : NULL;
}
@@ -826,7 +826,7 @@
INTVAL
parrot_hash_exists(Interp *interp, Hash *hash, void *key)
{
- HashBucket *bucket = parrot_hash_get_bucket(interp, hash, key);
+ const HashBucket * const bucket = parrot_hash_get_bucket(interp, hash,
key);
return bucket ? 1 : 0;
}
@@ -845,7 +845,7 @@
HashBucket*
parrot_hash_put(Interp *interp, Hash *hash, void *key, void *value)
{
- UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed);
+ const UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed);
HashBucket *bucket = hash->bi[hashval & hash->mask];
while (bucket) {
/* store hash_val or not */
@@ -895,11 +895,10 @@
void
parrot_hash_delete(Interp *interp, Hash *hash, void *key)
{
- UINTVAL hashval;
HashBucket *bucket;
HashBucket *prev = NULL;
- hashval = (hash->hash_val)(interp, key, hash->seed) & hash->mask;
+ const UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed) &
hash->mask;
for (bucket = hash->bi[hashval]; bucket; bucket = bucket->next) {
if ((hash->compare)(interp, key, bucket->key) == 0) {
@@ -940,7 +939,7 @@
for (i = 0; i <= hash->mask; i++) {
b = hash->bi[i];
while (b) {
- void *key = b->key;
+ void * const key = b->key;
void *valtmp;
switch (hash->entry_type) {
case enum_type_undef:
Modified: trunk/src/objects.c
==============================================================================
--- trunk/src/objects.c (original)
+++ trunk/src/objects.c Fri May 25 18:53:05 2007
@@ -40,10 +40,9 @@
INTVAL
Parrot_get_vtable_index(Interp *interp, STRING *name)
{
- char *name_c = string_to_cstring(interp, name);
+ const char * const name_c = string_to_cstring(interp, name);
INTVAL low = 0;
INTVAL high = NUM_VTABLE_FUNCTIONS - 1;
- INTVAL i;
/* some of the first "slots" don't have names. skip 'em. */
while (!Parrot_vtable_slot_names[low]) {
@@ -52,16 +51,13 @@
}
while (low <= high) {
- char *meth_c;
- int cmp;
-
- i = (low + high) / 2;
- meth_c = Parrot_vtable_slot_names[i];
+ const INTVAL i = (low + high) / 2;
+ const char * const meth_c = Parrot_vtable_slot_names[i];
/* XXX slot_names still have __ in front */
- cmp = strcmp(name_c, meth_c + 2);
+ const INTVAL cmp = strcmp(name_c, meth_c + 2);
- if (!cmp) {
+ if (cmp == 0) {
string_cstring_free(name_c);
return i;
}
@@ -90,21 +86,19 @@
static PMC*
find_vtable_meth_ns(Interp *interp, PMC *ns, INTVAL vtable_index)
{
- INTVAL k = VTABLE_elements(interp, ns);
- PMC *key = VTABLE_nextkey_keyed(interp, key_new(interp), ns,
+ const INTVAL k = VTABLE_elements(interp, ns);
+ PMC * const key = VTABLE_nextkey_keyed(interp, key_new(interp), ns,
ITERATE_FROM_START);
- const char *meth = Parrot_vtable_slot_names[vtable_index];
- STRING *meth_str = string_from_cstring(interp, meth, strlen(meth));
+ const char * const meth = Parrot_vtable_slot_names[vtable_index];
+ STRING * const meth_str = string_from_cstring(interp, meth,
strlen(meth));
- STRING *ns_key;
- PMC *res;
int j;
for (j = 0; j < k; ++j) {
- ns_key = (STRING *)parrot_hash_get_idx(interp,
+ STRING * const ns_key = (STRING *)parrot_hash_get_idx(interp,
(Hash *)PMC_struct_val(ns), key);
- res = VTABLE_get_pmc_keyed_str(interp, ns, ns_key);
+ PMC * const res = VTABLE_get_pmc_keyed_str(interp, ns, ns_key);
/* success if matching vtable index or double-underscored name */
if (res->vtable->base_type == enum_class_Sub &&
@@ -131,11 +125,11 @@
Parrot_find_vtable_meth(Interp *interp, PMC *pmc, STRING *meth)
{
INTVAL i, n;
- PMC *ns, *mro, *self_class, *res;
+ PMC *ns, *mro, *self_class;
PMC *_class = pmc;
/* Get index in Parrot_vtable_slot_names[]. */
- INTVAL vtable_index = Parrot_get_vtable_index(interp, meth);
+ const INTVAL vtable_index = Parrot_get_vtable_index(interp, meth);
if (vtable_index == -1)
return PMCNULL;
@@ -154,7 +148,7 @@
ns = VTABLE_pmc_namespace(interp, _class);
if (!PMC_IS_NULL(ns)) {
- res = find_vtable_meth_ns(interp, ns, vtable_index);
+ PMC * const res = find_vtable_meth_ns(interp, ns, vtable_index);
if (!PMC_IS_NULL(res))
return res;
Modified: trunk/src/string.c
==============================================================================
--- trunk/src/string.c (original)
+++ trunk/src/string.c Fri May 25 18:53:05 2007
@@ -1233,7 +1233,7 @@
*/
INTVAL
-string_equal(Interp *interp, STRING *s1, STRING *s2)
+string_equal(Interp *interp, const STRING *s1, const STRING *s2)
{
if ((s1 == s2) || (!s1 && !s2)) {
return 0;