int ISQLite3Provider.sqlite3_create_function(IntPtr db, string name, int nargs, object v, delegate_function_aggregate_step func_step, delegate_function_aggregate_final func_final) { string key = string.Format("{0}.{1}", nargs, name); if (_agg_functions.ContainsKey(key)) { agg_function_hook_info hi = _agg_functions[key]; // TODO maybe turn off the hook here, for now hi.free(); _agg_functions.Remove(key); } GCHandle pinned = GCHandle.Alloc(util.to_utf8(name), GCHandleType.Pinned); IntPtr ptr = pinned.AddrOfPinnedObject(); int rc; // 1 is SQLITE_UTF8 if (func_step != null) { // TODO both func_step and func_final must be non-null agg_function_hook_info hi = new agg_function_hook_info(func_step, func_final, v); rc = SQLite3RuntimeProvider.sqlite3_create_function_v2(db.ToInt64(), ptr.ToInt64(), nargs, 1, hi.ptr.ToInt64(), 0, Marshal.GetFunctionPointerForDelegate(new callback_agg_function_step(agg_function_hook_bridge_step)).ToInt64(), Marshal.GetFunctionPointerForDelegate(new callback_agg_function_final(agg_function_hook_bridge_final)).ToInt64(), 0); if (rc == 0) { _agg_functions[key] = hi; } } else { rc = SQLite3RuntimeProvider.sqlite3_create_function_v2(db.ToInt64(), ptr.ToInt64(), nargs, 1, 0, 0, 0, 0, 0); } pinned.Free(); return(rc); }