pr1172638.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* Area: ffi_call
  2. Purpose: Reproduce bug found in python ctypes
  3. Limitations: none.
  4. PR: Fedora 1174037 */
  5. /* { dg-do run } */
  6. #include "ffitest.h"
  7. typedef struct {
  8. long x;
  9. long y;
  10. } POINT;
  11. typedef struct {
  12. long left;
  13. long top;
  14. long right;
  15. long bottom;
  16. } RECT;
  17. static RECT ABI_ATTR pr_test(int i __UNUSED__, RECT ar __UNUSED__,
  18. RECT* br __UNUSED__, POINT cp __UNUSED__,
  19. RECT dr __UNUSED__, RECT *er __UNUSED__,
  20. POINT fp, RECT gr __UNUSED__)
  21. {
  22. RECT result;
  23. result.left = fp.x;
  24. result.right = fp.y;
  25. result.top = fp.x;
  26. result.bottom = fp.y;
  27. return result;
  28. }
  29. int main (void)
  30. {
  31. ffi_cif cif;
  32. ffi_type *args[MAX_ARGS];
  33. void *values[MAX_ARGS];
  34. ffi_type point_type, rect_type;
  35. ffi_type *point_type_elements[3];
  36. ffi_type *rect_type_elements[5];
  37. int i;
  38. POINT cp, fp;
  39. RECT ar, br, dr, er, gr;
  40. RECT *p1, *p2;
  41. /* This is a hack to get a properly aligned result buffer */
  42. RECT *rect_result =
  43. (RECT *) malloc (sizeof(RECT));
  44. point_type.size = 0;
  45. point_type.alignment = 0;
  46. point_type.type = FFI_TYPE_STRUCT;
  47. point_type.elements = point_type_elements;
  48. point_type_elements[0] = &ffi_type_slong;
  49. point_type_elements[1] = &ffi_type_slong;
  50. point_type_elements[2] = NULL;
  51. rect_type.size = 0;
  52. rect_type.alignment = 0;
  53. rect_type.type = FFI_TYPE_STRUCT;
  54. rect_type.elements = rect_type_elements;
  55. rect_type_elements[0] = &ffi_type_slong;
  56. rect_type_elements[1] = &ffi_type_slong;
  57. rect_type_elements[2] = &ffi_type_slong;
  58. rect_type_elements[3] = &ffi_type_slong;
  59. rect_type_elements[4] = NULL;
  60. args[0] = &ffi_type_sint;
  61. args[1] = &rect_type;
  62. args[2] = &ffi_type_pointer;
  63. args[3] = &point_type;
  64. args[4] = &rect_type;
  65. args[5] = &ffi_type_pointer;
  66. args[6] = &point_type;
  67. args[7] = &rect_type;
  68. /* Initialize the cif */
  69. CHECK(ffi_prep_cif(&cif, ABI_NUM, 8, &rect_type, args) == FFI_OK);
  70. i = 1;
  71. ar.left = 2;
  72. ar.right = 3;
  73. ar.top = 4;
  74. ar.bottom = 5;
  75. br.left = 6;
  76. br.right = 7;
  77. br.top = 8;
  78. br.bottom = 9;
  79. cp.x = 10;
  80. cp.y = 11;
  81. dr.left = 12;
  82. dr.right = 13;
  83. dr.top = 14;
  84. dr.bottom = 15;
  85. er.left = 16;
  86. er.right = 17;
  87. er.top = 18;
  88. er.bottom = 19;
  89. fp.x = 20;
  90. fp.y = 21;
  91. gr.left = 22;
  92. gr.right = 23;
  93. gr.top = 24;
  94. gr.bottom = 25;
  95. values[0] = &i;
  96. values[1] = &ar;
  97. p1 = &br;
  98. values[2] = &p1;
  99. values[3] = &cp;
  100. values[4] = &dr;
  101. p2 = &er;
  102. values[5] = &p2;
  103. values[6] = &fp;
  104. values[7] = &gr;
  105. ffi_call (&cif, FFI_FN(pr_test), rect_result, values);
  106. CHECK(rect_result->top == 20);
  107. free (rect_result);
  108. exit(0);
  109. }