ronantakizawa/codereview-bench huggingface dataset:
Repository: dotnet/runtime
File: src/coreclr/vm/method.cpp (C++)

Code before:
    }
}
#endif // !FEATURE_PORTABLE_ENTRYPOINTS

//*******************************************************************************
void MethodDesc::Reset()
{
    WRAPPER_NO_CONTRACT;

    // This method is not thread-safe since we are updating
    // different pieces of data non-atomically.
    // Use this only if you can guarantee thread-safety somehow.

    _ASSERTE(InEnCEnabledModule() || // The process is frozen by the debugger
             IsDynamicMethod() || // These are used in a very restricted way
             GetLoaderModule()->IsReflectionEmit()); // Rental methods

    // Reset any flags relevant to the old code
    ClearFlagsOnUpdate();

#ifdef FEATURE_PORTABLE_ENTRYPOINTS
    ResetPortableEntryPoint();
#else // !FEATURE_PORTABLE_ENTRYPOINTS
    _ASSERTE(HasPrecode());
    GetPrecode()->Reset();
#endif // !FEATURE_PORTABLE_ENTRYPOINTS

    if (HasNativeCodeSlot())
    {
        *GetAddrOfNativeCodeSlot() = (PCODE)NULL;
    }

#ifdef FEATURE_INTERPRETER
    ClearInterpreterCodePointer();
#endif

    _ASSERTE(!HasNativeCode());
}

//*******************************************************************************
Dictionary* MethodDesc::GetMethodDictionary()
{
    WRAPPER_NO_CONTRACT;

    return
        (GetClassification() == mcInstantiated)
        ? (Dictionary*) (AsInstantiatedMethodDesc()->IMD_GetMethodDictionary())
        : NULL;
}

//*******************************************************************************

Review comment (suggestion):
```suggestion
#endif // FEATURE_PORTABLE_ENTRYPOINTS
```

Code after:

    _ASSERTE(InEnCEnabledModule() || // The process is frozen by the debugger
             IsDynamicMethod() || // These are used in a very restricted way
             GetLoaderModule()->IsReflectionEmit()); // Rental methods

    // Reset any flags relevant to the old code
    ClearFlagsOnUpdate();

#ifdef FEATURE_PORTABLE_ENTRYPOINTS
    ResetPortableEntryPoint();
#else // !FEATURE_PORTABLE_ENTRYPOINTS
    _ASSERTE(HasPrecode());
    GetPrecode()->Reset();
#endif // FEATURE_PORTABLE_ENTRYPOINTS

    if (HasNativeCodeSlot())
    {
        *GetAddrOfNativeCodeSlot() = (PCODE)NULL;
    }

#ifdef FEATURE_INTERPRETER
    ClearInterpreterCodePointer();
#endif

    _ASSERTE(!HasNativeCode());
}

//*******************************************************************************
Dictionary* MethodDesc::GetMethodDictionary()
{
    WRAPPER_NO_CONTRACT;

    return
        (GetClassification() == mcInstantiated)
        ? (Dictionary*) (AsInstantiatedMethodDesc()->IMD_GetMethodDictionary())
        : NULL;
}

//*******************************************************************************
DictionaryLayout* MethodDesc::GetDictionaryLayout()
{
    WRAPPER_NO_CONTRACT;

    return
        ((GetClassification() == mcInstantiated) && !IsUnboxingStub())
        ? AsInstantiatedMethodDesc()->IMD_GetDictionaryLayout()
        : NULL;
}

#endif // !DACCESS_COMPILE
Repository: dotnet/runtime
File: src/coreclr/vm/dynamicmethod.cpp (C++)

Code before:
    } CONTRACTL_END;

    IndCellList * link = (IndCellList *)m_jitTempData.New(sizeof(IndCellList));
    link->indcell = indcell;

    // Insert into m_UsedIndCellList
    while (true)
    {
        link->pNext = m_UsedIndCellList;
        if (InterlockedCompareExchangeT(&m_UsedIndCellList, link, link->pNext) == link->pNext)
            break;
    }
}

