mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
Check pointer types
Sat Apr 23 18:38:46 2005 Søren Sandmann <sandmann@redhat.com> * sfile.c (post_process_read_instructions): Check pointer types * sfile.c (post_process_instructions_recurse): Delete this unused function
This commit is contained in:
committed by
Søren Sandmann Pedersen
parent
753eb9378b
commit
8424be6024
@ -1,3 +1,9 @@
|
|||||||
|
Sat Apr 23 18:38:46 2005 Søren Sandmann <sandmann@redhat.com>
|
||||||
|
|
||||||
|
* sfile.c (post_process_read_instructions): Check pointer types
|
||||||
|
|
||||||
|
* sfile.c (post_process_instructions_recurse): Delete this unused function
|
||||||
|
|
||||||
Sat Apr 23 17:49:33 2005 Søren Sandmann <sandmann@redhat.com>
|
Sat Apr 23 17:49:33 2005 Søren Sandmann <sandmann@redhat.com>
|
||||||
|
|
||||||
* sysprof-module.c (page_readable): New function to check if the
|
* sysprof-module.c (page_readable): New function to check if the
|
||||||
|
|||||||
90
sfile.c
90
sfile.c
@ -44,6 +44,7 @@ enum
|
|||||||
TYPE_INTEGER,
|
TYPE_INTEGER,
|
||||||
TYPE_GENERIC_RECORD,
|
TYPE_GENERIC_RECORD,
|
||||||
TYPE_GENERIC_LIST,
|
TYPE_GENERIC_LIST,
|
||||||
|
TYPE_VOID,
|
||||||
N_BUILTIN_TYPES,
|
N_BUILTIN_TYPES,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -60,11 +61,13 @@ struct Transition
|
|||||||
TransitionKind kind;
|
TransitionKind kind;
|
||||||
State *to;
|
State *to;
|
||||||
char *element; /* for begin/end transitions */
|
char *element; /* for begin/end transitions */
|
||||||
|
SType target_type; /* for pointer transitions */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct State
|
struct State
|
||||||
{
|
{
|
||||||
GQueue *transitions;
|
GQueue *transitions;
|
||||||
|
guint marked : 1; /* Used by sformat_free */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Fragment
|
struct Fragment
|
||||||
@ -148,6 +151,7 @@ transition_new (const char *element,
|
|||||||
t->kind = kind;
|
t->kind = kind;
|
||||||
t->type = type;
|
t->type = type;
|
||||||
t->to = to;
|
t->to = to;
|
||||||
|
t->target_type = TYPE_UNDEFINED;
|
||||||
|
|
||||||
if (from)
|
if (from)
|
||||||
g_queue_push_tail (from->transitions, t);
|
g_queue_push_tail (from->transitions, t);
|
||||||
@ -403,7 +407,12 @@ sformat_new_pointer (const char *name,
|
|||||||
SType *target_type)
|
SType *target_type)
|
||||||
{
|
{
|
||||||
Fragment *fragment = sformat_new_value (name, TYPE_POINTER);
|
Fragment *fragment = sformat_new_value (name, TYPE_POINTER);
|
||||||
/* FIXME: store the target type in the fragment */
|
Transition *value;
|
||||||
|
|
||||||
|
/* store the target type in the value transition */
|
||||||
|
value = fragment->enter->to->transitions->head->data;
|
||||||
|
value->target_type = define_type (target_type, TYPE_VOID);
|
||||||
|
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,7 +476,7 @@ state_transition_end (const State *state, const char *element, SType *type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const State *
|
static const State *
|
||||||
state_transition_text (const State *state, SType *type)
|
state_transition_text (const State *state, SType *type, SType *target_type)
|
||||||
{
|
{
|
||||||
GList *list;
|
GList *list;
|
||||||
|
|
||||||
@ -479,6 +488,9 @@ state_transition_text (const State *state, SType *type)
|
|||||||
{
|
{
|
||||||
*type = transition->type;
|
*type = transition->type;
|
||||||
|
|
||||||
|
if (*type == TYPE_POINTER && target_type)
|
||||||
|
*target_type = transition->target_type;
|
||||||
|
|
||||||
/* There will never be more than one allowed value transition for
|
/* There will never be more than one allowed value transition for
|
||||||
* a given state
|
* a given state
|
||||||
*/
|
*/
|
||||||
@ -520,6 +532,7 @@ struct Instruction
|
|||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
SType target_type;
|
||||||
int target_id;
|
int target_id;
|
||||||
Instruction *target_instruction;
|
Instruction *target_instruction;
|
||||||
gpointer target_object;
|
gpointer target_object;
|
||||||
@ -692,8 +705,6 @@ hook_up_pointers (SFileInput *file)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* FIXME: we need to check the types here */
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
g_print ("emfle\n");
|
g_print ("emfle\n");
|
||||||
#endif
|
#endif
|
||||||
@ -852,13 +863,14 @@ handle_text (GMarkupParseContext *context,
|
|||||||
BuildContext *build = user_data;
|
BuildContext *build = user_data;
|
||||||
Instruction instruction;
|
Instruction instruction;
|
||||||
char *free_me;
|
char *free_me;
|
||||||
|
SType target_type;
|
||||||
|
|
||||||
text = free_me = g_strstrip (g_strdup (text));
|
text = free_me = g_strstrip (g_strdup (text));
|
||||||
|
|
||||||
if (strlen (text) == 0)
|
if (strlen (text) == 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
build->state = state_transition_text (build->state, &instruction.type);
|
build->state = state_transition_text (build->state, &instruction.type, &target_type);
|
||||||
if (!build->state)
|
if (!build->state)
|
||||||
{
|
{
|
||||||
int line, ch;
|
int line, ch;
|
||||||
@ -876,6 +888,7 @@ handle_text (GMarkupParseContext *context,
|
|||||||
switch (instruction.type)
|
switch (instruction.type)
|
||||||
{
|
{
|
||||||
case TYPE_POINTER:
|
case TYPE_POINTER:
|
||||||
|
instruction.u.pointer.target_type = target_type;
|
||||||
if (!get_number (text, &instruction.u.pointer.target_id))
|
if (!get_number (text, &instruction.u.pointer.target_id))
|
||||||
{
|
{
|
||||||
set_invalid_content_error (err, "Contents '%s' of pointer element is not a number", text);
|
set_invalid_content_error (err, "Contents '%s' of pointer element is not a number", text);
|
||||||
@ -929,45 +942,6 @@ free_instructions (Instruction *instructions, int n_instructions)
|
|||||||
g_free (instructions);
|
g_free (instructions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This functions counts the number of instructions in each list, and
|
|
||||||
* matches up pointers with the lists/records they point to.
|
|
||||||
* FIMXE: think of a better name
|
|
||||||
*/
|
|
||||||
static Instruction *
|
|
||||||
post_process_instructions_recurse (Instruction *first, GHashTable *instructions_by_id, GError **err)
|
|
||||||
{
|
|
||||||
Instruction *instruction;
|
|
||||||
int n_elements;
|
|
||||||
|
|
||||||
g_assert (first->kind == BEGIN);
|
|
||||||
|
|
||||||
instruction = first + 1;
|
|
||||||
|
|
||||||
n_elements = 0;
|
|
||||||
while (instruction->kind != END)
|
|
||||||
{
|
|
||||||
if (instruction->kind == BEGIN)
|
|
||||||
{
|
|
||||||
instruction = post_process_instructions_recurse (instruction, instructions_by_id, err);
|
|
||||||
if (!instruction)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
instruction++;
|
|
||||||
}
|
|
||||||
|
|
||||||
n_elements++;
|
|
||||||
}
|
|
||||||
|
|
||||||
first->u.begin.n_elements = n_elements;
|
|
||||||
first->u.begin.end_instruction = instruction;
|
|
||||||
|
|
||||||
instruction->u.end.begin_instruction = first;
|
|
||||||
|
|
||||||
return instruction + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This functions makes end instructions point to the corresponding
|
/* This functions makes end instructions point to the corresponding
|
||||||
* begin instructions, and counts the number of instructions
|
* begin instructions, and counts the number of instructions
|
||||||
* contained in a begin/end pair
|
* contained in a begin/end pair
|
||||||
@ -979,7 +953,7 @@ process_instruction_pairs (Instruction *first)
|
|||||||
int n_elements;
|
int n_elements;
|
||||||
|
|
||||||
g_assert (first->kind == BEGIN);
|
g_assert (first->kind == BEGIN);
|
||||||
|
|
||||||
instruction = first + 1;
|
instruction = first + 1;
|
||||||
|
|
||||||
n_elements = 0;
|
n_elements = 0;
|
||||||
@ -995,7 +969,7 @@ process_instruction_pairs (Instruction *first)
|
|||||||
{
|
{
|
||||||
instruction++;
|
instruction++;
|
||||||
}
|
}
|
||||||
|
|
||||||
n_elements++;
|
n_elements++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1003,10 +977,10 @@ process_instruction_pairs (Instruction *first)
|
|||||||
first->u.begin.end_instruction = instruction;
|
first->u.begin.end_instruction = instruction;
|
||||||
|
|
||||||
instruction->u.end.begin_instruction = first;
|
instruction->u.end.begin_instruction = first;
|
||||||
|
|
||||||
return instruction + 1;
|
return instruction + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
post_process_read_instructions (Instruction *instructions, int n_instructions, GError **err)
|
post_process_read_instructions (Instruction *instructions, int n_instructions, GError **err)
|
||||||
{
|
{
|
||||||
@ -1049,11 +1023,21 @@ post_process_read_instructions (Instruction *instructions, int n_instructions, G
|
|||||||
|
|
||||||
if (target)
|
if (target)
|
||||||
{
|
{
|
||||||
instruction->u.pointer.target_instruction = target;
|
if (instruction->u.pointer.target_type == target->type)
|
||||||
|
{
|
||||||
|
instruction->u.pointer.target_instruction = target;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
set_invalid_content_error (err, "Id %d references an element of the wrong type",
|
||||||
|
instruction->u.pointer.target_id);
|
||||||
|
retval = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
set_invalid_content_error (err, "Id %d doesn't reference any record or list\n",
|
set_invalid_content_error (err, "Id %d doesn't reference any record or list",
|
||||||
instruction->u.pointer.target_id);
|
instruction->u.pointer.target_id);
|
||||||
retval = FALSE;
|
retval = FALSE;
|
||||||
break;
|
break;
|
||||||
@ -1243,7 +1227,7 @@ sfile_check_value (SFileOutput *file,
|
|||||||
file->state = state_transition_begin (file->state, name, &tmp_type);
|
file->state = state_transition_begin (file->state, name, &tmp_type);
|
||||||
g_return_if_fail (file->state && tmp_type == type);
|
g_return_if_fail (file->state && tmp_type == type);
|
||||||
|
|
||||||
file->state = state_transition_text (file->state, &type);
|
file->state = state_transition_text (file->state, &type, NULL);
|
||||||
g_return_if_fail (file->state && tmp_type == type);
|
g_return_if_fail (file->state && tmp_type == type);
|
||||||
|
|
||||||
file->state = state_transition_end (file->state, name, &type);
|
file->state = state_transition_end (file->state, name, &type);
|
||||||
@ -1552,10 +1536,6 @@ sfile_output_save (SFileOutput *sfile,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
g_print (output->str);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* FIMXE: bz2 compressing the output is probably
|
/* FIMXE: bz2 compressing the output is probably
|
||||||
* interesting at some point. For now just make sure
|
* interesting at some point. For now just make sure
|
||||||
* it works without actually using it.
|
* it works without actually using it.
|
||||||
|
|||||||
5
sfile.h
5
sfile.h
@ -42,7 +42,10 @@ typedef guint SType;
|
|||||||
* For formats consider:
|
* For formats consider:
|
||||||
*
|
*
|
||||||
* Format *format_new (void);
|
* Format *format_new (void);
|
||||||
* void format_new_record (Format *f, Record *r);
|
* void format_set_record (Format *f, Content *r);
|
||||||
|
* Content *new_record (Content *c1, ...);
|
||||||
|
*
|
||||||
|
* List *format_new_list (Format *f
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Consider adding optional elements:
|
* Consider adding optional elements:
|
||||||
|
|||||||
Reference in New Issue
Block a user