iso_c_generated_procs.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /* Implementation of the ISO_C_BINDING library helper generated functions.
  2. Copyright (C) 2007-2015 Free Software Foundation, Inc.
  3. Contributed by Christopher Rickett.
  4. This file is part of the GNU Fortran 95 runtime library (libgfortran).
  5. Libgfortran is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either
  8. version 3 of the License, or (at your option) any later version.
  9. Libgfortran is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #include "libgfortran.h"
  21. #include "iso_c_binding.h"
  22. /* TODO: This file needs to be finished so that a function is provided
  23. for all possible type/kind combinations! */
  24. #ifdef HAVE_GFC_INTEGER_1
  25. void ISO_C_BINDING_PREFIX (c_f_pointer_i1) (void *, gfc_array_void *,
  26. const array_t *);
  27. #endif
  28. #ifdef HAVE_GFC_INTEGER_2
  29. void ISO_C_BINDING_PREFIX (c_f_pointer_i2) (void *, gfc_array_void *,
  30. const array_t *);
  31. #endif
  32. #ifdef HAVE_GFC_INTEGER_4
  33. void ISO_C_BINDING_PREFIX (c_f_pointer_i4) (void *, gfc_array_void *,
  34. const array_t *);
  35. #endif
  36. #ifdef HAVE_GFC_INTEGER_8
  37. void ISO_C_BINDING_PREFIX (c_f_pointer_i8) (void *, gfc_array_void *,
  38. const array_t *);
  39. #endif
  40. #ifdef HAVE_GFC_INTEGER_16
  41. void ISO_C_BINDING_PREFIX (c_f_pointer_i16) (void *, gfc_array_void *,
  42. const array_t *);
  43. #endif
  44. #ifdef HAVE_GFC_REAL_4
  45. void ISO_C_BINDING_PREFIX (c_f_pointer_r4) (void *, gfc_array_void *,
  46. const array_t *);
  47. #endif
  48. #ifdef HAVE_GFC_REAL_8
  49. void ISO_C_BINDING_PREFIX (c_f_pointer_r8) (void *, gfc_array_void *,
  50. const array_t *);
  51. #endif
  52. #ifdef HAVE_GFC_REAL_10
  53. void ISO_C_BINDING_PREFIX (c_f_pointer_r10) (void *, gfc_array_void *,
  54. const array_t *);
  55. #endif
  56. #ifdef HAVE_GFC_REAL_16
  57. void ISO_C_BINDING_PREFIX (c_f_pointer_r16) (void *, gfc_array_void *,
  58. const array_t *);
  59. #endif
  60. #ifdef HAVE_GFC_COMPLEX_4
  61. void ISO_C_BINDING_PREFIX (c_f_pointer_c4) (void *, gfc_array_void *,
  62. const array_t *);
  63. #endif
  64. #ifdef HAVE_GFC_COMPLEX_8
  65. void ISO_C_BINDING_PREFIX (c_f_pointer_c8) (void *, gfc_array_void *,
  66. const array_t *);
  67. #endif
  68. #ifdef HAVE_GFC_COMPLEX_10
  69. void ISO_C_BINDING_PREFIX (c_f_pointer_c10) (void *, gfc_array_void *,
  70. const array_t *);
  71. #endif
  72. #ifdef HAVE_GFC_COMPLEX_16
  73. void ISO_C_BINDING_PREFIX (c_f_pointer_c16) (void *, gfc_array_void *,
  74. const array_t *);
  75. #endif
  76. #ifdef GFC_DEFAULT_CHAR
  77. void ISO_C_BINDING_PREFIX (c_f_pointer_s0) (void *, gfc_array_void *,
  78. const array_t *);
  79. #endif
  80. #ifdef HAVE_GFC_LOGICAL_1
  81. void ISO_C_BINDING_PREFIX (c_f_pointer_l1) (void *, gfc_array_void *,
  82. const array_t *);
  83. #endif
  84. #ifdef HAVE_GFC_LOGICAL_2
  85. void ISO_C_BINDING_PREFIX (c_f_pointer_l2) (void *, gfc_array_void *,
  86. const array_t *);
  87. #endif
  88. #ifdef HAVE_GFC_LOGICAL_4
  89. void ISO_C_BINDING_PREFIX (c_f_pointer_l4) (void *, gfc_array_void *,
  90. const array_t *);
  91. #endif
  92. #ifdef HAVE_GFC_LOGICAL_8
  93. void ISO_C_BINDING_PREFIX (c_f_pointer_l8) (void *, gfc_array_void *,
  94. const array_t *);
  95. #endif
  96. #ifdef HAVE_GFC_INTEGER_1
  97. /* Set the given Fortran pointer, 'f_ptr_out', to point to the given C
  98. address, 'c_ptr_in'. The Fortran pointer is of type integer and
  99. kind=1. The function c_f_pointer is used to set up the pointer
  100. descriptor. shape is a one-dimensional array of integers
  101. specifying the upper bounds of the array pointed to by the given C
  102. address, if applicable. 'shape' is an optional parameter in
  103. Fortran, so if the user does not provide it, it will come in here
  104. as NULL. */
  105. void
  106. ISO_C_BINDING_PREFIX (c_f_pointer_i1) (void *c_ptr_in,
  107. gfc_array_void *f_ptr_out,
  108. const array_t *shape)
  109. {
  110. /* Here we have an integer(kind=1). */
  111. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  112. (int) BT_INTEGER,
  113. (int) sizeof (GFC_INTEGER_1));
  114. }
  115. #endif
  116. #ifdef HAVE_GFC_INTEGER_2
  117. /* Set the given Fortran pointer, 'f_ptr_out', to point to the given C
  118. address, 'c_ptr_in'. The Fortran pointer is of type integer and
  119. kind=2. The function c_f_pointer is used to set up the pointer
  120. descriptor. shape is a one-dimensional array of integers
  121. specifying the upper bounds of the array pointed to by the given C
  122. address, if applicable. 'shape' is an optional parameter in
  123. Fortran, so if the user does not provide it, it will come in here
  124. as NULL. */
  125. void
  126. ISO_C_BINDING_PREFIX (c_f_pointer_i2) (void *c_ptr_in,
  127. gfc_array_void *f_ptr_out,
  128. const array_t *shape)
  129. {
  130. /* Here we have an integer(kind=2). */
  131. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  132. (int) BT_INTEGER,
  133. (int) sizeof (GFC_INTEGER_2));
  134. }
  135. #endif
  136. #ifdef HAVE_GFC_INTEGER_4
  137. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  138. address, c_ptr_in. The Fortran pointer is of type integer and
  139. kind=4. The function c_f_pointer is used to set up the pointer
  140. descriptor. */
  141. void
  142. ISO_C_BINDING_PREFIX (c_f_pointer_i4) (void *c_ptr_in,
  143. gfc_array_void *f_ptr_out,
  144. const array_t *shape)
  145. {
  146. /* Here we have an integer(kind=4). */
  147. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  148. (int) BT_INTEGER,
  149. (int) sizeof (GFC_INTEGER_4));
  150. }
  151. #endif
  152. #ifdef HAVE_GFC_INTEGER_8
  153. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  154. address, c_ptr_in. The Fortran pointer is of type integer and
  155. kind=8. The function c_f_pointer is used to set up the pointer
  156. descriptor. */
  157. void
  158. ISO_C_BINDING_PREFIX (c_f_pointer_i8) (void *c_ptr_in,
  159. gfc_array_void *f_ptr_out,
  160. const array_t *shape)
  161. {
  162. /* Here we have an integer(kind=8). */
  163. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  164. (int) BT_INTEGER,
  165. (int) sizeof (GFC_INTEGER_8));
  166. }
  167. #endif
  168. #ifdef HAVE_GFC_INTEGER_16
  169. /* Set the given Fortran pointer, 'f_ptr_out', to point to the given C
  170. address, 'c_ptr_in'. The Fortran pointer is of type integer and
  171. kind=16. The function c_f_pointer is used to set up the pointer
  172. descriptor. shape is a one-dimensional array of integers
  173. specifying the upper bounds of the array pointed to by the given C
  174. address, if applicable. 'shape' is an optional parameter in
  175. Fortran, so if the user does not provide it, it will come in here
  176. as NULL. */
  177. void
  178. ISO_C_BINDING_PREFIX (c_f_pointer_i16) (void *c_ptr_in,
  179. gfc_array_void *f_ptr_out,
  180. const array_t *shape)
  181. {
  182. /* Here we have an integer(kind=16). */
  183. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  184. (int) BT_INTEGER,
  185. (int) sizeof (GFC_INTEGER_16));
  186. }
  187. #endif
  188. #ifdef HAVE_GFC_REAL_4
  189. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  190. address, c_ptr_in. The Fortran pointer is of type real and
  191. kind=4. The function c_f_pointer is used to set up the pointer
  192. descriptor. */
  193. void
  194. ISO_C_BINDING_PREFIX (c_f_pointer_r4) (void *c_ptr_in,
  195. gfc_array_void *f_ptr_out,
  196. const array_t *shape)
  197. {
  198. /* Here we have an real(kind=4). */
  199. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  200. (int) BT_REAL,
  201. (int) sizeof (GFC_REAL_4));
  202. }
  203. #endif
  204. #ifdef HAVE_GFC_REAL_8
  205. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  206. address, c_ptr_in. The Fortran pointer is of type real and
  207. kind=8. The function c_f_pointer is used to set up the pointer
  208. descriptor. */
  209. void
  210. ISO_C_BINDING_PREFIX (c_f_pointer_r8) (void *c_ptr_in,
  211. gfc_array_void *f_ptr_out,
  212. const array_t *shape)
  213. {
  214. /* Here we have an real(kind=8). */
  215. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  216. (int) BT_REAL,
  217. (int) sizeof (GFC_REAL_8));
  218. }
  219. #endif
  220. #ifdef HAVE_GFC_REAL_10
  221. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  222. address, c_ptr_in. The Fortran pointer is of type real and
  223. kind=10. The function c_f_pointer is used to set up the pointer
  224. descriptor. */
  225. void
  226. ISO_C_BINDING_PREFIX (c_f_pointer_r10) (void *c_ptr_in,
  227. gfc_array_void *f_ptr_out,
  228. const array_t *shape)
  229. {
  230. /* Here we have an real(kind=10). */
  231. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  232. (int) BT_REAL,
  233. (int) sizeof (GFC_REAL_10));
  234. }
  235. #endif
  236. #ifdef HAVE_GFC_REAL_16
  237. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  238. address, c_ptr_in. The Fortran pointer is of type real and
  239. kind=16. The function c_f_pointer is used to set up the pointer
  240. descriptor. */
  241. void
  242. ISO_C_BINDING_PREFIX (c_f_pointer_r16) (void *c_ptr_in,
  243. gfc_array_void *f_ptr_out,
  244. const array_t *shape)
  245. {
  246. /* Here we have an real(kind=16). */
  247. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  248. (int) BT_REAL,
  249. (int) sizeof (GFC_REAL_16));
  250. }
  251. #endif
  252. #ifdef HAVE_GFC_COMPLEX_4
  253. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  254. address, c_ptr_in. The Fortran pointer is of type complex and
  255. kind=4. The function c_f_pointer is used to set up the pointer
  256. descriptor. */
  257. void
  258. ISO_C_BINDING_PREFIX (c_f_pointer_c4) (void *c_ptr_in,
  259. gfc_array_void *f_ptr_out,
  260. const array_t *shape)
  261. {
  262. /* Here we have an complex(kind=4). */
  263. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  264. (int) BT_COMPLEX,
  265. (int) sizeof (GFC_COMPLEX_4));
  266. }
  267. #endif
  268. #ifdef HAVE_GFC_COMPLEX_8
  269. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  270. address, c_ptr_in. The Fortran pointer is of type complex and
  271. kind=8. The function c_f_pointer is used to set up the pointer
  272. descriptor. */
  273. void
  274. ISO_C_BINDING_PREFIX (c_f_pointer_c8) (void *c_ptr_in,
  275. gfc_array_void *f_ptr_out,
  276. const array_t *shape)
  277. {
  278. /* Here we have an complex(kind=8). */
  279. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  280. (int) BT_COMPLEX,
  281. (int) sizeof (GFC_COMPLEX_8));
  282. }
  283. #endif
  284. #ifdef HAVE_GFC_COMPLEX_10
  285. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  286. address, c_ptr_in. The Fortran pointer is of type complex and
  287. kind=10. The function c_f_pointer is used to set up the pointer
  288. descriptor. */
  289. void
  290. ISO_C_BINDING_PREFIX (c_f_pointer_c10) (void *c_ptr_in,
  291. gfc_array_void *f_ptr_out,
  292. const array_t *shape)
  293. {
  294. /* Here we have an complex(kind=10). */
  295. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  296. (int) BT_COMPLEX,
  297. (int) sizeof (GFC_COMPLEX_10));
  298. }
  299. #endif
  300. #ifdef HAVE_GFC_COMPLEX_16
  301. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  302. address, c_ptr_in. The Fortran pointer is of type complex and
  303. kind=16. The function c_f_pointer is used to set up the pointer
  304. descriptor. */
  305. void
  306. ISO_C_BINDING_PREFIX (c_f_pointer_c16) (void *c_ptr_in,
  307. gfc_array_void *f_ptr_out,
  308. const array_t *shape)
  309. {
  310. /* Here we have an complex(kind=16). */
  311. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  312. (int) BT_COMPLEX,
  313. (int) sizeof (GFC_COMPLEX_16));
  314. }
  315. #endif
  316. #ifdef GFC_DEFAULT_CHAR
  317. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  318. address, c_ptr_in. The Fortran pointer is of type character. */
  319. void
  320. ISO_C_BINDING_PREFIX (c_f_pointer_s0) (void *c_ptr_in,
  321. gfc_array_void *f_ptr_out,
  322. const array_t *shape)
  323. {
  324. /* Here we have a character string of len=1. */
  325. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  326. (int) BT_CHARACTER,
  327. (int) sizeof (char));
  328. }
  329. #endif
  330. #ifdef HAVE_GFC_LOGICAL_1
  331. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  332. address, c_ptr_in. The Fortran pointer is of type logical, kind=1. */
  333. void
  334. ISO_C_BINDING_PREFIX (c_f_pointer_l1) (void *c_ptr_in,
  335. gfc_array_void *f_ptr_out,
  336. const array_t *shape)
  337. {
  338. /* Here we have a logical of kind=1. */
  339. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  340. (int) BT_LOGICAL,
  341. (int) sizeof (GFC_LOGICAL_1));
  342. }
  343. #endif
  344. #ifdef HAVE_GFC_LOGICAL_2
  345. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  346. address, c_ptr_in. The Fortran pointer is of type logical, kind=2. */
  347. void
  348. ISO_C_BINDING_PREFIX (c_f_pointer_l2) (void *c_ptr_in,
  349. gfc_array_void *f_ptr_out,
  350. const array_t *shape)
  351. {
  352. /* Here we have a logical of kind=2. */
  353. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  354. (int) BT_LOGICAL,
  355. (int) sizeof (GFC_LOGICAL_2));
  356. }
  357. #endif
  358. #ifdef HAVE_GFC_LOGICAL_4
  359. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  360. address, c_ptr_in. The Fortran pointer is of type logical, kind=4. */
  361. void
  362. ISO_C_BINDING_PREFIX (c_f_pointer_l4) (void *c_ptr_in,
  363. gfc_array_void *f_ptr_out,
  364. const array_t *shape)
  365. {
  366. /* Here we have a logical of kind=4. */
  367. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  368. (int) BT_LOGICAL,
  369. (int) sizeof (GFC_LOGICAL_4));
  370. }
  371. #endif
  372. #ifdef HAVE_GFC_LOGICAL_8
  373. /* Set the given Fortran pointer, f_ptr_out, to point to the given C
  374. address, c_ptr_in. The Fortran pointer is of type logical, kind=8. */
  375. void
  376. ISO_C_BINDING_PREFIX (c_f_pointer_l8) (void *c_ptr_in,
  377. gfc_array_void *f_ptr_out,
  378. const array_t *shape)
  379. {
  380. /* Here we have a logical of kind=8. */
  381. ISO_C_BINDING_PREFIX (c_f_pointer) (c_ptr_in, f_ptr_out, shape,
  382. (int) BT_LOGICAL,
  383. (int) sizeof (GFC_LOGICAL_8));
  384. }
  385. #endif