void LCGMethodResolver::ResolveToken(mdToken token, ResolvedToken* resolvedToken)
{
    STANDARD_VM_CONTRACT;

    GCX_COOP();

    struct
    {
        OBJECTREF Resolver;
    } gc;
    gc.Resolver = ObjectFromHandle(m_managedResolver);
    VALIDATEOBJECTREF(gc.Resolver); // gc root must be up the stack

    TypeHandle handle;
    MethodDesc* pMD;
    FieldDesc* pFD;

    GCPROTECT_BEGIN(gc);

    UnmanagedCallersOnlyCaller resolveToken(METHOD__RESOLVER__RESOLVE_TOKEN);
    TADDR typeHandleValue = 0;
    TADDR methodHandleValue = 0;
    TADDR fieldHandleValue = 0;
    resolveToken.InvokeThrowing(&gc.Resolver, static_cast<int32_t>(token), &typeHandleValue, &methodHandleValue, &fieldHandleValue);

    handle = TypeHandle::FromTAddr(typeHandleValue);
    pMD = reinterpret_cast<MethodDesc*>(methodHandleValue);
    pFD = reinterpret_cast<FieldDesc*>(fieldHandleValue);

    GCPROTECT_END();

    _ASSERTE(pMD == NULL || pFD == NULL);

    if (handle.IsNull())
    {
        if (pMD != NULL)
        {

Review comment (refactor):
What is "gc root must be up the stack" comment trying to say?

Also, `ObjectFromHandle` does `VALIDATEOBJECTREF` as well. I do not think we need to duplicate it here.

Code after:
    // Insert into m_UsedIndCellList
    while (true)
    {
        link->pNext = m_UsedIndCellList;
        if (InterlockedCompareExchangeT(&m_UsedIndCellList, link, link->pNext) == link->pNext)
            break;
    }
}

void LCGMethodResolver::ResolveToken(mdToken token, ResolvedToken* resolvedToken)
{
    STANDARD_VM_CONTRACT;

    GCX_COOP();

    struct
    {
        OBJECTREF Resolver;
    } gc;
    gc.Resolver = ObjectFromHandle(m_managedResolver);

    TypeHandle handle;
    MethodDesc* pMD;
    FieldDesc* pFD;

    GCPROTECT_BEGIN(gc);

    UnmanagedCallersOnlyCaller resolveToken(METHOD__RESOLVER__RESOLVE_TOKEN);
    TADDR typeHandleValue = 0;
    resolveToken.InvokeThrowing(&gc.Resolver, static_cast<int32_t>(token), &typeHandleValue, &pMD, &pFD);

    handle = TypeHandle::FromTAddr(typeHandleValue);

    GCPROTECT_END();

    _ASSERTE(pMD == NULL || pFD == NULL);

    if (handle.IsNull())
    {
        if (pMD != NULL)
        {
            handle = pMD->GetMethodTable();
        }
        else if (pFD != NULL)
        {
            handle = pFD->GetEnclosingMethodTable();
        }
    }

    _ASSERTE(!handle.IsNull());
    resolvedToken->TypeHandle = handle;
Repository: dotnet/runtime
File: src/coreclr/vm/dynamicmethod.cpp (C++)

Code before:
}

void LCGMethodResolver::ResolveToken(mdToken token, ResolvedToken* resolvedToken)
{
    STANDARD_VM_CONTRACT;

    GCX_COOP();

    struct
    {
        OBJECTREF Resolver;
    } gc;
    gc.Resolver = ObjectFromHandle(m_managedResolver);
    VALIDATEOBJECTREF(gc.Resolver); // gc root must be up the stack

    TypeHandle handle;
    MethodDesc* pMD;
    FieldDesc* pFD;

    GCPROTECT_BEGIN(gc);

    UnmanagedCallersOnlyCaller resolveToken(METHOD__RESOLVER__RESOLVE_TOKEN);
    TADDR typeHandleValue = 0;
    TADDR methodHandleValue = 0;
    TADDR fieldHandleValue = 0;
    resolveToken.InvokeThrowing(&gc.Resolver, static_cast<int32_t>(token), &typeHandleValue, &methodHandleValue, &fieldHandleValue);

    handle = TypeHandle::FromTAddr(typeHandleValue);
    pMD = reinterpret_cast<MethodDesc*>(methodHandleValue);
    pFD = reinterpret_cast<FieldDesc*>(fieldHandleValue);

    GCPROTECT_END();

    _ASSERTE(pMD == NULL || pFD == NULL);

    if (handle.IsNull())
    {
        if (pMD != NULL)
        {
            handle = pMD->GetMethodTable();
        }
        else if (pFD != NULL)
        {
            handle = pFD->GetEnclosingMethodTable();
        }
    }

    _ASSERTE(!handle.IsNull());
    resolvedToken->TypeHandle = handle;
    resolvedToken->Method = pMD;
    resolvedToken->Field = pFD;

Review comment (suggestion):
```suggestion
    TADDR typeHandleValue = 0;
    resolveToken.InvokeThrowing(&gc.Resolver, static_cast<int32_t>(token), &typeHandleValue, &pMD, &pFD);
```

Code after:

    GCX_COOP();

    struct
    {
        OBJECTREF Resolver;
    } gc;
    gc.Resolver = ObjectFromHandle(m_managedResolver);

    TypeHandle handle;
    MethodDesc* pMD;
    FieldDesc* pFD;

    GCPROTECT_BEGIN(gc);

    UnmanagedCallersOnlyCaller resolveToken(METHOD__RESOLVER__RESOLVE_TOKEN);
    TADDR typeHandleValue = 0;
    resolveToken.InvokeThrowing(&gc.Resolver, static_cast<int32_t>(token), &typeHandleValue, &pMD, &pFD);

    handle = TypeHandle::FromTAddr(typeHandleValue);

    GCPROTECT_END();

    _ASSERTE(pMD == NULL || pFD == NULL);

    if (handle.IsNull())
    {
        if (pMD != NULL)
        {
            handle = pMD->GetMethodTable();
        }
        else if (pFD != NULL)
        {
            handle = pFD->GetEnclosingMethodTable();
        }
    }

    _ASSERTE(!handle.IsNull());
    resolvedToken->TypeHandle = handle;
    resolvedToken->Method = pMD;
    resolvedToken->Field = pFD;
}

//---------------------------------------------------------------------------------------
//
SigPointer
LCGMethodResolver::ResolveSignature(
    mdToken token)
{
    STANDARD_VM_CONTRACT;
Repository: dotnet/runtime
File: src/coreclr/vm/dynamicmethod.cpp (C++)

Code before:
    GCX_COOP();

    struct
    {
        OBJECTREF Resolver;
        OBJECTREF DataArray;
    } gc;
    gc.Resolver = ObjectFromHandle(m_managedResolver);
    gc.DataArray = NULL;
    VALIDATEOBJECTREF(gc.Resolver); // gc root must be up the stack

    DWORD cbSig = 0;
    PCCOR_SIGNATURE pSig = NULL;

    GCPROTECT_BEGIN(gc);

    UnmanagedCallersOnlyCaller resolveSignature(METHOD__RESOLVER__RESOLVE_SIGNATURE);
    resolveSignature.InvokeThrowing(&gc.Resolver, static_cast<int32_t>(token), 0, &gc.DataArray);

    U1ARRAYREF dataArray = (U1ARRAYREF)gc.DataArray;
    if (dataArray == NULL)
        COMPlusThrow(kInvalidProgramException);

    cbSig = dataArray->GetNumComponents();
    pSig = (PCCOR_SIGNATURE)m_jitTempData.New(cbSig);
    memcpy((void *)pSig, dataArray->GetDataPtr(), cbSig);

    GCPROTECT_END();

    return SigPointer(pSig, cbSig);
} // LCGMethodResolver::ResolveSignature

//---------------------------------------------------------------------------------------
//
SigPointer
LCGMethodResolver::ResolveSignatureForVarArg(
    mdToken token)
{
    STANDARD_VM_CONTRACT;

    GCX_COOP();

    struct
    {
        OBJECTREF Resolver;
        OBJECTREF DataArray;
    } gc;
    gc.Resolver = ObjectFromHandle(m_managedResolver);
    gc.DataArray = NULL;
    VALIDATEOBJECTREF(gc.Resolver); // gc root must be up the stack


Review comment (suggestion):
We make some function calls here, some aren't obviously **not** switching to PREEMPT mode. Let's avoid the local `U1ARRAYREF`. We can simply type the `DataArray` if you'd like or create a new field in the `gc` struct.

Code after:
    DWORD cbSig = 0;
    PCCOR_SIGNATURE pSig = NULL;

    GCPROTECT_BEGIN(gc);

    UnmanagedCallersOnlyCaller resolveSignature(METHOD__RESOLVER__RESOLVE_SIGNATURE);
    resolveSignature.InvokeThrowing(&gc.Resolver, static_cast<int32_t>(token), 0, &gc.DataArray);

    if (gc.DataArray == NULL)
    {
        COMPlusThrow(kInvalidProgramException);
    }

    cbSig = gc.DataArray->GetNumComponents();
    pSig = (PCCOR_SIGNATURE)m_jitTempData.New(cbSig);
    memcpy((void *)pSig, gc.DataArray->GetDataPtr(), cbSig);

    GCPROTECT_END();

    return SigPointer(pSig, cbSig);
} // LCGMethodResolver::ResolveSignature

//---------------------------------------------------------------------------------------
//
SigPointer
LCGMethodResolver::ResolveSignatureForVarArg(
    mdToken token)
{
    STANDARD_VM_CONTRACT;

    GCX_COOP();

    struct
    {
        OBJECTREF Resolver;
        U1ARRAYREF DataArray;
    } gc;
    gc.Resolver = ObjectFromHandle(m_managedResolver);
    gc.DataArray = NULL;

    DWORD cbSig = 0;
    PCCOR_SIGNATURE pSig = NULL;

    GCPROTECT_BEGIN(gc);

    UnmanagedCallersOnlyCaller resolveSignature(METHOD__RESOLVER__RESOLVE_SIGNATURE);
    resolveSignature.InvokeThrowing(&gc.Resolver, static_cast<int32_t>(token), 1, &gc.DataArray);

    if (gc.DataArray == NULL)
    {
        COMPlusThrow(kInvalidProgramException);
Repository: dotnet/runtime
File: src/coreclr/vm/array.cpp (C++)

Code before:
        return "Get";
    case ARRAY_FUNC_SET:
        return "Set";
    case ARRAY_FUNC_ADDRESS:
        return "Address";
    default:
        return COR_CTOR_METHOD_NAME;    // ".ctor"
    }
}

/*****************************************************************************************/
DWORD ArrayMethodDesc::GetAttrs()
{
    LIMITED_METHOD_CONTRACT;
    return (GetArrayFuncIndex() >= ARRAY_FUNC_CTOR) ? (mdPublic | mdRTSpecialName) : mdPublic;
}

#ifndef DACCESS_COMPILE

/*****************************************************************************************/

//
// Generate a short sig (descr) for an array accessors
//

static VOID GenerateArrayAccessorCallSig(
    DWORD   dwRank,
    DWORD   dwFuncType,    // Load, store, or <init>
    PCCOR_SIGNATURE *ppSig,// Generated signature
    DWORD * pcSig,         // Generated signature size
    LoaderAllocator *pLoaderAllocator,
    AllocMemTracker *pamTracker,
    BOOL fForStubAsIL
    )
{
    CONTRACTL {
        STANDARD_VM_CHECK;
        PRECONDITION(dwRank >= 1 && dwRank < 0x3ffff);
    } CONTRACTL_END;

    PCOR_SIGNATURE pSig;
    PCOR_SIGNATURE pSigMemory;
    DWORD   dwCallSigSize = dwRank;
    DWORD   dwArgCount = (dwFuncType == ArrayMethodDesc::ARRAY_FUNC_SET) ? dwRank+1 : dwRank;
    DWORD   i;

    switch (dwFuncType)
    {
        // <callconv> <argcount> VAR 0 I4 , ... , I4
        case ArrayMethodDesc::ARRAY_FUNC_GET:
            dwCallSigSize += 4;

Review comment (suggestion):
```suggestion
static void GenerateArrayAccessorCallSig(
```

Code after:
        return "Get";
    case ARRAY_FUNC_SET:
        return "Set";
    case ARRAY_FUNC_ADDRESS:
        return "Address";
    default:
        return COR_CTOR_METHOD_NAME;    // ".ctor"
    }
}

/*****************************************************************************************/
DWORD ArrayMethodDesc::GetAttrs()
{
    LIMITED_METHOD_CONTRACT;
    return (GetArrayFuncIndex() >= ARRAY_FUNC_CTOR) ? (mdPublic | mdRTSpecialName) : mdPublic;
}

#ifndef DACCESS_COMPILE

/*****************************************************************************************/

//
// Generate a short sig (descr) for an array accessors
//

static void GenerateArrayAccessorCallSig(
    DWORD   dwRank,
    DWORD   dwFuncType,    // Load, store, or <init>
    PCCOR_SIGNATURE *ppSig,// Generated signature
    DWORD * pcSig,         // Generated signature size
    LoaderAllocator *pLoaderAllocator,
    AllocMemTracker *pamTracker,
    BOOL fForStubAsIL
    )
{
    CONTRACTL {
        STANDARD_VM_CHECK;
        PRECONDITION(dwRank >= 1 && dwRank < 0x3ffff);
    } CONTRACTL_END;

    PCOR_SIGNATURE pSig;
    PCOR_SIGNATURE pSigMemory;
    DWORD   dwCallSigSize = dwRank;
    DWORD   dwArgCount = (dwFuncType == ArrayMethodDesc::ARRAY_FUNC_SET) ? dwRank+1 : dwRank;
    DWORD   i;

    switch (dwFuncType)
    {
        // <callconv> <argcount> VAR 0 I4 , ... , I4
        case ArrayMethodDesc::ARRAY_FUNC_GET:
            dwCallSigSize += 4;
Repository: duckdb/duckdb
File: src/function/table/table_scan.cpp (C++)

Code before:
	});
}

string TableScanToString(const FunctionData *bind_data_p) {
	auto &bind_data = (const TableScanBindData &)*bind_data_p;
	string result = bind_data.table->name;
	return result;
}

TableFunction TableScanFunction::GetFunction() {
	TableFunction scan_function("seq_scan", {}, TableScanFunc);
	scan_function.init_local = TableScanInitLocal;
	scan_function.init_global = TableScanInitGlobal;
	scan_function.statistics = TableScanStatistics;
	scan_function.dependency = TableScanDependency;
	scan_function.cardinality = TableScanCardinality;
	scan_function.pushdown_complex_filter = TableScanPushdownComplexFilter;
	scan_function.to_string = TableScanToString;
	scan_function.table_scan_progress = TableScanProgress;
	scan_function.get_batch_index = TableScanGetBatchIndex;
	scan_function.projection_pushdown = true;
	scan_function.filter_pushdown = true;
	return scan_function;
}

TableCatalogEntry *TableScanFunction::GetStandardEntry(const TableFunction &function, const FunctionData *bind_data_p) {
	if (function.function != TableScanFunc || !bind_data_p) {
		return nullptr;
	}
	auto &bind_data = (TableScanBindData &)*bind_data_p;
	return bind_data.table;
}

} // namespace duckdb


