PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Languages/IronPython/IronPython.Modules/_ctypes/INativeType.cs

http://github.com/IronLanguages/main
C# | 98 lines | 26 code | 10 blank | 62 comment | 0 complexity | 80980cafc35778c403ee84dd7f75c11c MD5 | raw file
Possible License(s): CPL-1.0, BSD-3-Clause, ISC, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Apache License, Version 2.0, please send an email to
  8. * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Apache License, Version 2.0.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. #if FEATURE_NATIVE
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Reflection.Emit;
  19. namespace IronPython.Modules {
  20. /// <summary>
  21. /// Provides support for interop with native code from Python code.
  22. /// </summary>
  23. public static partial class CTypes {
  24. /// <summary>
  25. /// Common functionality that all of the meta classes provide which is part of
  26. /// our implementation. This is used to implement the serialization/deserialization
  27. /// of values into/out of memory, emit the marshalling logic for call stubs, and
  28. /// provide common information (size/alignment) for the types.
  29. /// </summary>
  30. internal interface INativeType {
  31. /// <summary>
  32. /// Gets the native size of the type
  33. /// </summary>
  34. int Size {
  35. get;
  36. }
  37. /// <summary>
  38. /// Gets the required alignment for the type
  39. /// </summary>
  40. int Alignment {
  41. get;
  42. }
  43. /// <summary>
  44. /// Deserialized the value of this type from the given address at the given
  45. /// offset. Any new objects which are created will keep the provided
  46. /// MemoryHolder alive.
  47. ///
  48. /// raw determines if the cdata is returned or if the primitive value is
  49. /// returned. This is only applicable for subtypes of simple cdata types.
  50. /// </summary>
  51. object GetValue(MemoryHolder/*!*/ owner, object readingFrom, int offset, bool raw);
  52. /// <summary>
  53. /// Serializes the provided value into the specified address at the given
  54. /// offset.
  55. /// </summary>
  56. object SetValue(MemoryHolder/*!*/ address, int offset, object value);
  57. /// <summary>
  58. /// Gets the .NET type which is used when calling or returning the value
  59. /// from native code.
  60. /// </summary>
  61. Type/*!*/ GetNativeType();
  62. /// <summary>
  63. /// Gets the .NET type which the native type is converted into when going to Python
  64. /// code. This is usually int, BigInt, double, object, or a CData type.
  65. /// </summary>
  66. Type/*!*/ GetPythonType();
  67. /// <summary>
  68. /// Emits marshalling of an object from Python to native code. This produces the
  69. /// native type from the Python type.
  70. /// </summary>
  71. MarshalCleanup EmitMarshalling(ILGenerator/*!*/ method, LocalOrArg/*!*/ argIndex, List<object>/*!*/ constantPool, int constantPoolArgument);
  72. /// <summary>
  73. /// Emits marshalling from native code to Python code This produces the python type
  74. /// from the native type. This is used for return values and parameters
  75. /// to Python callable objects that are passed back out to native code.
  76. /// </summary>
  77. void EmitReverseMarshalling(ILGenerator/*!*/ method, LocalOrArg/*!*/ value, List<object>/*!*/ constantPool, int constantPoolArgument);
  78. /// <summary>
  79. /// Returns a string which describes the type. Used for _buffer_info implementation which
  80. /// only exists for testing purposes.
  81. /// </summary>
  82. string TypeFormat {
  83. get;
  84. }
  85. }
  86. }
  87. }
  88. #endif