Skip to content

Commit

Permalink
#342 fixed crash when redeclaring with different type
Browse files Browse the repository at this point in the history
Also fixed issue with using underscore in a select query
  • Loading branch information
SanderMertens committed Nov 22, 2015
1 parent 323b169 commit b358e8a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 24 deletions.
6 changes: 5 additions & 1 deletion packages/corto/lang/src/corto_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ static corto_object corto__initScope(corto_object o, corto_string name, corto_ob

scope->name = corto_strdup(name);
scope->declared = 1;

/* Set parent, so that initializer can refer to it */
scope->parent = parent;
corto_rwmutexNew(&scope->scopeLock);

Expand All @@ -274,6 +276,8 @@ static corto_object corto__initScope(corto_object o, corto_string name, corto_ob

/* Add object to the scope of the parent-object */
if (!(result = corto_adopt(parent, o))) {
/* Reset parent */
scope->parent = NULL;
goto error;
}

Expand Down Expand Up @@ -725,7 +729,7 @@ static corto_object corto_adopt(corto_object parent, corto_object child) {
/* Parent must not be deleted before all childs are gone. */
corto_claim(parent);
if (corto_rwmutexUnlock(&p_scope->scopeLock))
corto_critical("corto_adopt: unlock operation on scopeLock of parent failed");;
corto_critical("corto_adopt: unlock operation on scopeLock of parent failed");
} else {
corto_critical("corto_adopt: child-object is not scoped");
}
Expand Down
4 changes: 2 additions & 2 deletions packages/corto/lang/src/corto_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ static int corto_selectParse(corto_selectData *data) {
break;
default:
while((ch = *ptr++) &&
(isalnum(ch) || (ch == '*') || (ch == '?') || (ch == '(') ||
(ch == ')') || (ch == '{') || (ch == '}'))) {
(isalnum(ch) || (ch == '_') || (ch == '*') || (ch == '?') ||
(ch == '(') || (ch == ')') || (ch == '{') || (ch == '}'))) {
if ((ch == '*') || (ch == '?')) {
data->program[op].containsWildcard = TRUE;
}
Expand Down
67 changes: 46 additions & 21 deletions packages/corto/lang/test/src/test_ObjectMgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ corto_void _test_ObjectMgmt_tc_createChildFoo(test_ObjectMgmt this) {
test_Foo o = corto_createChild(NULL, "o", test_Foo_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == (corto_type)test_Foo_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand Down Expand Up @@ -60,7 +60,7 @@ corto_void _test_ObjectMgmt_tc_createChildFooAttr0(test_ObjectMgmt this) {
test_Foo o = corto_createChild(NULL, "o", test_Foo_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == (corto_type)test_Foo_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand Down Expand Up @@ -106,7 +106,7 @@ corto_void _test_ObjectMgmt_tc_createChildInt(test_ObjectMgmt this) {
corto_object o = corto_createChild(NULL, "o", corto_int32_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == (corto_type)corto_int32_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand Down Expand Up @@ -135,7 +135,7 @@ corto_void _test_ObjectMgmt_tc_createChildIntAttr0(test_ObjectMgmt this) {
corto_object o = corto_createChild(NULL, "o", corto_int32_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == (corto_type)corto_int32_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand Down Expand Up @@ -187,7 +187,7 @@ corto_void _test_ObjectMgmt_tc_createChildNested(test_ObjectMgmt this) {
test_Foo o = corto_createChild(NULL, "o", test_Foo_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == (corto_type)test_Foo_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand All @@ -200,7 +200,7 @@ corto_void _test_ObjectMgmt_tc_createChildNested(test_ObjectMgmt this) {
test_Foo p = corto_createChild(o, "p", test_Foo_o);
test_assert(p != NULL);
test_assert(!strcmp(corto_nameof(p), "p"));
test_assert(corto_parentof(p) == o);
test_assert(corto_parentof(p) == o);
test_assert(corto_typeof(p) == (corto_type)test_Foo_o);
test_assert(corto_checkState(p, CORTO_VALID));
test_assert(corto_checkState(p, CORTO_DECLARED));
Expand All @@ -213,7 +213,7 @@ corto_void _test_ObjectMgmt_tc_createChildNested(test_ObjectMgmt this) {
test_Foo q = corto_createChild(p, "q", test_Foo_o);
test_assert(p != NULL);
test_assert(!strcmp(corto_nameof(q), "q"));
test_assert(corto_parentof(q) == p);
test_assert(corto_parentof(q) == p);
test_assert(corto_typeof(q) == (corto_type)test_Foo_o);
test_assert(corto_checkState(q, CORTO_VALID));
test_assert(corto_checkState(q, CORTO_DECLARED));
Expand Down Expand Up @@ -298,7 +298,7 @@ corto_void _test_ObjectMgmt_tc_createChildVoid(test_ObjectMgmt this) {
corto_object o = corto_declareChild(NULL, "o", corto_void_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == corto_void_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand Down Expand Up @@ -327,7 +327,7 @@ corto_void _test_ObjectMgmt_tc_createChildVoidAttr0(test_ObjectMgmt this) {
corto_object o = corto_createChild(NULL, "o", corto_void_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == corto_void_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand Down Expand Up @@ -528,7 +528,7 @@ corto_void _test_ObjectMgmt_tc_declareChildFoo(test_ObjectMgmt this) {
test_Foo o = corto_declareChild(NULL, "o", test_Foo_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == (corto_type)test_Foo_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand Down Expand Up @@ -565,7 +565,7 @@ corto_void _test_ObjectMgmt_tc_declareChildFooAttr0(test_ObjectMgmt this) {
test_Foo o = corto_declareChild(NULL, "o", test_Foo_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == (corto_type)test_Foo_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand Down Expand Up @@ -611,7 +611,7 @@ corto_void _test_ObjectMgmt_tc_declareChildInt(test_ObjectMgmt this) {
corto_object o = corto_declareChild(NULL, "o", corto_int32_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == (corto_type)corto_int32_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand Down Expand Up @@ -644,7 +644,7 @@ corto_void _test_ObjectMgmt_tc_declareChildIntAttr0(test_ObjectMgmt this) {
corto_object o = corto_declareChild(NULL, "o", corto_int32_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == (corto_type)corto_int32_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand Down Expand Up @@ -745,7 +745,7 @@ corto_void _test_ObjectMgmt_tc_declareChildVoid(test_ObjectMgmt this) {
corto_object o = corto_declareChild(NULL, "o", corto_void_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == corto_void_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand Down Expand Up @@ -774,7 +774,7 @@ corto_void _test_ObjectMgmt_tc_declareChildVoidAttr0(test_ObjectMgmt this) {
corto_object o = corto_declareChild(NULL, "o", corto_void_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == corto_void_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand Down Expand Up @@ -903,7 +903,7 @@ corto_void _test_ObjectMgmt_tc_declareInt(test_ObjectMgmt this) {
test_assert(corto_checkAttr(o, CORTO_ATTR_OBSERVABLE));
test_assert(!corto_checkAttr(o, CORTO_ATTR_PERSISTENT));
corto_delete(o);

/* $end */
}

Expand Down Expand Up @@ -973,7 +973,7 @@ corto_void _test_ObjectMgmt_tc_declareVoid(test_ObjectMgmt this) {
test_assert(corto_checkAttr(o, CORTO_ATTR_OBSERVABLE));
test_assert(!corto_checkAttr(o, CORTO_ATTR_PERSISTENT));
corto_delete(o);

/* $end */
}

Expand Down Expand Up @@ -1184,7 +1184,7 @@ corto_void _test_ObjectMgmt_tc_defineVoidAttr0(test_ObjectMgmt this) {
corto_setAttr(0);
corto_object o = corto_declare(corto_void_o);
corto_define(o);

test_assert(o != NULL);
test_assert(corto_typeof(o) == (corto_type)corto_void_o);
test_assert(corto_checkState(o, CORTO_VALID));
Expand All @@ -1205,7 +1205,7 @@ corto_void _test_ObjectMgmt_tc_drop(test_ObjectMgmt this) {
test_Foo o = corto_createChild(NULL, "o", test_Foo_o);
test_assert(o != NULL);
test_assert(!strcmp(corto_nameof(o), "o"));
test_assert(corto_parentof(o) == root_o);
test_assert(corto_parentof(o) == root_o);
test_assert(corto_typeof(o) == (corto_type)test_Foo_o);
test_assert(corto_checkState(o, CORTO_VALID));
test_assert(corto_checkState(o, CORTO_DECLARED));
Expand All @@ -1218,7 +1218,7 @@ corto_void _test_ObjectMgmt_tc_drop(test_ObjectMgmt this) {
test_Foo p = corto_createChild(o, "p", test_Foo_o);
test_assert(p != NULL);
test_assert(!strcmp(corto_nameof(p), "p"));
test_assert(corto_parentof(p) == o);
test_assert(corto_parentof(p) == o);
test_assert(corto_typeof(p) == (corto_type)test_Foo_o);
test_assert(corto_checkState(p, CORTO_VALID));
test_assert(corto_checkState(p, CORTO_DECLARED));
Expand All @@ -1231,7 +1231,7 @@ corto_void _test_ObjectMgmt_tc_drop(test_ObjectMgmt this) {
test_Foo q = corto_createChild(o, "q", test_Foo_o);
test_assert(p != NULL);
test_assert(!strcmp(corto_nameof(q), "q"));
test_assert(corto_parentof(q) == o);
test_assert(corto_parentof(q) == o);
test_assert(corto_typeof(q) == (corto_type)test_Foo_o);
test_assert(corto_checkState(q, CORTO_VALID));
test_assert(corto_checkState(q, CORTO_DECLARED));
Expand Down Expand Up @@ -1291,6 +1291,31 @@ corto_void _test_ObjectMgmt_tc_invalidate(test_ObjectMgmt this) {
/* $end */
}

corto_void _test_ObjectMgmt_tc_redeclareWithDifferentType(test_ObjectMgmt this) {
/* $begin(test/ObjectMgmt/tc_redeclareWithDifferentType) */

corto_float32DeclareChild(NULL, "a");
corto_float32DeclareChild(NULL, "b");
corto_float32DeclareChild(NULL, "c");

corto_object a = corto_float64DeclareChild(NULL, "a");
test_assert(a == NULL);
test_assert(corto_lasterr() != NULL);
test_assert(!strcmp(corto_lasterr(), "'a' is already declared with a different type"));

corto_object b = corto_float64DeclareChild(NULL, "b");
test_assert(b == NULL);
test_assert(corto_lasterr() != NULL);
test_assert(!strcmp(corto_lasterr(), "'b' is already declared with a different type"));

corto_object c = corto_float64DeclareChild(NULL, "c");
test_assert(c == NULL);
test_assert(corto_lasterr() != NULL);
test_assert(!strcmp(corto_lasterr(), "'c' is already declared with a different type"));

/* $end */
}

corto_void _test_ObjectMgmt_teardown(test_ObjectMgmt this) {
/* $begin(test/ObjectMgmt/teardown) */
corto_setAttr(this->prevAttr);
Expand Down
1 change: 1 addition & 0 deletions packages/corto/lang/test/test.cx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ test::Suite ObjectMgmt::
void tc_declareExistingWithParentState()
void tc_declareChildNullType()
void tc_declareChildInvalidType()
void tc_redeclareWithDifferentType()

void tc_createChildVoid()
void tc_createChildInt()
Expand Down

0 comments on commit b358e8a

Please sign in to comment.