C# Class IronPython.Modules.CTypes

Provides support for interop with native code from Python code.
Show file Open project: jschementi/iron Class Usage Examples

Private Properties

Property Type Description
Cast System.IntPtr
CheckBits int
EmitCDataCreation void
EnsureRefCountTable void
GetFieldInfo void
GetFieldsList IList
GetFunctionType CFuncPtrType
GetHandleFromObject System.IntPtr
GetMarshalTypeFromSize System.Type
IsPointer bool
MakeArrayType System.Reflection.Emit.ArrayType
MakePointer System.Reflection.Emit.PointerType
PerformModuleReload void
StringAt System.IntPtr
StructureCannotContainSelf System.Exception
ValidateArraySizes void
ValidateArraySizes void
ValidateArraySizes void
WStringAt System.IntPtr

Public Methods

Method Description
@sizeof ( IronPython.Runtime.Types.PythonType type ) : int
@sizeof ( object instance ) : int
CopyComPointer ( object src, object dest ) : int
DeleteCharArrayValue ( _Array arr, object value ) : void
DeleteWCharArrayRaw ( _Array arr ) : object
DeleteWCharArrayValue ( _Array arr ) : object
FormatError ( ) : string
FormatError ( int errorCode ) : string
FreeLibrary ( BigInteger handle ) : void
FreeLibrary ( IntPtr handle ) : void
FreeLibrary ( int handle ) : void
GetCharArrayValue ( _Array arr ) : object
GetWCharArrayRaw ( _Array arr ) : object
GetWCharArrayValue ( _Array arr ) : object
LoadLibrary ( string library, [ mode ) : object
POINTER ( CodeContext context, IronPython.Runtime.Types.PythonType type ) : IronPython.Runtime.Types.PythonType

Returns a new type which represents a pointer given the existing type.

POINTER ( CodeContext context, [ name ) : IronPython.Runtime.Types.PythonType
PyObj_FromPtr ( IntPtr address ) : object

Converts an address acquired from PyObj_FromPtr or that has been marshaled as type 'O' back into an object.

PyObj_ToPtr ( object obj ) : IntPtr

Converts an object into an opaque address which can be handed out to managed code.

Py_DECREF ( object key ) : void

Decreases the ref count on an object which has been increased with Py_INCREF.

Py_INCREF ( object key ) : void

Increases the ref count on an object ensuring that it will not be collected.

SetCharArrayValue ( _Array arr, object value ) : void
SetWCharArrayRaw ( _Array arr, object value ) : void
SetWCharArrayValue ( _Array arr, object value ) : void
_buffer_info ( CData data ) : PythonTuple
_check_HRESULT ( int hresult ) : void
_unpickle ( ) : void
addressof ( CData data ) : object

returns address of C instance internal buffer. It is the callers responsibility to ensure that the provided instance will stay alive if memory in the resulting address is to be used later.

alignment ( IronPython.Runtime.Types.PythonType type ) : int

Gets the required alignment of the given type.

alignment ( object o ) : int

Gets the required alignment of an object.

byref ( CData instance, [ offset ) : object
call_cdeclfunction ( CodeContext context, BigInteger address, PythonTuple args ) : object
call_cdeclfunction ( CodeContext context, IntPtr address, PythonTuple args ) : object
call_cdeclfunction ( CodeContext context, int address, PythonTuple args ) : object
call_commethod ( ) : void
call_function ( CodeContext context, BigInteger address, PythonTuple args ) : object
call_function ( CodeContext context, IntPtr address, PythonTuple args ) : object
call_function ( CodeContext context, int address, PythonTuple args ) : object
dlopen ( string library, [ mode ) : object
get_errno ( ) : int
get_last_error ( ) : int
pointer ( CodeContext context, CData data ) : Pointer

Returns a pointer instance for the given CData

resize ( CData obj, int newSize ) : void
set_conversion_mode ( CodeContext context, string encoding, string errors ) : PythonTuple
set_errno ( ) : void
set_last_error ( int errorCode ) : void

Private Methods

Method Description
Cast ( IntPtr data, IntPtr obj, IntPtr type ) : IntPtr

Implementation of our cast function. data is marshalled as a void* so it ends up as an address. obj and type are marshalled as an object so we need to unmarshal them.

CheckBits ( INativeType cdata, PythonTuple pt ) : int

Verifies that the provided bit field settings are valid for this type.

EmitCDataCreation ( INativeType type, ILGenerator method, List constantPool, int constantPoolArgument ) : void

Emits the marshalling code to create a CData object for reverse marshalling.

EnsureRefCountTable ( ) : void
GetFieldInfo ( INativeType type, object o, string &fieldName, INativeType &cdata, int &bitCount ) : void

Shared helper between struct and union for getting field info and validating it.

GetFieldsList ( object fields ) : IList

Shared helper to get the _fields_ list for struct/union and validate it.

GetFunctionType ( CodeContext context, int flags ) : CFuncPtrType
GetHandleFromObject ( object dll, string errorMsg ) : IntPtr
GetMarshalTypeFromSize ( int size ) : Type

Given a specific size returns a .NET type of the equivalent size that we can use when marshalling these values across calls.

IsPointer ( IronPython.Runtime.Types.PythonType pt ) : bool
MakeArrayType ( IronPython.Runtime.Types.PythonType type, int count ) : ArrayType
MakePointer ( CodeContext context, string name, PythonDictionary dict ) : PointerType
PerformModuleReload ( IronPython.Runtime.PythonContext context, PythonDictionary dict ) : void
StringAt ( IntPtr src, int len ) : IntPtr

Helper function for translating from memset to NT's FillMemory API.

StructureCannotContainSelf ( ) : Exception
ValidateArraySizes ( IronPython.Modules.ArrayModule array, int offset, int size ) : void
ValidateArraySizes ( System.Bytes bytes, int offset, int size ) : void
ValidateArraySizes ( int arraySize, int offset, int size ) : void
WStringAt ( IntPtr src, int len ) : IntPtr

Helper function for translating from memset to NT's FillMemory API.

Method Details

@sizeof() public static method

public static @sizeof ( IronPython.Runtime.Types.PythonType type ) : int
type IronPython.Runtime.Types.PythonType
return int

@sizeof() public static method

public static @sizeof ( object instance ) : int
instance object
return int

CopyComPointer() public static method

public static CopyComPointer ( object src, object dest ) : int
src object
dest object
return int

DeleteCharArrayValue() public static method

public static DeleteCharArrayValue ( _Array arr, object value ) : void
arr _Array
value object
return void

DeleteWCharArrayRaw() public static method

public static DeleteWCharArrayRaw ( _Array arr ) : object
arr _Array
return object

DeleteWCharArrayValue() public static method

public static DeleteWCharArrayValue ( _Array arr ) : object
arr _Array
return object

FormatError() public static method

public static FormatError ( ) : string
return string

FormatError() public static method

public static FormatError ( int errorCode ) : string
errorCode int
return string

FreeLibrary() public static method

public static FreeLibrary ( BigInteger handle ) : void
handle Microsoft.Scripting.Math.BigInteger
return void

FreeLibrary() public static method

public static FreeLibrary ( IntPtr handle ) : void
handle System.IntPtr
return void

FreeLibrary() public static method

public static FreeLibrary ( int handle ) : void
handle int
return void

GetCharArrayValue() public static method

public static GetCharArrayValue ( _Array arr ) : object
arr _Array
return object

GetWCharArrayRaw() public static method

public static GetWCharArrayRaw ( _Array arr ) : object
arr _Array
return object

GetWCharArrayValue() public static method

public static GetWCharArrayValue ( _Array arr ) : object
arr _Array
return object

LoadLibrary() public static method

public static LoadLibrary ( string library, [ mode ) : object
library string
mode [
return object

POINTER() public static method

Returns a new type which represents a pointer given the existing type.
public static POINTER ( CodeContext context, IronPython.Runtime.Types.PythonType type ) : IronPython.Runtime.Types.PythonType
context CodeContext
type IronPython.Runtime.Types.PythonType
return IronPython.Runtime.Types.PythonType

POINTER() public static method

public static POINTER ( CodeContext context, [ name ) : IronPython.Runtime.Types.PythonType
context CodeContext
name [
return IronPython.Runtime.Types.PythonType

PyObj_FromPtr() public static method

Converts an address acquired from PyObj_FromPtr or that has been marshaled as type 'O' back into an object.
public static PyObj_FromPtr ( IntPtr address ) : object
address System.IntPtr
return object

PyObj_ToPtr() public static method

Converts an object into an opaque address which can be handed out to managed code.
public static PyObj_ToPtr ( object obj ) : IntPtr
obj object
return System.IntPtr

Py_DECREF() public static method

Decreases the ref count on an object which has been increased with Py_INCREF.
public static Py_DECREF ( object key ) : void
key object
return void

Py_INCREF() public static method

Increases the ref count on an object ensuring that it will not be collected.
public static Py_INCREF ( object key ) : void
key object
return void

SetCharArrayValue() public static method

public static SetCharArrayValue ( _Array arr, object value ) : void
arr _Array
value object
return void

SetWCharArrayRaw() public static method

public static SetWCharArrayRaw ( _Array arr, object value ) : void
arr _Array
value object
return void

SetWCharArrayValue() public static method

public static SetWCharArrayValue ( _Array arr, object value ) : void
arr _Array
value object
return void

_buffer_info() public static method

public static _buffer_info ( CData data ) : PythonTuple
data CData
return PythonTuple

_check_HRESULT() public static method

public static _check_HRESULT ( int hresult ) : void
hresult int
return void

_unpickle() public static method

public static _unpickle ( ) : void
return void

addressof() public static method

returns address of C instance internal buffer. It is the callers responsibility to ensure that the provided instance will stay alive if memory in the resulting address is to be used later.
public static addressof ( CData data ) : object
data CData
return object

alignment() public static method

Gets the required alignment of the given type.
public static alignment ( IronPython.Runtime.Types.PythonType type ) : int
type IronPython.Runtime.Types.PythonType
return int

alignment() public static method

Gets the required alignment of an object.
public static alignment ( object o ) : int
o object
return int

byref() public static method

public static byref ( CData instance, [ offset ) : object
instance CData
offset [
return object

call_cdeclfunction() public static method

public static call_cdeclfunction ( CodeContext context, BigInteger address, PythonTuple args ) : object
context CodeContext
address Microsoft.Scripting.Math.BigInteger
args PythonTuple
return object

call_cdeclfunction() public static method

public static call_cdeclfunction ( CodeContext context, IntPtr address, PythonTuple args ) : object
context CodeContext
address System.IntPtr
args PythonTuple
return object

call_cdeclfunction() public static method

public static call_cdeclfunction ( CodeContext context, int address, PythonTuple args ) : object
context CodeContext
address int
args PythonTuple
return object

call_commethod() public static method

public static call_commethod ( ) : void
return void

call_function() public static method

public static call_function ( CodeContext context, BigInteger address, PythonTuple args ) : object
context CodeContext
address Microsoft.Scripting.Math.BigInteger
args PythonTuple
return object

call_function() public static method

public static call_function ( CodeContext context, IntPtr address, PythonTuple args ) : object
context CodeContext
address System.IntPtr
args PythonTuple
return object

call_function() public static method

public static call_function ( CodeContext context, int address, PythonTuple args ) : object
context CodeContext
address int
args PythonTuple
return object

dlopen() public static method

public static dlopen ( string library, [ mode ) : object
library string
mode [
return object

get_errno() public static method

public static get_errno ( ) : int
return int

get_last_error() public static method

public static get_last_error ( ) : int
return int

pointer() public static method

Returns a pointer instance for the given CData
public static pointer ( CodeContext context, CData data ) : Pointer
context CodeContext
data CData
return System.Reflection.Pointer

resize() public static method

public static resize ( CData obj, int newSize ) : void
obj CData
newSize int
return void

set_conversion_mode() public static method

public static set_conversion_mode ( CodeContext context, string encoding, string errors ) : PythonTuple
context CodeContext
encoding string
errors string
return PythonTuple

set_errno() public static method

public static set_errno ( ) : void
return void

set_last_error() public static method

public static set_last_error ( int errorCode ) : void
errorCode int
return void