本文整理汇总了C#中IronPython.Modules.MemoryHolder类的典型用法代码示例。如果您正苦于以下问题:C# MemoryHolder类的具体用法?C# MemoryHolder怎么用?C# MemoryHolder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemoryHolder类属于IronPython.Modules命名空间,在下文中一共展示了MemoryHolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MemoryHolder
/// <summary>
/// Creates a new MemoryHolder at the specified address which will keep alive the
/// parent memory holder.
/// </summary>
public MemoryHolder(IntPtr data, int size, MemoryHolder parent) {
GC.SuppressFinalize(this);
_data = data;
_parent = parent;
_objects = parent._objects;
_size = size;
}
示例2: __init__
public void __init__(object value) {
_memHolder = new MemoryHolder(Size);
NativeType.SetValue(_memHolder, 0, value);
if (IsString) {
_memHolder.AddObject("str", value);
}
}
示例3: Pointer
public Pointer(CData value) {
_object = value; // Keep alive the object, more to do here.
_memHolder = new MemoryHolder(IntPtr.Size);
_memHolder.WriteIntPtr(0, value._memHolder);
_memHolder.AddObject("1", value);
if (value._objects != null) {
_memHolder.AddObject("0", value._objects);
}
}
示例4: __init__
public void __init__(params object[] args) {
CheckAbstract();
INativeType nativeType = NativeType;
StructType st = (StructType)nativeType;
_memHolder = new MemoryHolder(nativeType.Size);
st.SetValueInternal(_memHolder, 0, args);
}
示例5: __init__
public void __init__(params object[] args) {
INativeType nativeType = NativeType;
_memHolder = new MemoryHolder(nativeType.Size);
if (args.Length > ((ArrayType)nativeType).Length) {
throw PythonOps.IndexError("too many arguments");
}
nativeType.SetValue(_memHolder, 0, args);
}
示例6: WriteIntPtr
public void WriteIntPtr(int offset, MemoryHolder address) {
Marshal.WriteIntPtr(_data, offset, address.UnsafeAddress);
GC.KeepAlive(this);
GC.KeepAlive(address);
}
示例7: NotImplementedException
object INativeType.GetValue(MemoryHolder owner, int offset, bool raw) {
throw new NotImplementedException("union get value");
}
示例8: WriteString
private void WriteString(MemoryHolder address, int offset, string str) {
SimpleType st = (SimpleType)_type;
if (str.Length < _length) {
str = str + '\x00';
}
if (st._type == SimpleTypeKind.Char) {
address.WriteAnsiString(offset, str);
} else {
address.WriteUnicodeString(offset, str);
}
}
示例9: switch
object INativeType.GetValue(MemoryHolder/*!*/ owner, object readingFrom, int offset, bool raw) {
object res;
switch (_type) {
case SimpleTypeKind.Boolean: res = owner.ReadByte(offset) != 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False; break;
case SimpleTypeKind.Char: res = new string((char)owner.ReadByte(offset), 1); break;
case SimpleTypeKind.SignedByte: res = GetIntReturn((int)(sbyte)owner.ReadByte(offset)); break;
case SimpleTypeKind.UnsignedByte: res = GetIntReturn((int)owner.ReadByte(offset)); break;
case SimpleTypeKind.SignedShort: res = GetIntReturn((int)owner.ReadInt16(offset)); break;
case SimpleTypeKind.WChar: res = new string((char)owner.ReadInt16(offset), 1); break;
case SimpleTypeKind.UnsignedShort: res = GetIntReturn((int)(ushort)owner.ReadInt16(offset)); break;
case SimpleTypeKind.VariantBool: res = owner.ReadInt16(offset) != 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False; break;
case SimpleTypeKind.SignedInt: res = GetIntReturn((int)owner.ReadInt32(offset)); break;
case SimpleTypeKind.UnsignedInt: res = GetIntReturn((uint)owner.ReadInt32(offset)); break;
case SimpleTypeKind.UnsignedLong: res = GetIntReturn((uint)owner.ReadInt32(offset)); break;
case SimpleTypeKind.SignedLong: res = GetIntReturn(owner.ReadInt32(offset)); break;
case SimpleTypeKind.Single: res = GetSingleReturn(owner.ReadInt32(offset)); break;
case SimpleTypeKind.Double: res = GetDoubleReturn(owner.ReadInt64(offset)); break;
case SimpleTypeKind.UnsignedLongLong: res = GetIntReturn((ulong)owner.ReadInt64(offset)); break;
case SimpleTypeKind.SignedLongLong: res = GetIntReturn(owner.ReadInt64(offset)); break;
case SimpleTypeKind.Object: res = GetObjectReturn(owner.ReadIntPtr(offset)); break;
case SimpleTypeKind.Pointer: res = owner.ReadIntPtr(offset).ToPython(); break;
case SimpleTypeKind.CharPointer: res = owner.ReadMemoryHolder(offset).ReadAnsiString(0); break;
case SimpleTypeKind.WCharPointer: res = owner.ReadMemoryHolder(offset).ReadUnicodeString(0); break;
default:
throw new InvalidOperationException();
}
if (!raw && IsSubClass) {
res = PythonCalls.Call(this, res);
}
return res;
}
示例10: SetBitsValue
/// <summary>
/// Called for fields which have been limited to a range of bits. Sets the
/// specified value into the bits for the field.
/// </summary>
private void SetBitsValue(MemoryHolder address, int baseOffset, object value) {
// get the value in the form of a ulong which can contain the biggest bitfield
ulong newBits;
if (value is int) {
newBits = (ulong)(int)value;
} else if (value is BigInteger) {
newBits = (ulong)(long)(BigInteger)value;
} else {
throw PythonOps.TypeErrorForTypeMismatch("int or long", value);
}
// do the same for the existing value
int offset = checked(_offset + baseOffset);
object curValue = _fieldType.GetValue(address, null, offset, false);
ulong valueBits;
if (curValue is int) {
valueBits = (ulong)(int)curValue;
} else {
valueBits = (ulong)(long)(BigInteger)curValue;
}
// get a mask for the bits this field owns
ulong targetBits = ((1UL << _bits) - 1) << _bitsOffset;
// clear the existing bits
valueBits &= ~targetBits;
// or in the new bits provided by the user
valueBits |= (newBits << _bitsOffset) & targetBits;
// and set the value
if (IsSignedType) {
if (_fieldType.Size <= 4) {
_fieldType.SetValue(address, offset, (int)(long)valueBits);
} else {
_fieldType.SetValue(address, offset, (BigInteger)(long)valueBits);
}
} else {
if (_fieldType.Size < 4) {
_fieldType.SetValue(address, offset, (int)valueBits);
} else {
_fieldType.SetValue(address, offset, (BigInteger)valueBits);
}
}
}
示例11: SetValue
internal void SetValue(MemoryHolder address, int baseOffset, object value) {
if (_bits == -1) {
object keepAlive = _fieldType.SetValue(address, baseOffset + _offset, value);
if (keepAlive != null) {
address.AddObject(_index.ToString(), keepAlive);
}
} else {
SetBitsValue(address, baseOffset, value);
}
}
示例12: checked
object INativeType.GetValue(MemoryHolder owner, int offset, bool raw) {
if (IsStringType) {
SimpleType st = (SimpleType)_type;
string str;
if (st._type == SimpleTypeKind.Char) {
str = owner.ReadAnsiString(offset, _length);
} else {
str = owner.ReadUnicodeString(offset, _length);
}
// remove any trailing nulls
for (int i = 0; i < str.Length; i++) {
if (str[i] == '\x00') {
return str.Substring(0, i);
}
}
return str;
}
object[] res = new object[_length];
for (int i = 0; i < res.Length; i++) {
res[i] = _type.GetValue(owner, checked(offset + _type.Size * i), raw);
}
return List.FromArrayNoCopy(res);
}
示例13: __init__
public void __init__(object value) {
_memHolder = new MemoryHolder(Size);
NativeType.SetValue(_memHolder, 0, value);
}
示例14: if
object INativeType.SetValue(MemoryHolder address, int offset, object value) {
Pointer ptr;
_Array array;
if (value == null) {
address.WriteIntPtr(offset, IntPtr.Zero);
} else if (value is int) {
address.WriteIntPtr(offset, new IntPtr((int)value));
} else if (value is BigInteger) {
address.WriteIntPtr(offset, new IntPtr((long)(BigInteger)value));
} else if ((ptr = value as Pointer) != null) {
address.WriteIntPtr(offset, ptr._memHolder.ReadMemoryHolder(0));
return PythonOps.MakeDictFromItems(ptr, "0", ptr._objects, "1");
} else if ((array = value as _Array) != null) {
address.WriteIntPtr(offset, array._memHolder);
return array;
} else {
throw PythonOps.TypeErrorForTypeMismatch(Name, value);
}
return null;
}
示例15: GetRawValue
internal string GetRawValue(MemoryHolder owner, int offset) {
Debug.Assert(IsStringType);
SimpleType st = (SimpleType)_type;
string str;
if (st._type == SimpleTypeKind.Char) {
str = owner.ReadAnsiString(offset, _length);
} else {
str = owner.ReadUnicodeString(offset, _length);
}
return str;
}