Review comment (suggestion):
This should probably still be called `GetTableEntry`

Code after:
				// use an index scan!
				bind_data.is_index_scan = true;
				get.function.init_local = nullptr;
				get.function.init_global = IndexScanInitGlobal;
				get.function.function = IndexScanFunction;
				get.function.table_scan_progress = nullptr;
				get.function.get_batch_index = nullptr;
				get.function.filter_pushdown = false;
			} else {
				bind_data.result_ids.clear();
			}
			return true;
		}
		return false;
	});
}

string TableScanToString(const FunctionData *bind_data_p) {
	auto &bind_data = (const TableScanBindData &)*bind_data_p;
	string result = bind_data.table->name;
	return result;
}

TableFunction TableScanFunction::GetFunction() {
	TableFunction scan_function("seq_scan", {}, TableScanFunc);
	scan_function.init_local = TableScanInitLocal;
	scan_function.init_global = TableScanInitGlobal;
	scan_function.statistics = TableScanStatistics;
	scan_function.dependency = TableScanDependency;
	scan_function.cardinality = TableScanCardinality;
	scan_function.pushdown_complex_filter = TableScanPushdownComplexFilter;
	scan_function.to_string = TableScanToString;
	scan_function.table_scan_progress = TableScanProgress;
	scan_function.get_batch_index = TableScanGetBatchIndex;
	scan_function.projection_pushdown = true;
	scan_function.filter_pushdown = true;
	return scan_function;
}

