2004-12-13 21:51:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2004-12-14 01:36:48 +00:00
|
|
|
#include <pobj/pobj.h>
|
2004-12-13 21:51:11 +00:00
|
|
|
|
|
|
|
|
2004-12-16 23:04:21 +00:00
|
|
|
struct data {
|
|
|
|
int val;
|
|
|
|
};
|
|
|
|
|
2004-12-13 21:51:11 +00:00
|
|
|
struct item {
|
|
|
|
int val;
|
2004-12-16 23:04:21 +00:00
|
|
|
struct data *data;
|
2004-12-13 21:51:11 +00:00
|
|
|
struct item *next;
|
|
|
|
int dummy[45];
|
|
|
|
};
|
|
|
|
int item_ref_fields[] = {
|
2004-12-16 23:04:21 +00:00
|
|
|
member_offset(struct item, data),
|
2004-12-13 21:51:11 +00:00
|
|
|
member_offset(struct item, next),
|
|
|
|
-1
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
static struct item *list = NULL;
|
2004-12-16 23:04:21 +00:00
|
|
|
struct data *data;
|
2004-12-13 21:51:11 +00:00
|
|
|
struct item *tmp, *next;
|
|
|
|
int i;
|
|
|
|
|
2004-12-14 20:28:18 +00:00
|
|
|
switch (pobj_init (NULL, NULL)) {
|
2004-12-13 21:51:11 +00:00
|
|
|
case 0:
|
|
|
|
printf ("first-time init\n");
|
|
|
|
/* Build list. */
|
|
|
|
next = NULL;
|
2004-12-16 23:12:23 +00:00
|
|
|
for (i = 0; i < 15; i++) {
|
2004-12-13 21:51:11 +00:00
|
|
|
pobj_start ();
|
2004-12-16 23:04:21 +00:00
|
|
|
|
2004-12-13 21:51:11 +00:00
|
|
|
tmp = (struct item *) pobj_malloc (sizeof (struct item));
|
2004-12-16 23:04:21 +00:00
|
|
|
data = (struct data *) pobj_malloc_transient (sizeof (struct data));
|
|
|
|
if (! (tmp && data)) {
|
2004-12-13 21:51:11 +00:00
|
|
|
printf ("allocation error\n");
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
|
2004-12-16 23:04:21 +00:00
|
|
|
pobj_ref_typify (tmp, item_ref_fields);
|
2004-12-13 21:51:11 +00:00
|
|
|
|
2004-12-16 23:04:21 +00:00
|
|
|
pobj_static_set_ref (&list, tmp);
|
|
|
|
|
|
|
|
data->val = -i;
|
|
|
|
|
2004-12-13 21:51:11 +00:00
|
|
|
tmp->val = i;
|
2004-12-16 23:04:21 +00:00
|
|
|
tmp->data = data;
|
2004-12-13 21:51:11 +00:00
|
|
|
tmp->next = next;
|
2004-12-16 23:04:21 +00:00
|
|
|
|
|
|
|
#if 0
|
2004-12-13 21:51:11 +00:00
|
|
|
POBJ_SET_INT (tmp, val, i);
|
2004-12-16 23:04:21 +00:00
|
|
|
|
2004-12-13 21:51:11 +00:00
|
|
|
/* Intended crash code... */
|
|
|
|
if (i == 7)
|
|
|
|
abort ();
|
2004-12-16 23:04:21 +00:00
|
|
|
|
2004-12-13 21:51:11 +00:00
|
|
|
POBJ_SET_REF (tmp, next, next);
|
2004-12-16 23:04:21 +00:00
|
|
|
#endif
|
|
|
|
|
2004-12-16 23:12:23 +00:00
|
|
|
POBJ_UPDATE (data);
|
2004-12-16 23:04:21 +00:00
|
|
|
POBJ_UPDATE (tmp);
|
|
|
|
|
2004-12-13 21:51:11 +00:00
|
|
|
pobj_end ();
|
|
|
|
|
|
|
|
next = tmp;
|
|
|
|
}
|
|
|
|
/* pobj_update_recursive (tmp); */
|
|
|
|
/* pobj_static_set_ref (&list, tmp); */
|
|
|
|
/* list = tmp; */
|
|
|
|
/* pobj_static_update_ref (&list); */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
printf ("subsequent init\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
printf ("init error\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf ("unknown return value\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print list. */
|
|
|
|
printf ("printing list...\n");
|
|
|
|
for (tmp = list; tmp; tmp = tmp->next)
|
2004-12-16 23:04:21 +00:00
|
|
|
printf ("%p: val=%d next=%p data=%p data->val=%d\n",
|
|
|
|
(void *) tmp, tmp->val, (void *) tmp->next,
|
|
|
|
(void *) tmp->data, (tmp->data ? tmp->data->val : 0));
|
2004-12-13 21:51:11 +00:00
|
|
|
printf ("...done\n");
|
|
|
|
|
|
|
|
pobj_shutdown ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|