Skip to content

Commit

Permalink
Fix: namespace with the same name as a builtin function causes crash
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed Feb 7, 2017
1 parent 5aabfb9 commit e824eec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/parse/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,17 @@ void read_namespace_name( struct parse* parse ) {
struct ns_path* path = parse->ns_fragment->path;
while ( path ) {
struct name* name = t_extend_name( ns->body, path->text );
if ( name->object ) {
// NOTE: We assume that the object is a namespace, since all the
// other objects read will be bound during the semantic phase.
ns = ( struct ns* ) name->object;
}
else {
if ( ! ( name->object &&
name->object->node.type == NODE_NAMESPACE ) ) {
struct ns* nested_ns = t_alloc_ns( name );
nested_ns->object.pos = path->pos;
nested_ns->parent = ns;
list_append( &parse->task->namespaces, nested_ns );
nested_ns->object.next_scope = name->object;
name->object = &nested_ns->object;
ns = nested_ns;
}
// At this point, the name should be referring to a namespace object.
ns = ( struct ns* ) name->object;
path = path->next;
}
parse->ns = ns;
Expand Down Expand Up @@ -1034,7 +1032,7 @@ void unbind_namespaces( struct parse* parse ) {
list_iter_init( &i, &parse->task->namespaces );
while ( ! list_end( &i ) ) {
struct ns* ns = list_data( &i );
ns->name->object = NULL;
ns->name->object = ns->name->object->next_scope;
list_next( &i );
}
}
1 change: 1 addition & 0 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void t_init( struct task* task, struct options* options, jmp_buf* bail,
list_init( &task->runtime_asserts );
task->root_name = t_create_name();
task->upmost_ns = t_alloc_ns( task->root_name );
task->upmost_ns->name->object = &task->upmost_ns->object;
list_append( &task->namespaces, task->upmost_ns );

task->array_name = t_create_name();
Expand Down

0 comments on commit e824eec

Please sign in to comment.