TableCatalogEntry *TableScanFunction::GetTableEntry(const TableFunction &function, const FunctionData *bind_data_p) {
	if (function.function != TableScanFunc || !bind_data_p) {
		return nullptr;
	}
	auto &bind_data = (TableScanBindData &)*bind_data_p;
	return bind_data.table;
}

} // namespace duckdb
Repository: duckdb/duckdb
File: src/common/types/vector.cpp (C++)

Code before:
		auto &val_children = ListValue::GetChildren(val);
		if (!val_children.empty()) {
			for (idx_t i = 0; i < val_children.size(); i++) {
				ListVector::PushBack(*this, val_children[i]);
			}
		}
		//! now set the pointer
		auto &entry = ((list_entry_t *)data)[index];
		entry.length = val_children.size();
		entry.offset = offset;
		break;
	}
	default:
		throw InternalException("Unimplemented type for Vector::SetValue");
	}
}

Value Vector::AttachTypeInfo(const Vector &v, Value &&val) {
	if (!v.GetType().HasAlias()) {
		return val;
	}
	val.type().CopyAuxInfo(v.GetType());
	return val;
}

Value Vector::GetValue(const Vector &v_p, idx_t index_p) {
	const Vector *vector = &v_p;
	idx_t index = index_p;
	bool finished = false;
	while (!finished) {
		switch (vector->GetVectorType()) {
		case VectorType::CONSTANT_VECTOR:
			index = 0;
			finished = true;
			break;
		case VectorType::FLAT_VECTOR:
			finished = true;
			break;
			// dictionary: apply dictionary and forward to child
		case VectorType::DICTIONARY_VECTOR: {
			auto &sel_vector = DictionaryVector::SelVector(*vector);
			auto &child = DictionaryVector::Child(*vector);
			vector = &child;
			index = sel_vector.get_index(index);
			break;
		}
		case VectorType::SEQUENCE_VECTOR: {
			int64_t start, increment;
			SequenceVector::GetSequence(*vector, start, increment);
			return AttachTypeInfo(*vector, Value::Numeric(vector->GetType(), start + increment * index));
		}

Review comment (suggestion):
Are these changes to `GetValue` necessary? It seems to do the same as the previous function but (in my opinion) in a less readable manner.

Code after:
		}
		//! now set the pointer
		auto &entry = ((list_entry_t *)data)[index];
		entry.length = val_children.size();
		entry.offset = offset;
		break;
	}
	default:
		throw InternalException("Unimplemented type for Vector::SetValue");
	}
}

