Skip to content

Commit

Permalink
fix final ctk_object cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Dec 5, 2023
1 parent 20349de commit 5d921fc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
16 changes: 9 additions & 7 deletions VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ ChucK VERSIONS log

1.5.2.0 (November 2023) "Better Late Than Never...constructors"
=======
- (added) language-level, overloadable class constructors
- (added) language-level class destructor
- (added) class constructors
- (added) overloadable class constructors definitions
============
constructors can be invoked when declaring or with `new`:
constructors can be invoked when declaring a variable or with `new`:
```
// connecting UGens, with construtors
SinOsc foo(440) => Gain g(.5) => dac;
Expand Down Expand Up @@ -54,7 +54,6 @@ new Foo(10,11,12) @=> Foo @ f4;
- (added) examples/class/constructors.ck
- (added) examples/class/destructor.ck
- (added) CKDoc and .help() support for constructors
- (added) Shred.parent() and Shred.ancestor()
- (added) overloaded functions can now have different return types;
for example:
```
Expand All @@ -71,6 +70,7 @@ for example:
- (fixed) disambiguating overloaded functions to choose the "closest" match
by function call argument type inheritance "distance" to function
argument type
- (added) Shred.parent() and Shred.ancestor()
- (added) compiler error for ambiguous function calls when there is no
"closest" match
- (fixed) array popFront() crash on Object-based arrays
Expand All @@ -85,6 +85,8 @@ for example:
Construct a SndBuf with the 'path' to a sound file to read, and a default playback 'rate' (1.0 is normal rate)
SndBuf( string path, float rate, int pos );
Construct a SndBuf with the 'path' to a sound file to read, a default playback 'rate' (1.0 is normal rate), and starting at sample position 'pos'
Step( float value );
Construct a Step with a default value.
string( string str );
Construct a string as a copy of another string.
Osc( float freq );
Expand All @@ -95,15 +97,13 @@ for example:
==================
chugins API update
==================
- (updated) chugin API version updated to 10.x
- (updated) chugin API version updated to 10.1
-- complete decoupling of chugins interface and chuck core
implementation details
-- new chugins runtime API functions to provide access
to chuck core operations that is safe across the shared/dynamic
library boudaries between chugins and a chuck host
(see Chuck_DL_Api in chuck_dl.h for details)
- (updated) chugin AND host API version must now match
(previously only the major version must match)
- (updated) all chugins can now include a single header `chugin.h`
with no additional header dependencies
[see: https://github.com/ccrma/cheaders/tree/main/include]
Expand All @@ -115,6 +115,8 @@ chugins API update
directly (either chuck_dl.h or chuck.h), but must #define
__CHUCK_CHUGIN__ macro (if using chugin.h, this macro is always
defined at the top of file)
- (updated) chugin AND host API version must now match
(previously only the major version must match)
- (added) chugins runtime API support for creating arrays from chugins
- (added) chugins support for overloading constructors

Expand Down
11 changes: 5 additions & 6 deletions src/core/chuck_oo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,22 +331,21 @@ Chuck_Object::~Chuck_Object()
}

// release class-scope member vars | 1.5.2.0 (ge) added
Chuck_Type * t = type_ref;
Chuck_Object * obj = NULL;
type = this->type_ref; Chuck_Object * obj = NULL;
// for each type in the inheritance chain
while( t )
while( type )
{
// for each mvar directly in the class
for( t_CKUINT i = 0; i < t->obj_mvars_offsets.size(); i++ )
for( t_CKUINT i = 0; i < type->obj_mvars_offsets.size(); i++ )
{
// get the object reference from the offsets
obj = OBJ_MEMBER_OBJECT( this, t->obj_mvars_offsets[i] );
obj = OBJ_MEMBER_OBJECT( this, type->obj_mvars_offsets[i] );
// release
CK_SAFE_RELEASE(obj);
}

// go up to parent type
t = t->parent;
type = type->parent;
}

// release origin shred
Expand Down
8 changes: 4 additions & 4 deletions src/core/chuck_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2533,13 +2533,13 @@ t_CKBOOL type_engine_scan2_exp_decl_create( Chuck_Env * env, a_Exp_Decl decl )
// more info
if( !isaStr )
{
EM_error2( decl->where,
"...(primitive types: 'int', 'float', 'time', 'dur', 'vec3', etc.)" );
EM_error2( 0,
"...(primitive types: 'int', 'float', 'time', 'dur', 'vec3', etc.)" );
}
else
{
EM_error2( decl->where,
"...(NOTE 'string' is a special Object whose operational semantics resemble both Object types and primitive types; e.g., instantiation and function argument-passing are like any other Object; however assignment '@=>' and '=>' are carried out by-value, as with primitive types such as 'int', 'float', 'time', 'dur', 'vec3', etc.)" );
EM_error2( 0,
"...(NOTE 'string' is a special Object whose operational semantics resemble both Object types and primitive types; e.g., instantiation and function argument-passing are like any other Object; however assignment '@=>' and '=>' are carried out by-value, as with primitive types such as 'int', 'float', 'time', 'dur', 'vec3', etc.)" );
}
return FALSE;
}
Expand Down
14 changes: 11 additions & 3 deletions src/core/chuck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,14 @@ void Chuck_Env::cleanup()
Chuck_Type * skip = ckt_object->type_ref != NULL ? ckt_object->type_ref->parent : NULL;
// free the Type type
CK_SAFE_UNLOCK_DELETE(ckt_class);

// part 2: break the dependency manually | 1.5.0.1 (ge) added
ckt_object->type_ref = skip;
ckt_object->type_ref = NULL; // was: skip -- but ckt_object is a Chuck_Object...
// and will try to to use type_ref->obj_mvars_offsets to cleanup, but aspects
// of chuck_type could be already be deleted before ~Chuck_Object() is invoked,
// including the obj_mvars_offsets vector; NOTE: this means that the final object
// does not delete its string mvar (by default it is NULL, so works out)

// finally, free the Object type
CK_SAFE_UNLOCK_DELETE(ckt_object);
}
Expand Down Expand Up @@ -4181,9 +4187,10 @@ t_CKTYPE type_engine_check_exp_decl_part2( Chuck_Env * env, a_Exp_Decl decl )
{
// offset
value->offset = env->curr->offset;
// if at class_scope
if( env->class_def && env->class_scope == 0 && isobj(env,type) )
// if at class_scope and is object
if( is_obj )
{
// cerr << "adding: " << value->name << " : " << value->offset << endl;
// add it to the class | 1.5.2.0 (ge)
env->class_def->obj_mvars_offsets.push_back( value->offset );
}
Expand Down Expand Up @@ -9565,6 +9572,7 @@ void Chuck_Type::reset()

// TODO: uncomment this, fix it to behave correctly
// TODO: make it safe to do this, as there are multiple instances of ->parent assignments without add-refs
// TODO: verify this is valid for final shutdown sequence, including Chuck_Env::cleanup()
// CK_SAFE_RELEASE( parent );
// CK_SAFE_RELEASE( array_type );
// CK_SAFE_RELEASE( ugen_info );
Expand Down
2 changes: 1 addition & 1 deletion src/core/ugen_xxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ DLL_QUERY xxx_query( Chuck_DL_Query * QUERY )
// add ctor( float value )
func = make_new_ctor( step_ctor_value );
func->add_arg( "float", "value" );
func->doc = "construct a Step with default 'value'";
func->doc = "construct a Step with default value.";
if( !type_engine_import_ctor( env, func ) ) goto error;

// add ctrl: next
Expand Down

0 comments on commit 5d921fc

Please sign in to comment.