Skip to content

Commit

Permalink
consting and PARROT_xxx annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Dec 9, 2010
1 parent 9d14f6b commit 86406d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
14 changes: 7 additions & 7 deletions include/parrot/list.h
Expand Up @@ -105,13 +105,15 @@ void Parrot_list_append(SHIM_INTERP,
FUNC_MODIFIES(*item);

PARROT_EXPORT
INTVAL Parrot_list_check(SHIM_INTERP, ARGIN(Linked_List *list))
PARROT_CONST_FUNCTION
INTVAL Parrot_list_check(SHIM_INTERP, ARGIN(const Linked_List *list))
__attribute__nonnull__(2);

PARROT_EXPORT
PARROT_PURE_FUNCTION
INTVAL Parrot_list_contains(SHIM_INTERP,
ARGIN(Linked_List *list),
ARGIN(List_Item_Header *item))
ARGIN(const Linked_List *list),
ARGIN(const List_Item_Header *item))
__attribute__nonnull__(2)
__attribute__nonnull__(3);

Expand All @@ -126,8 +128,7 @@ struct Linked_List* Parrot_list_new(SHIM_INTERP);

PARROT_EXPORT
PARROT_CAN_RETURN_NULL
List_Item_Header* Parrot_list_pop(PARROT_INTERP, ARGIN(Linked_List *list))
__attribute__nonnull__(1)
List_Item_Header* Parrot_list_pop(SHIM_INTERP, ARGIN(Linked_List *list))
__attribute__nonnull__(2);

PARROT_EXPORT
Expand All @@ -152,8 +153,7 @@ List_Item_Header* Parrot_list_remove(SHIM_INTERP,
PARROT_ASSERT_ARG(list))
#define ASSERT_ARGS_Parrot_list_new __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_list_pop __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(list))
PARROT_ASSERT_ARG(list))
#define ASSERT_ARGS_Parrot_list_remove __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(list) \
, PARROT_ASSERT_ARG(item))
Expand Down
26 changes: 14 additions & 12 deletions src/list.c
Expand Up @@ -43,7 +43,7 @@ Parrot_list_new(SHIM_INTERP)
{
ASSERT_ARGS(Parrot_list_new)

Linked_List *res = (Linked_List*)mem_sys_allocate_zeroed(sizeof (Linked_List));
Linked_List * const res = (Linked_List*)mem_sys_allocate_zeroed(sizeof (Linked_List));
return res;
}

Expand Down Expand Up @@ -119,8 +119,8 @@ Parrot_list_remove(SHIM_INTERP, ARGMOD(Linked_List *list), ARGMOD(List_Item_Head
{
ASSERT_ARGS(Parrot_list_remove)

List_Item_Header *next = item->next;
List_Item_Header *prev = item->prev;
List_Item_Header * const next = item->next;
List_Item_Header * const prev = item->prev;

PARROT_ASSERT(list == item->owner);

Expand Down Expand Up @@ -153,19 +153,19 @@ Pop an item off the list - i.e. get the first item in the list and remove it.
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
List_Item_Header*
Parrot_list_pop(PARROT_INTERP, ARGIN(Linked_List *list))
Parrot_list_pop(SHIM_INTERP, ARGIN(Linked_List *list))
{
ASSERT_ARGS(Parrot_list_pop)

List_Item_Header *ret = list->first;
List_Item_Header * const ret = list->first;
if (ret)
LIST_REMOVE(list, ret);
return ret;
}

/*
=item C<INTVAL Parrot_list_check(PARROT_INTERP, Linked_List *list)>
=item C<INTVAL Parrot_list_check(PARROT_INTERP, const Linked_List *list)>
Check the validity of the list
Expand All @@ -174,12 +174,13 @@ Check the validity of the list
*/

PARROT_EXPORT
PARROT_CONST_FUNCTION
INTVAL
Parrot_list_check(SHIM_INTERP, ARGIN(Linked_List *list))
Parrot_list_check(SHIM_INTERP, ARGIN(const Linked_List *list))
{
ASSERT_ARGS(Parrot_list_check)

List_Item_Header *tmp = list->first;
const List_Item_Header *tmp = list->first;
size_t counter = 0;

while (tmp) {
Expand All @@ -195,8 +196,8 @@ Parrot_list_check(SHIM_INTERP, ARGIN(Linked_List *list))

/*
=item C<INTVAL Parrot_list_contains(PARROT_INTERP, Linked_List *list,
List_Item_Header *item)>
=item C<INTVAL Parrot_list_contains(PARROT_INTERP, const Linked_List *list,
const List_Item_Header *item)>
Returns True if the is in the list
Expand All @@ -205,12 +206,13 @@ Returns True if the is in the list
*/

PARROT_EXPORT
PARROT_PURE_FUNCTION
INTVAL
Parrot_list_contains(SHIM_INTERP, ARGIN(Linked_List *list), ARGIN(List_Item_Header *item))
Parrot_list_contains(SHIM_INTERP, ARGIN(const Linked_List *list), ARGIN(const List_Item_Header *item))
{
ASSERT_ARGS(Parrot_list_contains)

List_Item_Header *tmp = list->first;
const List_Item_Header *tmp = list->first;

#ifndef NDEBUG
if (item->owner != list)
Expand Down

0 comments on commit 86406d0

Please sign in to comment.