Value Vector::GetValueInternal(const Vector &v_p, idx_t index_p) {
	const Vector *vector = &v_p;
	idx_t index = index_p;
	bool finished = false;
	while (!finished) {
		switch (vector->GetVectorType()) {
		case VectorType::CONSTANT_VECTOR:
			index = 0;
			finished = true;
			break;
		case VectorType::FLAT_VECTOR:
			finished = true;
			break;
			// dictionary: apply dictionary and forward to child
		case VectorType::DICTIONARY_VECTOR: {
			auto &sel_vector = DictionaryVector::SelVector(*vector);
			auto &child = DictionaryVector::Child(*vector);
			vector = &child;
			index = sel_vector.get_index(index);
			break;
		}
		case VectorType::SEQUENCE_VECTOR: {
			int64_t start, increment;
			SequenceVector::GetSequence(*vector, start, increment);
			return Value::Numeric(vector->GetType(), start + increment * index);
		}
		default:
			throw InternalException("Unimplemented vector type for Vector::GetValue");
		}
	}
	auto data = vector->data;
	auto &validity = vector->validity;
	auto &type = vector->GetType();

	if (!validity.RowIsValid(index)) {
		return Value(vector->GetType());
	}
	switch (vector->GetType().id()) {
	case LogicalTypeId::BOOLEAN:
Repository: duckdb/duckdb
File: tools/juliapkg/src/table_function.jl (Julia)

Code before:
function set_stats_cardinality(bind_info::BindInfo, cardinality::UInt64, is_exact::Bool)
    duckdb_bind_set_cardinality(bind_info.handle, cardinality, is_exact)
    return
end

function add_result_column(bind_info::BindInfo, name::AbstractString, type::DataType)
    return add_result_column(bind_info, name, create_logical_type(type))
end

function add_result_column(bind_info::BindInfo, name::AbstractString, type::LogicalType)
    return duckdb_bind_add_result_column(bind_info.handle, name, type.handle)
end

function get_extra_data(bind_info::BindInfo)
    return bind_info.main_function.extra_data
end

function _add_global_object(main_function, object)
    lock(main_function.global_lock)
    push!(main_function.global_objects, object)
    unlock(main_function.global_lock)
    return
end

function _remove_global_object(main_function, object)
    lock(main_function.global_lock)
    delete!(main_function.global_objects, object)
    unlock(main_function.global_lock)
    return
end

function _table_bind_cleanup(data::Ptr{Cvoid})
    info::InfoWrapper = unsafe_pointer_to_objref(data)
    _remove_global_object(info.main_function, info)
    return
end

function get_exception_info()
    error = ""
    if VERSION < v"1.7"
        for (exc, bt) in Base.catch_stack()
            error = string(error, sprint(showerror, exc, bt))
        end
    else
        for (exc, bt) in current_exceptions()
            error = string(error, sprint(showerror, exc, bt))
        end
    end
    return error
end


Review comment (suggestion):
This is more compact?
```
lock(main_function.global_lock) do
    push!(main_function.global_objects, object)
end
```

Code after:
function set_stats_cardinality(bind_info::BindInfo, cardinality::UInt64, is_exact::Bool)
    duckdb_bind_set_cardinality(bind_info.handle, cardinality, is_exact)
    return
end

function add_result_column(bind_info::BindInfo, name::AbstractString, type::DataType)
    return add_result_column(bind_info, name, create_logical_type(type))
end

function add_result_column(bind_info::BindInfo, name::AbstractString, type::LogicalType)
    return duckdb_bind_add_result_column(bind_info.handle, name, type.handle)
end

function get_extra_data(bind_info::BindInfo)
    return bind_info.main_function.extra_data
end

function _add_global_object(main_function, object)
    begin
        lock(main_function.global_lock)
        try
            push!(main_function.global_objects, object)
        finally
            unlock(main_function.global_lock)
        end
    end
    return
end

function _remove_global_object(main_function, object)
    begin
        lock(main_function.global_lock)
        try
            delete!(main_function.global_objects, object)
        finally
            unlock(main_function.global_lock)
        end
    end
    return
end

function _table_bind_cleanup(data::Ptr{Cvoid})
    info::InfoWrapper = unsafe_pointer_to_objref(data)
    _remove_global_object(info.main_function, info)
    return
end

function get_exception_info()
    error = ""
    if VERSION < v"1.7"
        for (exc, bt) in Base.catch_stack()