cfgexpand.c (dump_stack_var_partition): Use the correct index for the offset.
[gcc.git] / libgfortran / io / io.h
1 /* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
2 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
4
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
7 Libgfortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 Libgfortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Libgfortran; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22 /* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License. */
28
29 #ifndef GFOR_IO_H
30 #define GFOR_IO_H
31
32 /* IO library include. */
33
34 #include "libgfortran.h"
35
36 #include <setjmp.h>
37 #include <gthr.h>
38
39 /* Basic types used in data transfers. */
40
41 typedef enum
42 { BT_NULL, BT_INTEGER, BT_LOGICAL, BT_CHARACTER, BT_REAL,
43 BT_COMPLEX
44 }
45 bt;
46
47
48 struct st_parameter_dt;
49
50 typedef struct stream
51 {
52 char *(*alloc_w_at) (struct stream *, int *, gfc_offset);
53 char *(*alloc_r_at) (struct stream *, int *, gfc_offset);
54 try (*sfree) (struct stream *);
55 try (*close) (struct stream *);
56 try (*seek) (struct stream *, gfc_offset);
57 try (*trunc) (struct stream *);
58 int (*read) (struct stream *, void *, size_t *);
59 int (*write) (struct stream *, const void *, size_t *);
60 try (*set) (struct stream *, int, size_t);
61 }
62 stream;
63
64
65 /* Macros for doing file I/O given a stream. */
66
67 #define sfree(s) ((s)->sfree)(s)
68 #define sclose(s) ((s)->close)(s)
69
70 #define salloc_r(s, len) ((s)->alloc_r_at)(s, len, -1)
71 #define salloc_w(s, len) ((s)->alloc_w_at)(s, len, -1)
72
73 #define salloc_r_at(s, len, where) ((s)->alloc_r_at)(s, len, where)
74 #define salloc_w_at(s, len, where) ((s)->alloc_w_at)(s, len, where)
75
76 #define sseek(s, pos) ((s)->seek)(s, pos)
77 #define struncate(s) ((s)->trunc)(s)
78 #define sread(s, buf, nbytes) ((s)->read)(s, buf, nbytes)
79 #define swrite(s, buf, nbytes) ((s)->write)(s, buf, nbytes)
80
81 #define sset(s, c, n) ((s)->set)(s, c, n)
82
83 /* Macros for testing what kinds of I/O we are doing. */
84
85 #define is_array_io(dtp) ((dtp)->internal_unit_desc)
86
87 #define is_internal_unit(dtp) ((dtp)->u.p.unit_is_internal)
88
89 #define is_stream_io(dtp) ((dtp)->u.p.current_unit->flags.access == ACCESS_STREAM)
90
91 /* The array_loop_spec contains the variables for the loops over index ranges
92 that are encountered. Since the variables can be negative, ssize_t
93 is used. */
94
95 typedef struct array_loop_spec
96 {
97 /* Index counter for this dimension. */
98 ssize_t idx;
99
100 /* Start for the index counter. */
101 ssize_t start;
102
103 /* End for the index counter. */
104 ssize_t end;
105
106 /* Step for the index counter. */
107 ssize_t step;
108 }
109 array_loop_spec;
110
111 /* Representation of a namelist object in libgfortran
112
113 Namelist Records
114 &GROUPNAME OBJECT=value[s] [,OBJECT=value[s]].../
115 or
116 &GROUPNAME OBJECT=value[s] [,OBJECT=value[s]]...&END
117
118 The object can be a fully qualified, compound name for an intrinsic
119 type, derived types or derived type components. So, a substring
120 a(:)%b(4)%ch(2:4)(1:7) has to be treated correctly in namelist
121 read. Hence full information about the structure of the object has
122 to be available to list_read.c and write.
123
124 These requirements are met by the following data structures.
125
126 namelist_info type contains all the scalar information about the
127 object and arrays of descriptor_dimension and array_loop_spec types for
128 arrays. */
129
130 typedef struct namelist_type
131 {
132
133 /* Object type, stored as GFC_DTYPE_xxxx. */
134 bt type;
135
136 /* Object name. */
137 char * var_name;
138
139 /* Address for the start of the object's data. */
140 void * mem_pos;
141
142 /* Flag to show that a read is to be attempted for this node. */
143 int touched;
144
145 /* Length of intrinsic type in bytes. */
146 int len;
147
148 /* Rank of the object. */
149 int var_rank;
150
151 /* Overall size of the object in bytes. */
152 index_type size;
153
154 /* Length of character string. */
155 index_type string_length;
156
157 descriptor_dimension * dim;
158 array_loop_spec * ls;
159 struct namelist_type * next;
160 }
161 namelist_info;
162
163 /* Options for the OPEN statement. */
164
165 typedef enum
166 { ACCESS_SEQUENTIAL, ACCESS_DIRECT, ACCESS_APPEND, ACCESS_STREAM,
167 ACCESS_UNSPECIFIED
168 }
169 unit_access;
170
171 typedef enum
172 { ACTION_READ, ACTION_WRITE, ACTION_READWRITE,
173 ACTION_UNSPECIFIED
174 }
175 unit_action;
176
177 typedef enum
178 { BLANK_NULL, BLANK_ZERO, BLANK_UNSPECIFIED }
179 unit_blank;
180
181 typedef enum
182 { DELIM_NONE, DELIM_APOSTROPHE, DELIM_QUOTE,
183 DELIM_UNSPECIFIED
184 }
185 unit_delim;
186
187 typedef enum
188 { FORM_FORMATTED, FORM_UNFORMATTED, FORM_UNSPECIFIED }
189 unit_form;
190
191 typedef enum
192 { POSITION_ASIS, POSITION_REWIND, POSITION_APPEND,
193 POSITION_UNSPECIFIED
194 }
195 unit_position;
196
197 typedef enum
198 { STATUS_UNKNOWN, STATUS_OLD, STATUS_NEW, STATUS_SCRATCH,
199 STATUS_REPLACE, STATUS_UNSPECIFIED
200 }
201 unit_status;
202
203 typedef enum
204 { PAD_YES, PAD_NO, PAD_UNSPECIFIED }
205 unit_pad;
206
207 typedef enum
208 { ADVANCE_YES, ADVANCE_NO, ADVANCE_UNSPECIFIED }
209 unit_advance;
210
211 typedef enum
212 {READING, WRITING}
213 unit_mode;
214
215 #define CHARACTER1(name) \
216 char * name; \
217 gfc_charlen_type name ## _len
218 #define CHARACTER2(name) \
219 gfc_charlen_type name ## _len; \
220 char * name
221
222 typedef struct
223 {
224 st_parameter_common common;
225 GFC_INTEGER_4 recl_in;
226 CHARACTER2 (file);
227 CHARACTER1 (status);
228 CHARACTER2 (access);
229 CHARACTER1 (form);
230 CHARACTER2 (blank);
231 CHARACTER1 (position);
232 CHARACTER2 (action);
233 CHARACTER1 (delim);
234 CHARACTER2 (pad);
235 CHARACTER1 (convert);
236 }
237 st_parameter_open;
238
239 #define IOPARM_CLOSE_HAS_STATUS (1 << 7)
240
241 typedef struct
242 {
243 st_parameter_common common;
244 CHARACTER1 (status);
245 }
246 st_parameter_close;
247
248 typedef struct
249 {
250 st_parameter_common common;
251 }
252 st_parameter_filepos;
253
254 #define IOPARM_INQUIRE_HAS_EXIST (1 << 7)
255 #define IOPARM_INQUIRE_HAS_OPENED (1 << 8)
256 #define IOPARM_INQUIRE_HAS_NUMBER (1 << 9)
257 #define IOPARM_INQUIRE_HAS_NAMED (1 << 10)
258 #define IOPARM_INQUIRE_HAS_NEXTREC (1 << 11)
259 #define IOPARM_INQUIRE_HAS_RECL_OUT (1 << 12)
260 #define IOPARM_INQUIRE_HAS_STRM_POS_OUT (1 << 13)
261 #define IOPARM_INQUIRE_HAS_FILE (1 << 14)
262 #define IOPARM_INQUIRE_HAS_ACCESS (1 << 15)
263 #define IOPARM_INQUIRE_HAS_FORM (1 << 16)
264 #define IOPARM_INQUIRE_HAS_BLANK (1 << 17)
265 #define IOPARM_INQUIRE_HAS_POSITION (1 << 18)
266 #define IOPARM_INQUIRE_HAS_ACTION (1 << 19)
267 #define IOPARM_INQUIRE_HAS_DELIM (1 << 20)
268 #define IOPARM_INQUIRE_HAS_PAD (1 << 21)
269 #define IOPARM_INQUIRE_HAS_NAME (1 << 22)
270 #define IOPARM_INQUIRE_HAS_SEQUENTIAL (1 << 23)
271 #define IOPARM_INQUIRE_HAS_DIRECT (1 << 24)
272 #define IOPARM_INQUIRE_HAS_FORMATTED (1 << 25)
273 #define IOPARM_INQUIRE_HAS_UNFORMATTED (1 << 26)
274 #define IOPARM_INQUIRE_HAS_READ (1 << 27)
275 #define IOPARM_INQUIRE_HAS_WRITE (1 << 28)
276 #define IOPARM_INQUIRE_HAS_READWRITE (1 << 29)
277 #define IOPARM_INQUIRE_HAS_CONVERT (1 << 30)
278
279 typedef struct
280 {
281 st_parameter_common common;
282 GFC_INTEGER_4 *exist, *opened, *number, *named;
283 GFC_INTEGER_4 *nextrec, *recl_out;
284 GFC_IO_INT *strm_pos_out;
285 CHARACTER1 (file);
286 CHARACTER2 (access);
287 CHARACTER1 (form);
288 CHARACTER2 (blank);
289 CHARACTER1 (position);
290 CHARACTER2 (action);
291 CHARACTER1 (delim);
292 CHARACTER2 (pad);
293 CHARACTER1 (name);
294 CHARACTER2 (sequential);
295 CHARACTER1 (direct);
296 CHARACTER2 (formatted);
297 CHARACTER1 (unformatted);
298 CHARACTER2 (read);
299 CHARACTER1 (write);
300 CHARACTER2 (readwrite);
301 CHARACTER1 (convert);
302 }
303 st_parameter_inquire;
304
305 struct gfc_unit;
306 struct format_data;
307
308 #define IOPARM_DT_LIST_FORMAT (1 << 7)
309 #define IOPARM_DT_NAMELIST_READ_MODE (1 << 8)
310 #define IOPARM_DT_HAS_REC (1 << 9)
311 #define IOPARM_DT_HAS_SIZE (1 << 10)
312 #define IOPARM_DT_HAS_IOLENGTH (1 << 11)
313 #define IOPARM_DT_HAS_FORMAT (1 << 12)
314 #define IOPARM_DT_HAS_ADVANCE (1 << 13)
315 #define IOPARM_DT_HAS_INTERNAL_UNIT (1 << 14)
316 #define IOPARM_DT_HAS_NAMELIST_NAME (1 << 15)
317 /* Internal use bit. */
318 #define IOPARM_DT_IONML_SET (1 << 31)
319
320 typedef struct st_parameter_dt
321 {
322 st_parameter_common common;
323 GFC_IO_INT rec;
324 GFC_IO_INT *size, *iolength;
325 gfc_array_char *internal_unit_desc;
326 CHARACTER1 (format);
327 CHARACTER2 (advance);
328 CHARACTER1 (internal_unit);
329 CHARACTER2 (namelist_name);
330 /* Private part of the structure. The compiler just needs
331 to reserve enough space. */
332 union
333 {
334 struct
335 {
336 void (*transfer) (struct st_parameter_dt *, bt, void *, int,
337 size_t, size_t);
338 struct gfc_unit *current_unit;
339 /* Item number in a formatted data transfer. Also used in namelist
340 read_logical as an index into line_buffer. */
341 int item_count;
342 unit_mode mode;
343 unit_blank blank_status;
344 enum {SIGN_S, SIGN_SS, SIGN_SP} sign_status;
345 int scale_factor;
346 int max_pos; /* Maximum righthand column written to. */
347 /* Number of skips + spaces to be done for T and X-editing. */
348 int skips;
349 /* Number of spaces to be done for T and X-editing. */
350 int pending_spaces;
351 /* Whether an EOR condition was encountered. Value is:
352 0 if no EOR was encountered
353 1 if an EOR was encountered due to a 1-byte marker (LF)
354 2 if an EOR was encountered due to a 2-bytes marker (CRLF) */
355 int sf_seen_eor;
356 unit_advance advance_status;
357
358 unsigned reversion_flag : 1; /* Format reversion has occurred. */
359 unsigned first_item : 1;
360 unsigned seen_dollar : 1;
361 unsigned eor_condition : 1;
362 unsigned no_leading_blank : 1;
363 unsigned char_flag : 1;
364 unsigned input_complete : 1;
365 unsigned at_eol : 1;
366 unsigned comma_flag : 1;
367 /* A namelist specific flag used in the list directed library
368 to flag that calls are being made from namelist read (eg. to
369 ignore comments or to treat '/' as a terminator) */
370 unsigned namelist_mode : 1;
371 /* A namelist specific flag used in the list directed library
372 to flag read errors and return, so that an attempt can be
373 made to read a new object name. */
374 unsigned nml_read_error : 1;
375 /* A sequential formatted read specific flag used to signal that a
376 character string is being read so don't use commas to shorten a
377 formatted field width. */
378 unsigned sf_read_comma : 1;
379 /* A namelist specific flag used to enable reading input from
380 line_buffer for logical reads. */
381 unsigned line_buffer_enabled : 1;
382 /* An internal unit specific flag used to identify that the associated
383 unit is internal. */
384 unsigned unit_is_internal : 1;
385 /* An internal unit specific flag to signify an EOF condition for list
386 directed read. */
387 unsigned at_eof : 1;
388 /* 16 unused bits. */
389
390 char last_char;
391 char nml_delim;
392
393 int repeat_count;
394 int saved_length;
395 int saved_used;
396 bt saved_type;
397 char *saved_string;
398 char *scratch;
399 char *line_buffer;
400 struct format_data *fmt;
401 jmp_buf *eof_jump;
402 namelist_info *ionml;
403 /* A flag used to identify when a non-standard expanded namelist read
404 has occurred. */
405 int expanded_read;
406 /* Storage area for values except for strings. Must be large
407 enough to hold a complex value (two reals) of the largest
408 kind. */
409 char value[32];
410 gfc_offset size_used;
411 } p;
412 /* This pad size must be equal to the pad_size declared in
413 trans-io.c (gfc_build_io_library_fndecls). The above structure
414 must be smaller or equal to this array. */
415 char pad[16 * sizeof (char *) + 32 * sizeof (int)];
416 } u;
417 }
418 st_parameter_dt;
419
420 /* Ensure st_parameter_dt's u.pad is bigger or equal to u.p. */
421 extern char check_st_parameter_dt[sizeof (((st_parameter_dt *) 0)->u.pad)
422 >= sizeof (((st_parameter_dt *) 0)->u.p)
423 ? 1 : -1];
424
425 #undef CHARACTER1
426 #undef CHARACTER2
427
428 typedef struct
429 {
430 unit_access access;
431 unit_action action;
432 unit_blank blank;
433 unit_delim delim;
434 unit_form form;
435 int is_notpadded;
436 unit_position position;
437 unit_status status;
438 unit_pad pad;
439 unit_convert convert;
440 int has_recl;
441 }
442 unit_flags;
443
444
445 typedef struct gfc_unit
446 {
447 int unit_number;
448 stream *s;
449
450 /* Treap links. */
451 struct gfc_unit *left, *right;
452 int priority;
453
454 int read_bad, current_record, saved_pos;
455 enum
456 { NO_ENDFILE, AT_ENDFILE, AFTER_ENDFILE }
457 endfile;
458
459 unit_mode mode;
460 unit_flags flags;
461
462 /* recl -- Record length of the file.
463 last_record -- Last record number read or written
464 maxrec -- Maximum record number in a direct access file
465 bytes_left -- Bytes left in current record.
466 strm_pos -- Current position in file for STREAM I/O.
467 recl_subrecord -- Maximum length for subrecord.
468 bytes_left_subrecord -- Bytes left in current subrecord. */
469 gfc_offset recl, last_record, maxrec, bytes_left, strm_pos,
470 recl_subrecord, bytes_left_subrecord;
471
472 /* Set to 1 if we have read a subrecord. */
473
474 int continued;
475
476 __gthread_mutex_t lock;
477 /* Number of threads waiting to acquire this unit's lock.
478 When non-zero, close_unit doesn't only removes the unit
479 from the UNIT_ROOT tree, but doesn't free it and the
480 last of the waiting threads will do that.
481 This must be either atomically increased/decreased, or
482 always guarded by UNIT_LOCK. */
483 int waiting;
484 /* Flag set by close_unit if the unit as been closed.
485 Must be manipulated under unit's lock. */
486 int closed;
487
488 /* For traversing arrays */
489 array_loop_spec *ls;
490 int rank;
491
492 int file_len;
493 char *file;
494 }
495 gfc_unit;
496
497 /* Format tokens. Only about half of these can be stored in the
498 format nodes. */
499
500 typedef enum
501 {
502 FMT_NONE = 0, FMT_UNKNOWN, FMT_SIGNED_INT, FMT_ZERO, FMT_POSINT, FMT_PERIOD,
503 FMT_COMMA, FMT_COLON, FMT_SLASH, FMT_DOLLAR, FMT_T, FMT_TR, FMT_TL,
504 FMT_LPAREN, FMT_RPAREN, FMT_X, FMT_S, FMT_SS, FMT_SP, FMT_STRING,
505 FMT_BADSTRING, FMT_P, FMT_I, FMT_B, FMT_BN, FMT_BZ, FMT_O, FMT_Z, FMT_F,
506 FMT_E, FMT_EN, FMT_ES, FMT_G, FMT_L, FMT_A, FMT_D, FMT_H, FMT_END
507 }
508 format_token;
509
510
511 /* Format nodes. A format string is converted into a tree of these
512 structures, which is traversed as part of a data transfer statement. */
513
514 typedef struct fnode
515 {
516 format_token format;
517 int repeat;
518 struct fnode *next;
519 char *source;
520
521 union
522 {
523 struct
524 {
525 int w, d, e;
526 }
527 real;
528
529 struct
530 {
531 int length;
532 char *p;
533 }
534 string;
535
536 struct
537 {
538 int w, m;
539 }
540 integer;
541
542 int w;
543 int k;
544 int r;
545 int n;
546
547 struct fnode *child;
548 }
549 u;
550
551 /* Members for traversing the tree during data transfer. */
552
553 int count;
554 struct fnode *current;
555
556 }
557 fnode;
558
559
560 /* unix.c */
561
562 extern int move_pos_offset (stream *, int);
563 internal_proto(move_pos_offset);
564
565 extern int compare_files (stream *, stream *);
566 internal_proto(compare_files);
567
568 extern stream *open_external (st_parameter_open *, unit_flags *);
569 internal_proto(open_external);
570
571 extern stream *open_internal (char *, int);
572 internal_proto(open_internal);
573
574 extern stream *input_stream (void);
575 internal_proto(input_stream);
576
577 extern stream *output_stream (void);
578 internal_proto(output_stream);
579
580 extern stream *error_stream (void);
581 internal_proto(error_stream);
582
583 extern int compare_file_filename (gfc_unit *, const char *, int);
584 internal_proto(compare_file_filename);
585
586 extern gfc_unit *find_file (const char *file, gfc_charlen_type file_len);
587 internal_proto(find_file);
588
589 extern int stream_at_bof (stream *);
590 internal_proto(stream_at_bof);
591
592 extern int stream_at_eof (stream *);
593 internal_proto(stream_at_eof);
594
595 extern int delete_file (gfc_unit *);
596 internal_proto(delete_file);
597
598 extern int file_exists (const char *file, gfc_charlen_type file_len);
599 internal_proto(file_exists);
600
601 extern const char *inquire_sequential (const char *, int);
602 internal_proto(inquire_sequential);
603
604 extern const char *inquire_direct (const char *, int);
605 internal_proto(inquire_direct);
606
607 extern const char *inquire_formatted (const char *, int);
608 internal_proto(inquire_formatted);
609
610 extern const char *inquire_unformatted (const char *, int);
611 internal_proto(inquire_unformatted);
612
613 extern const char *inquire_read (const char *, int);
614 internal_proto(inquire_read);
615
616 extern const char *inquire_write (const char *, int);
617 internal_proto(inquire_write);
618
619 extern const char *inquire_readwrite (const char *, int);
620 internal_proto(inquire_readwrite);
621
622 extern gfc_offset file_length (stream *);
623 internal_proto(file_length);
624
625 extern gfc_offset file_position (stream *);
626 internal_proto(file_position);
627
628 extern int is_seekable (stream *);
629 internal_proto(is_seekable);
630
631 extern int is_special (stream *);
632 internal_proto(is_special);
633
634 extern int is_preconnected (stream *);
635 internal_proto(is_preconnected);
636
637 extern void flush_if_preconnected (stream *);
638 internal_proto(flush_if_preconnected);
639
640 extern void empty_internal_buffer(stream *);
641 internal_proto(empty_internal_buffer);
642
643 extern try flush (stream *);
644 internal_proto(flush);
645
646 extern int stream_isatty (stream *);
647 internal_proto(stream_isatty);
648
649 extern char * stream_ttyname (stream *);
650 internal_proto(stream_ttyname);
651
652 extern gfc_offset stream_offset (stream *s);
653 internal_proto(stream_offset);
654
655 extern int unpack_filename (char *, const char *, int);
656 internal_proto(unpack_filename);
657
658 /* unit.c */
659
660 /* Maximum file offset, computed at library initialization time. */
661 extern gfc_offset max_offset;
662 internal_proto(max_offset);
663
664 /* Unit tree root. */
665 extern gfc_unit *unit_root;
666 internal_proto(unit_root);
667
668 extern __gthread_mutex_t unit_lock;
669 internal_proto(unit_lock);
670
671 extern int close_unit (gfc_unit *);
672 internal_proto(close_unit);
673
674 extern gfc_unit *get_internal_unit (st_parameter_dt *);
675 internal_proto(get_internal_unit);
676
677 extern void free_internal_unit (st_parameter_dt *);
678 internal_proto(free_internal_unit);
679
680 extern gfc_unit *find_unit (int);
681 internal_proto(find_unit);
682
683 extern gfc_unit *find_or_create_unit (int);
684 internal_proto(find_or_create_unit);
685
686 extern gfc_unit *get_unit (st_parameter_dt *, int);
687 internal_proto(get_unit);
688
689 extern void unlock_unit (gfc_unit *);
690 internal_proto(unlock_unit);
691
692 extern void update_position (gfc_unit *);
693 internal_proto(update_position);
694
695 /* open.c */
696
697 extern gfc_unit *new_unit (st_parameter_open *, gfc_unit *, unit_flags *);
698 internal_proto(new_unit);
699
700 /* format.c */
701
702 extern void parse_format (st_parameter_dt *);
703 internal_proto(parse_format);
704
705 extern const fnode *next_format (st_parameter_dt *);
706 internal_proto(next_format);
707
708 extern void unget_format (st_parameter_dt *, const fnode *);
709 internal_proto(unget_format);
710
711 extern void format_error (st_parameter_dt *, const fnode *, const char *);
712 internal_proto(format_error);
713
714 extern void free_format_data (st_parameter_dt *);
715 internal_proto(free_format_data);
716
717 /* transfer.c */
718
719 #define SCRATCH_SIZE 300
720
721 extern const char *type_name (bt);
722 internal_proto(type_name);
723
724 extern void *read_block (st_parameter_dt *, int *);
725 internal_proto(read_block);
726
727 extern char *read_sf (st_parameter_dt *, int *, int);
728 internal_proto(read_sf);
729
730 extern void *write_block (st_parameter_dt *, int);
731 internal_proto(write_block);
732
733 extern gfc_offset next_array_record (st_parameter_dt *, array_loop_spec *);
734 internal_proto(next_array_record);
735
736 extern gfc_offset init_loop_spec (gfc_array_char *, array_loop_spec *);
737 internal_proto(init_loop_spec);
738
739 extern void next_record (st_parameter_dt *, int);
740 internal_proto(next_record);
741
742 extern void reverse_memcpy (void *, const void *, size_t);
743 internal_proto (reverse_memcpy);
744
745 /* read.c */
746
747 extern void set_integer (void *, GFC_INTEGER_LARGEST, int);
748 internal_proto(set_integer);
749
750 extern GFC_UINTEGER_LARGEST max_value (int, int);
751 internal_proto(max_value);
752
753 extern int convert_real (st_parameter_dt *, void *, const char *, int);
754 internal_proto(convert_real);
755
756 extern void read_a (st_parameter_dt *, const fnode *, char *, int);
757 internal_proto(read_a);
758
759 extern void read_f (st_parameter_dt *, const fnode *, char *, int);
760 internal_proto(read_f);
761
762 extern void read_l (st_parameter_dt *, const fnode *, char *, int);
763 internal_proto(read_l);
764
765 extern void read_x (st_parameter_dt *, int);
766 internal_proto(read_x);
767
768 extern void read_radix (st_parameter_dt *, const fnode *, char *, int, int);
769 internal_proto(read_radix);
770
771 extern void read_decimal (st_parameter_dt *, const fnode *, char *, int);
772 internal_proto(read_decimal);
773
774 /* list_read.c */
775
776 extern void list_formatted_read (st_parameter_dt *, bt, void *, int, size_t,
777 size_t);
778 internal_proto(list_formatted_read);
779
780 extern void finish_list_read (st_parameter_dt *);
781 internal_proto(finish_list_read);
782
783 extern void namelist_read (st_parameter_dt *);
784 internal_proto(namelist_read);
785
786 extern void namelist_write (st_parameter_dt *);
787 internal_proto(namelist_write);
788
789 /* write.c */
790
791 extern void write_a (st_parameter_dt *, const fnode *, const char *, int);
792 internal_proto(write_a);
793
794 extern void write_b (st_parameter_dt *, const fnode *, const char *, int);
795 internal_proto(write_b);
796
797 extern void write_d (st_parameter_dt *, const fnode *, const char *, int);
798 internal_proto(write_d);
799
800 extern void write_e (st_parameter_dt *, const fnode *, const char *, int);
801 internal_proto(write_e);
802
803 extern void write_en (st_parameter_dt *, const fnode *, const char *, int);
804 internal_proto(write_en);
805
806 extern void write_es (st_parameter_dt *, const fnode *, const char *, int);
807 internal_proto(write_es);
808
809 extern void write_f (st_parameter_dt *, const fnode *, const char *, int);
810 internal_proto(write_f);
811
812 extern void write_i (st_parameter_dt *, const fnode *, const char *, int);
813 internal_proto(write_i);
814
815 extern void write_l (st_parameter_dt *, const fnode *, char *, int);
816 internal_proto(write_l);
817
818 extern void write_o (st_parameter_dt *, const fnode *, const char *, int);
819 internal_proto(write_o);
820
821 extern void write_x (st_parameter_dt *, int, int);
822 internal_proto(write_x);
823
824 extern void write_z (st_parameter_dt *, const fnode *, const char *, int);
825 internal_proto(write_z);
826
827 extern void list_formatted_write (st_parameter_dt *, bt, void *, int, size_t,
828 size_t);
829 internal_proto(list_formatted_write);
830
831 /* size_from_kind.c */
832 extern size_t size_from_real_kind (int);
833 internal_proto(size_from_real_kind);
834
835 extern size_t size_from_complex_kind (int);
836 internal_proto(size_from_complex_kind);
837
838 /* lock.c */
839 extern void free_ionml (st_parameter_dt *);
840 internal_proto(free_ionml);
841
842 static inline void
843 inc_waiting_locked (gfc_unit *u)
844 {
845 #ifdef HAVE_SYNC_FETCH_AND_ADD
846 (void) __sync_fetch_and_add (&u->waiting, 1);
847 #else
848 u->waiting++;
849 #endif
850 }
851
852 static inline int
853 predec_waiting_locked (gfc_unit *u)
854 {
855 #ifdef HAVE_SYNC_FETCH_AND_ADD
856 return __sync_add_and_fetch (&u->waiting, -1);
857 #else
858 return --u->waiting;
859 #endif
860 }
861
862 static inline void
863 dec_waiting_unlocked (gfc_unit *u)
864 {
865 #ifdef HAVE_SYNC_FETCH_AND_ADD
866 (void) __sync_fetch_and_add (&u->waiting, -1);
867 #else
868 __gthread_mutex_lock (&unit_lock);
869 u->waiting--;
870 __gthread_mutex_unlock (&unit_lock);
871 #endif
872 }
873
874 #endif
875