diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index 69628ef61..4ea7a017a 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -1541,7 +1541,7 @@ static Chuck_DL_Api::Object CK_DLL_CALL ck_create_without_shred( Chuck_VM * vm, if( t == NULL ) { // print error message - EM_error2( 0, "DL_Api:object:ck_create_no_shred: NULL object reference." ); + EM_error2( 0, "DL_Api:object:ck_create_without_shred: NULL object reference." ); // done return NULL; } @@ -2114,7 +2114,7 @@ Chuck_DL_Return CK_DLL_CALL ck_invoke_mfun_immediate_mode( Chuck_Object * obj, t // iterate over c-style array for( t_CKUINT i = 0; i < numArgs; i++ ) args_vector.push_back(args_list[i]); // invoke the invoker - func->invoker_mfun->invoke( obj, args_vector ); + func->invoker_mfun->invoke( obj, args_vector, caller_shred ); } // return it diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index 3759b0693..2b60c658f 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -45,25 +45,22 @@ #include - - // major version must be the same between chuck:chugin -#define CK_DLL_VERSION_MAJOR (0x0009) +#define CK_DLL_VERSION_MAJOR (9) // minor version of chugin must be less than or equal to chuck's -#define CK_DLL_VERSION_MINOR (0x0000) +#define CK_DLL_VERSION_MINOR (0) #define CK_DLL_VERSION_MAKE(maj,min) ((t_CKUINT)(((maj) << 16) | (min))) #define CK_DLL_VERSION_GETMAJOR(v) (((v) >> 16) & 0xFFFF) #define CK_DLL_VERSION_GETMINOR(v) ((v) & 0xFFFF) #define CK_DLL_VERSION (CK_DLL_VERSION_MAKE(CK_DLL_VERSION_MAJOR, CK_DLL_VERSION_MINOR)) - - +// string literal containing default chugin path (platform-specific) extern char g_default_chugin_path[]; +// string literal containing environment variable for chugin search path extern char g_chugin_path_envvar[]; - // DL forward references struct Chuck_DL_Query; struct Chuck_DL_Class; @@ -888,16 +885,14 @@ struct Chuck_DL_Api void (CK_DLL_CALL * const release)( Object object ); // get reference count t_CKUINT (CK_DLL_CALL * const refcount)( Object object ); - // instantiating and initializing a ChucK object by type, with reference to a parent shred + // instantiating and initializing a ChucK object by type // if addRef == TRUE the newly created object will have a reference count of 1; otherwise 0 // NOTE set addRef to TRUE if you intend to keep a reference of the newly created object around (e.g., in the chugin) // NOTE set addRef to FALSE if the created object is to be returned without keeping a reference around Object (CK_DLL_CALL * const create)( Chuck_VM_Shred *, Type type, t_CKBOOL addRef ); // instantiating and initializing a ChucK object by type, with no reference to a parent shred - // if addRef == TRUE the newly created object will have a reference count of 1; otherwise 0 Object (CK_DLL_CALL * const create_without_shred)( Chuck_VM *, Type type, t_CKBOOL addRef ); - // instantiate and initialize a ChucK string by type - // if addRef == TRUE the newly created object will have a reference count of 1; otherwise 0 + // instantiate and initialize a ChucK string by type (without ref to a parent shred) String (CK_DLL_CALL * const create_string)( Chuck_VM *, const char * value, t_CKBOOL addRef ); // get the origin shred Chuck_VM_Shred * (CK_DLL_CALL * const get_origin_shred)( Object object ); diff --git a/src/core/chuck_instr.cpp b/src/core/chuck_instr.cpp index 26d1b6652..f16b7f68f 100644 --- a/src/core/chuck_instr.cpp +++ b/src/core/chuck_instr.cpp @@ -4226,7 +4226,7 @@ void Chuck_Instr_Pre_Constructor::execute( Chuck_VM * vm, Chuck_VM_Shred * shred //----------------------------------------------------------------------------- // name: instantiate_object() -// desc: ... +// desc: instantiate Object including data and virtual table //----------------------------------------------------------------------------- t_CKBOOL initialize_object( Chuck_Object * object, Chuck_Type * type, Chuck_VM_Shred * shred, Chuck_VM * vm, t_CKBOOL setShredOrigin ) { @@ -4239,20 +4239,8 @@ t_CKBOOL initialize_object( Chuck_Object * object, Chuck_Type * type, Chuck_VM_S // REFACTOR-2017: added | 1.5.1.5 (ge & andrew) moved here from instantiate_... object->setOriginVM( vm ); - // check if origin shred is available | 1.5.1.5 (ge) - if( shred ) - { - // set the origin shred only in specific cases... - // UGens: needs shred for auto-disconnect when shred is removed - // user-defined classes (that refer to global-scope variables): - // ...needs shred to access the global-scope variables across sporking - // setShredOrigin: if true, this is likely a registered callback_on_instantiate - if( type->ugen_info || type->originHint == te_originUserDefined || setShredOrigin ) - { - // set origin shred | 1.5.1.5 (ge) was: ugen->shred = shred; - object->setOriginShred( shred ); - } - } + // set origin shred for non-ugens | 1.5.1.5 (ge & andrew) moved here from instantiate_... + if( !type->ugen_info && setShredOrigin ) object->setOriginShred( shred ); // allocate virtual table object->vtable = new Chuck_VTable; @@ -4281,8 +4269,15 @@ t_CKBOOL initialize_object( Chuck_Object * object, Chuck_Type * type, Chuck_VM_S { // ugen Chuck_UGen * ugen = (Chuck_UGen *)object; - // add ugen to shred | 1.5.1.5 (ge & andrew) moved from instantiate_and_initialize_object() - if( shred ) shred->add( ugen ); + // UGens: needs shred for auto-disconnect when shred is removed + // 1.5.1.5 (ge & andrew) moved from instantiate_and_initialize_object() + if( shred ) + { + // add ugen to shred (ref-counted) + shred->add( ugen ); + // add shred to ugen (ref-counted) | 1.5.1.5 (ge) was: ugen->shred = shred; + object->setOriginShred( shred ); + } // set tick if( type->ugen_info->tick ) ugen->tick = type->ugen_info->tick; // added 1.3.0.0 -- tickf for multi-channel tick diff --git a/src/core/chuck_vm.cpp b/src/core/chuck_vm.cpp index 644288b9f..cb224ff39 100644 --- a/src/core/chuck_vm.cpp +++ b/src/core/chuck_vm.cpp @@ -1936,7 +1936,7 @@ t_CKBOOL Chuck_VM_Shred::add( Chuck_UGen * ugen ) return FALSE; // increment reference count (added 1.3.0.0) - ugen->add_ref(); + CK_SAFE_ADD_REF( ugen ); // RUBBISH // cerr << "vm add ugen: 0x" << hex << (int)ugen << endl; @@ -3193,7 +3193,7 @@ void Chuck_VM_Status::clear() Chuck_VM_MFunInvoker::Chuck_VM_MFunInvoker() { // zero - shred = NULL; + invoker_shred = NULL; instr_pushThis = NULL; instr_pushReturnVar = NULL; } @@ -3220,7 +3220,7 @@ Chuck_VM_MFunInvoker::~Chuck_VM_MFunInvoker() t_CKBOOL Chuck_VM_MFunInvoker::setup( Chuck_Func * func, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * caller ) { // clean up first - if( shred ) cleanup(); + if( invoker_shred ) cleanup(); // a vector of VM instructions vector instructions; @@ -3387,15 +3387,15 @@ t_CKBOOL Chuck_VM_MFunInvoker::setup( Chuck_Func * func, t_CKUINT func_vt_offset code->need_this = FALSE; // create dedicated shred - shred = new Chuck_VM_Shred; + invoker_shred = new Chuck_VM_Shred; // set the VM ref (needed by initialize) - shred->vm_ref = vm; + invoker_shred->vm_ref = vm; // initialize with code + allocate stacks - shred->initialize( code ); + invoker_shred->initialize( code ); // set name - shred->name = func->signature(FALSE,TRUE); + invoker_shred->name = func->signature(FALSE,TRUE); // enter immediate mode (will throw runtime exception on any time/event ops) - shred->setImmediateMode( TRUE ); + invoker_shred->setImmediateMode( TRUE ); // done return TRUE; @@ -3442,7 +3442,7 @@ static Chuck_Instr_Reg_Push_Imm2 * ckvm_next_instr_as_float( vector & args ) +Chuck_DL_Return Chuck_VM_MFunInvoker::invoke( Chuck_Object * obj, const vector & args, Chuck_VM_Shred * parent_shred ) { // the return value Chuck_DL_Return RETURN; @@ -3452,7 +3452,7 @@ Chuck_DL_Return Chuck_VM_MFunInvoker::invoke( Chuck_Object * obj, const vectorset( (t_CKUINT)&RETURN ); // reset shred: program counter - shred->pc = 0; + invoker_shred->pc = 0; // next pc - shred->next_pc = 1; + invoker_shred->next_pc = 1; + + // set parent + invoker_shred->parent = parent_shred; + // commented out: parent if any should have been set in setup() + // invoker_shred->parent = obj->originShred(); // set parent base_ref; in case mfun is part of a non-public class // that can access file-global variables outside the class definition - shred->parent = obj->originShred(); - if( shred->parent ) shred->base_ref = shred->parent->base_ref; - else shred->base_ref = shred->mem; + if( invoker_shred->parent ) invoker_shred->base_ref = invoker_shred->parent->base_ref; + else invoker_shred->base_ref = invoker_shred->mem; // shred in dump (all done) - shred->is_dumped = FALSE; + invoker_shred->is_dumped = FALSE; // shred done - shred->is_done = FALSE; + invoker_shred->is_done = FALSE; // shred running - shred->is_running = FALSE; + invoker_shred->is_running = FALSE; // shred abort - shred->is_abort = FALSE; + invoker_shred->is_abort = FALSE; // set the instr - shred->instr = shred->code->instr; + invoker_shred->instr = invoker_shred->code->instr; // zero out the id (shred is in immediate mode and cannot be shreduled) - shred->xid = 0; + invoker_shred->xid = 0; // inherit now from vm - shred->now = shred->vm_ref->now(); + invoker_shred->now = invoker_shred->vm_ref->now(); // run shred on VM - shred->run( shred->vm_ref ); + invoker_shred->run( invoker_shred->vm_ref ); // done; by the point, return should have been filled with return value, if func has one return RETURN; @@ -3564,7 +3568,7 @@ void Chuck_VM_MFunInvoker::cleanup() { // release shred reference // NB this should also cleanup the code and VM instruction we created in setup - CK_SAFE_RELEASE( shred ); + CK_SAFE_RELEASE( invoker_shred ); // clear the arg instructions instr_args.clear(); diff --git a/src/core/chuck_vm.h b/src/core/chuck_vm.h index 3a6a616f2..f5e98c178 100644 --- a/src/core/chuck_vm.h +++ b/src/core/chuck_vm.h @@ -843,13 +843,14 @@ struct Chuck_VM_MFunInvoker Chuck_VM * vm, Chuck_VM_Shred * caller ); // invoke the member function Chuck_DL_Return invoke( Chuck_Object * obj, - const std::vector & args ); + const std::vector & args, + Chuck_VM_Shred * parent_shred ); // clean up void cleanup(); public: // dedicated shred to call the mfun on - Chuck_VM_Shred * shred; + Chuck_VM_Shred * invoker_shred; // instructions for args (to be filled on invoke) std::vector instr_args; // instruction to update on invoke: pushing this pointer diff --git a/src/core/ugen_xxx.cpp b/src/core/ugen_xxx.cpp index b05076b38..7765e117f 100644 --- a/src/core/ugen_xxx.cpp +++ b/src/core/ugen_xxx.cpp @@ -1634,7 +1634,7 @@ CK_DLL_TICK( foogen_tick ) // set input data->input = in; // invoke the function | 1.5.1.5 (ge) encapsulated into invoker - ret = data->invoker->invoke( SELF, args ); + ret = data->invoker->invoke( SELF, args, SELF->originShred() ); // set output data->output = ret.v_float; } diff --git a/src/core/ulib_opsc.cpp b/src/core/ulib_opsc.cpp index 7a452d8d9..f9619c477 100644 --- a/src/core/ulib_opsc.cpp +++ b/src/core/ulib_opsc.cpp @@ -1584,7 +1584,7 @@ CK_DLL_MFUN( oscmsg_numArgs ) CK_DLL_MFUN( oscmsg_getInt ) { - int i = GET_NEXT_INT( ARGS ); + t_CKINT i = GET_NEXT_INT( ARGS ); Chuck_ArrayInt * args_obj = (Chuck_ArrayInt *)OBJ_MEMBER_OBJECT( SELF, oscmsg_offset_args ); Chuck_Object * arg_obj; @@ -1602,7 +1602,7 @@ CK_DLL_MFUN( oscmsg_getInt ) CK_DLL_MFUN( oscmsg_getFloat ) { - int i = GET_NEXT_INT( ARGS ); + t_CKINT i = GET_NEXT_INT( ARGS ); Chuck_ArrayInt * args_obj = (Chuck_ArrayInt *)OBJ_MEMBER_OBJECT( SELF, oscmsg_offset_args ); Chuck_Object * arg_obj; if( i >= 0 && i < args_obj->size() ) @@ -1616,7 +1616,7 @@ CK_DLL_MFUN( oscmsg_getFloat ) CK_DLL_MFUN( oscmsg_getString ) { - int i = GET_NEXT_INT( ARGS ); + t_CKINT i = GET_NEXT_INT( ARGS ); Chuck_ArrayInt * args_obj = (Chuck_ArrayInt *)OBJ_MEMBER_OBJECT( SELF, oscmsg_offset_args ); Chuck_Object * arg_obj;