From b358e8a3e1ae2fae2560c6338cff77b7e33a4553 Mon Sep 17 00:00:00 2001 From: Sander Mertens Date: Sun, 22 Nov 2015 15:33:07 -0500 Subject: [PATCH] #342 fixed crash when redeclaring with different type Also fixed issue with using underscore in a select query --- packages/corto/lang/src/corto_object.c | 6 +- packages/corto/lang/src/corto_select.c | 4 +- .../corto/lang/test/src/test_ObjectMgmt.c | 67 +++++++++++++------ packages/corto/lang/test/test.cx | 1 + 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/packages/corto/lang/src/corto_object.c b/packages/corto/lang/src/corto_object.c index f96952b5..29dbf109 100644 --- a/packages/corto/lang/src/corto_object.c +++ b/packages/corto/lang/src/corto_object.c @@ -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); @@ -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; } @@ -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"); } diff --git a/packages/corto/lang/src/corto_select.c b/packages/corto/lang/src/corto_select.c index 5a6e826f..f3ca42f4 100644 --- a/packages/corto/lang/src/corto_select.c +++ b/packages/corto/lang/src/corto_select.c @@ -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; } diff --git a/packages/corto/lang/test/src/test_ObjectMgmt.c b/packages/corto/lang/test/src/test_ObjectMgmt.c index 44f7a736..2744425c 100644 --- a/packages/corto/lang/test/src/test_ObjectMgmt.c +++ b/packages/corto/lang/test/src/test_ObjectMgmt.c @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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 */ } @@ -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 */ } @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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); diff --git a/packages/corto/lang/test/test.cx b/packages/corto/lang/test/test.cx index ab8fa7ab..7bce9247 100644 --- a/packages/corto/lang/test/test.cx +++ b/packages/corto/lang/test/test.cx @@ -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()