Exemplo n.º 1
0
uThrowable::uThrowable(::g::Uno::Exception* exception, const char* func, int line)
    : Exception(exception)
    , Function(func)
    , Line(line)
{
    uRetain(Exception);
}
Exemplo n.º 2
0
uType* uNewMethodType(uType* parent, size_t index)
{
    U_ASSERT(parent && index < 0xffff);
    uTypeOptions options;
    size_t count = index + 1;
    options.GenericCount = parent->GenericCount + count;
    options.PrecalcCount = parent->PrecalcCount;
    options.ObjectSize = 0;
    options.TypeSize = sizeof(uGenericType);
    uGenericType* type =
        (uGenericType*)uNewType(
            uTypeTypeGeneric,
            (Xli::String(parent->FullName) + "``" + (int)count).CopyPtr(), // Leak
            options,
            false);
    type->Base = parent;
    type->GenericIndex = parent->GenericCount;
    uRetain(type);

    for (size_t i = 0; i < parent->GenericCount; i++)
        type->Generics[i] = parent->Generics[i];
    for (size_t i = parent->GenericCount; i < type->GenericCount; i++)
        type->Generics[i] = uGetGenericType(i);

    if (!parent->State)
        _RuntimeTypes->Add(type);
    else
        type->Build();

    return type;
}
Exemplo n.º 3
0
uThrowable::uThrowable(const uThrowable& copy)
    : Exception(copy.Exception)
    , Function(copy.Function)
    , Line(copy.Line)
{
    uRetain(Exception);
}
Exemplo n.º 4
0
uArray* uArray::New(uType* type, int length, const void* optionalData)
{
    U_ASSERT(type && type->Type == uTypeTypeArray);
    uArrayType* arrayType = (uArrayType*)type;
    uType* elementType = arrayType->ElementType;
    size_t elementSize = elementType->ValueSize;

    uArray* array = (uArray*)uNew(type, sizeof(uArray) + elementSize * length);
    array->_ptr = (uint8_t*)array + sizeof(uArray);
    array->_length = length;

    if (optionalData)
    {
        memcpy(array->Ptr(), optionalData, elementSize * length);

        if (U_IS_OBJECT(elementType))
            for (int i = 0; i < length; i++)
                uRetain(((uObject**)array->Ptr())[i]);
        else if (elementType->Flags & uTypeFlagsRetainStruct)
            for (int i = 0; i < length; i++)
                uRetainStruct(elementType, (uint8_t*)array->Ptr() + elementType->ValueSize * i);
    }

    return array;
}
Exemplo n.º 5
0
void uRetainStruct(uType* type, void* address)
{
#if DEBUG_ARC >= 4
    Xli::Error->WriteFormat("retain %s [struct] (%d bytes)%s\n", type->FullName, type->ValueSize, uGetCaller().Ptr());
#endif
    for (size_t i = 0; i < type->Refs.StrongCount; i++)
        uRetain(*(uObject**)((uint8_t*)address + type->Refs.Strong[i].Value));
}
// public static Android.Base.Primitives.ujobject Box(object unoObject) [static] :57
jobject JavaUnoObject::Box(uObject* unoObject)
{
    uStackFrame __("Uno.Compiler.ExportTargetInterop.Foreign.Android.JavaUnoObject", "Box(object)");
    JavaUnoObject::EnsureInitialized();
    uRetain(unoObject);
    int64_t longPtr = (int64_t)unoObject;
    jobject boxed = ::g::Android::Base::JNI::NewObject1(JavaUnoObject::_unoObjectClass(), JavaUnoObject::_unoObjectConstructor(), ::g::Android::Base::Primitives::ujvalue::op_Implicit17(longPtr));
    ::g::Android::Base::JNI::CheckException();
    return boxed;
}
Exemplo n.º 7
0
uString* uString::Const(const char* mutf8)
{
    uString* string;
    Xli::MutexLock lock(_Mutex);
    if (!_StringConsts->TryGetValue(mutf8, string))
    {
        uRetain(string = Utf8(mutf8));
        (*_StringConsts)[mutf8] = string; // FIXME: Got exception when using HashMap::Add()
    }

    return string;
}
Exemplo n.º 8
0
uString* uString::Const(const char* mutf8)
{
    uString* string;
    Xli::String key(mutf8);
    Xli::MutexLock lock(_Mutex);
    if (!_StringConsts->TryGetValue(key, string))
    {
        uRetain(string = Utf8(key.Ptr(), (size_t)key.Length()));
        (*_StringConsts)[key] = string;
    }

    return string;
}
Exemplo n.º 9
0
void uArray::MarshalPtr(int index, const void* value, size_t size)
{
    uType* type = ((uArrayType*)__type)->ElementType;
    void* item = (uint8_t*)_ptr + type->ValueSize * index;

    if (type->ValueSize == size)
    {
        INLINE_MEMCPY(item, value, size);

        if (U_IS_OBJECT(type))
            uRetain(*(uObject**)item);
    }
    else
    {
        // Cast value back to correct type (or throw exception)
        // * small ints are promoted to 'int' when passed through '...'
        // * floats are promoted to 'double' when passed through '...'
        switch (size)
        {
        case sizeof(int):
            switch (type->ValueSize)
            {
            case 1:
                if (type == ::g::Uno::Byte_typeof())
                    return *(uint8_t*)item = (uint8_t)*(int*)value, void();
                else if (type == ::g::Uno::SByte_typeof())
                    return *(int8_t*)item = (int8_t)*(int*)value, void();
                else if (type == ::g::Uno::Bool_typeof())
                    return *(bool*)item = *(int*)value != 0, void();
                break;

            case 2:
                if (type == ::g::Uno::Short_typeof())
                    return *(int16_t*)item = (int16_t)*(int*)value, void();
                else if (type == ::g::Uno::UShort_typeof())
                    return *(uint16_t*)item = (uint16_t)*(int*)value, void();
                else if (type == ::g::Uno::Char_typeof())
                    return *(uChar*)item = (uChar)*(int*)value, void();
                break;
            }

        case sizeof(double):
            if (type == ::g::Uno::Float_typeof())
                return *(float*)item = (float)*(double*)value, void();
            break;
        }

        U_THROW_ICE();
    }
}
Exemplo n.º 10
0
static uObject* uLoadWeak_inner(uWeakObject* weak)
{
    if (weak->ZombieState == uWeakObject::Zombie)
    {
        if (!weak->ZombieStateIntercept(uWeakStateIntercept::OnLoad, weak->Object))
        {
            weak->ZombieState = uWeakObject::Dead;
            weak->Object = NULL;
            return NULL;
        }

        weak->ZombieState = uWeakObject::Infected;
    }

    uRetain(weak->Object);
    return weak->Object;
}
Exemplo n.º 11
0
void uArray::Copy(const uArray* srcArray, int srcIndex, uArray* dstArray, int dstIndex, int length)
{
    if (!srcArray || !dstArray)
        U_THROW_NRE();
    if (srcArray->GetType() != dstArray->GetType())
        U_THROW_ICE();
    if (length < 0 ||
        srcIndex < 0 || srcIndex + length > srcArray->Length() ||
        dstIndex < 0 || dstIndex + length > dstArray->Length())
        U_THROW_IOORE();

    uType* type = ((uArrayType*)srcArray->GetType())->ElementType;
    size_t size = type->ValueSize;
    uint8_t* dst = (uint8_t*)dstArray->Ptr() + size * dstIndex;
    const uint8_t* src = (const uint8_t*)srcArray->Ptr() + size * srcIndex;

    switch (type->Type)
    {
    case uTypeTypeEnum:
        memcpy(dst, src, size * length);
        break;

    case uTypeTypeStruct:
        if (type->Flags & uTypeFlagsRetainStruct)
        {
            for (int i = 0; i < length; i++)
                uAutoReleaseStruct(type, dst + i * size);
            memcpy(dst, src, size * length);
            for (int i = 0; i < length; i++)
                uRetainStruct(type, dst + i * size);
        }
        else
            memcpy(dst, src, size * length);
        break;

    default:
        for (int i = 0; i < length; i++)
            uAutoRelease((uObject*)dst + i);
        memcpy(dst, src, size * length);
        for (int i = 0; i < length; i++)
            uRetain((uObject*)dst + i);
        break;
    }
}
Exemplo n.º 12
0
static uType* uGetGenericType(size_t index)
{
    for (size_t i = _GenericTypes->Length(); i <= index; i++)
    {
        uTypeOptions options;
        options.TypeSize = sizeof(uGenericType);
        uGenericType* type =
            (uGenericType*)uNewType(
                uTypeTypeGeneric,
                (Xli::String("T") + (int)index).CopyPtr(), // Leak
                options,
                false);
        type->GenericIndex = index;
        _GenericTypes->Add(type);
        uRetain(type);
    }

    return (*_GenericTypes)[(int)index];
}
Exemplo n.º 13
0
uByRefType* uType::ByRef()
{
    if (_byRef)
        return _byRef;

    Xli::MutexLock lock(_Mutex);
    uTypeOptions options;
    options.TypeSize = sizeof(uByRefType);
    options.ObjectSize = sizeof(uObject);
    options.ValueSize = sizeof(void*);
    uByRefType* type =
        (uByRefType*)uNewType(
            uTypeTypeByRef,
            (Xli::String(FullName) + "&").CopyPtr(), // Leak
            options);
    type->ValueType = this;

    uRetain(type);
    return _byRef = type;
}
Exemplo n.º 14
0
static uType* uGetParameterization(const uTypeKey& key)
{
    Xli::MutexLock lock(_Mutex);

    uType* result;
    if (!_TypeMap->TryGetValue(key, result))
    {
        uTypeOptions options;
        uType* def = key.Definition;
        options.FieldCount = def->FieldCount;
        options.GenericCount = def->GenericCount;
        options.MethodTypeCount = def->MethodTypeCount;
        options.InterfaceCount = def->InterfaceCount;
        options.PrecalcCount = def->PrecalcCount;
        options.ObjectSize = def->ObjectSize;
        options.TypeSize = def->TypeSize;
        options.ValueSize = def->ValueSize;
        result = uNewType(def->Type, def->FullName, options, false);
        result->Definition = def;

        if (result->Type == uTypeTypeGeneric)
            ((uGenericType*)result)->GenericIndex = ((uGenericType*)def)->GenericIndex;
        for (size_t i = 0; i < result->GenericCount; i++)
            result->Generics[i] = key.Arguments[i];
        for (size_t i = 0; i < result->MethodTypeCount; i++)
        {
            result->MethodTypes[i] = uNewMethodType(result, i);
            result->MethodTypes[i]->Definition = def->MethodTypes[i]->Definition;
        }

        _TypeMap->Add(key, result);
        uRetain(result);

        if (!def->State)
            _RuntimeTypes->Add(result);
        else
            result->Build();
    }

    return result;
}
Exemplo n.º 15
0
uArrayType* uType::Array()
{
    if (_array)
        return _array;

    Xli::MutexLock lock(_Mutex);
    uTypeOptions options;
    options.TypeSize = sizeof(uArrayType);
    options.ObjectSize = sizeof(uArray);
    options.ValueSize = sizeof(uArray*);
    uArrayType* type =
        (uArrayType*)uNewType(
            uTypeTypeArray,
            (Xli::String(FullName) + "[]").CopyPtr(), // Leak
            options);
    type->SetBase(_ObjectTypePtr);
    type->ElementType = this;

    uRetain(type);
    return _array = type;
}
Exemplo n.º 16
0
void uStoreStrong(uObject** address, uObject* object)
{
    uAutoRelease(*address);
    uRetain(*address = object);
}