Nick Cremelie wrote:
Not really with bindings, but anyway: There's a known bug "On IRIX work stations, _p_initfdr() must be called manually" on the To-Do list. So, I'm adding AIX there. I don't know anything about these architectures, but I agree that fixing this would be a good idea... :-/
I don't see how I can call _p_initfdr() manually. From within the Pascal program, the compiler complains when I call that function. When I try to call InitFDR (defined in p/rts/gpc.pas I thought), the compiler says:
txtfile.pas: In function `Assign': txtfile.pas:16: undeclared identifier `Initfdr' (first use this function) txtfile.pas:16: (Each undeclared identifier is reported only once txtfile.pas:16: for each function it appears in.)
So how do I call initfdr manually???
Yes, the above description for the work around is a bit too simplistic. If you want to call it from Pascal, you have to copy the declaration of InitFDR from gpc.pas, or add an "uses gpc;" to your program (however, the latter is not yet completely worked out, so it may cause some name conflicts).
As you will recall, I had problems with gpc on AIX when opening files. I made a little change in rts-file.c: I replaced line 370:
_p_generic (701); /* FDR not initialized */
with
_p_initfdr(File,filename,8,0xf);
This means: if m_SIZ(File) == 0 (indicating that _p_initfdr was not called), I call it with a standard buffersize and flags). This enables me indeed to open files for reading and writing! However, I have no clue about the impact of this change.
A clever idea! The problem is to get the parameters right. The above work for text files, but they're a bit unusual (and I wonder why GPC uses them for Input and Output).
The following are the parameters GPC uses for the different kinds of files -- however, they're subject to change in future versions, but not too soon (i.e. not until GPC version 2.1):
Text files (text): 1, 1 Typed files (file of foo): Sizeof(f^), 0 Direct typed files (file [bar..baz] of foo): Sizeof(f^), 16 Untyped files (file) (BP extension): 1, 64
For "external" files, i.e. those declared in the program header, add 4 to the last parameter. The second parameter is actually the internal file name (i.e. the name of the variable as declared in the program), but it's only used for the Standard Pascal feature of asking the user for a name for file "foo", and for some error messages.
But it seems strange to me in the first place why _p_initfdr() isn't called automatically -- after all, the compiler (util.c, function init_simple() generates code to do so). Could you generate an assembler output of your Pascal program (gpc -S), and check if it contains some calls to _p_initfdr(), and if so, what parameters are pushed before it.
But then we noticed something else: reading a string (string[255]) with readln (from file or stdin) always returned an empty string, although eoln and eof are set appropriately (so it is actually reading the file!). We checked and noticed that the argument maxlen to _p_reads in rts-rdsub.c is always zero. Question: would this be because va_arg (which gets maxlen from a variable argument list) doesn't work probably, or because the variable argument list is not set properly when calling _p_read in rts-read.c ?
Could you please check which parameters are pushed before the call to _p_read() in the assembler code of your program (or just send me the assembler file if that's easier to you)?
For another test, you could check the value of s_maxlen in the READ_STRING macro in rts-rdinc.c (with some printf) and see if it's already wrong there. (I suppose it is, but one never knows...)
Also, did you get any warnings (especially of type mismatches and the like) when compiling the RTS? This might indicate some non-portable type conversions in the C files.
Perhaps really the varargs are to blame -- I don't know much about their inner workings. I intend to get rid of them, anyway. If they're the problem here, this might be a reason to get rid of them even earlier than planned...
Frank
Hi all
A clever idea! The problem is to get the parameters right. The above work for text files, but they're a bit unusual (and I wonder why GPC uses them for Input and Output).
So do I. But if I set them to e.g. 256,1 ("large" buffer, type text files), it didn't work. So I just took the values as for Input, Output).
But it seems strange to me in the first place why _p_initfdr() isn't called automatically -- after all, the compiler (util.c, function init_simple() generates code to do so). Could you generate an assembler output of your Pascal program (gpc -S), and check if it contains some calls to _p_initfdr(), and if so, what parameters are pushed before it.
I'm not familiar with assembler listings, but I definitely see _p_initfdr somewhere in there. But don't forget that Input and Output are always initialized with that function. I'll mail you the listing, Frank, no need to send the whole thing to the mailing list I presume...
Could you please check which parameters are pushed before the call to _p_read() in the assembler code of your program (or just send me the assembler file if that's easier to you)?
I'll send it too.
For another test, you could check the value of s_maxlen in the READ_STRING macro in rts-rdinc.c (with some printf) and see if it's already wrong there. (I suppose it is, but one never knows...)
Indeed, s_maxlen is zero as well. Strange:
Also, did you get any warnings (especially of type mismatches and the like) when compiling the RTS? This might indicate some non-portable type conversions in the C files.
These are all the warnings I got during the stage2 build for c and pascal using the stage 1 gcc-2.8.1 compiler (I didn't really worry about them, they did not seem too severe):
---begin--- p/version.c:59: warning: unknown escape sequence `)' include/sys/wait.h:90: warning: `WIFEXITED' redefined module.h:51: warning: this is the location of the previous definition include/sys/wait.h:92: warning: `WEXITSTATUS' redefined module.h:54: warning: this is the location of the previous definition include/sys/wait.h:94: warning: `WIFSIGNALED' redefined module.h:45: warning: this is the location of the previous definition include/sys/wait.h:96: warning: `WTERMSIG' redefined module.h:48: warning: this is the location of the previous definition module.c:1663: warning: comparison is always 0 due to limited range of data type include/sys/wait.h:90: warning: `WIFEXITED' redefined module.h:51: warning: this is the location of the previous definition include/sys/wait.h:92: warning: `WEXITSTATUS' redefined module.h:54: warning: this is the location of the previous definition include/sys/wait.h:94: warning: `WIFSIGNALED' redefined module.h:45: warning: this is the location of the previous definition include/sys/wait.h:96: warning: `WTERMSIG' redefined module.h:48: warning: this is the location of the previous definition include/sys/wait.h:90: warning: `WIFEXITED' redefined module.h:51: warning: this is the location of the previous definition include/sys/wait.h:92: warning: `WEXITSTATUS' redefined module.h:54: warning: this is the location of the previous definition include/sys/wait.h:94: warning: `WIFSIGNALED' redefined module.h:45: warning: this is the location of the previous definition include/sys/wait.h:96: warning: `WTERMSIG' redefined module.h:48: warning: this is the location of the previous definition types.c:197: warning: `this_set_type' might be used uninitialized in this function include/sys/wait.h:90: warning: `WIFEXITED' redefined module.h:51: warning: this is the location of the previous definition include/sys/wait.h:92: warning: `WEXITSTATUS' redefined module.h:54: warning: this is the location of the previous definition include/sys/wait.h:94: warning: `WIFSIGNALED' redefined module.h:45: warning: this is the location of the previous definition include/sys/wait.h:96: warning: `WTERMSIG' redefined module.h:48: warning: this is the location of the previous definition ./enquire.c:1401: warning: comparison is always 0 due to limited range of data type ./enquire.c:2443: warning: comparison is always 0 due to limited range of data type enquire.c:2147: warning: decimal constant is so large that it is unsigned enquire.c:2151: warning: decimal constant is so large that it is unsigned enquire.c:2147: warning: decimal constant is so large that it is unsigned enquire.c:2151: warning: decimal constant is so large that it is unsigned rts-write.c:69: warning: no previous prototype for `_p_write' rts-read.c:69: warning: no previous prototype for `_p_read' rts-read.c:152: warning: `_p_GetByt' was used with no prototype before its definition rts-block.c:33: warning: no previous prototype for `_p_blockread' rts-block.c:67: warning: no previous prototype for `_p_blockwrite' rts-file.c:169: warning: implicit declaration of function `strcasecmp' rts-random.c:85: warning: no previous prototype for `_p_truncate' rts-random.c:143: warning: suggest explicit braces to avoid ambiguous `else' rts-setup.c:28: warning: no previous prototype for `_p_setup' rts-setup.c:33: warning: no previous prototype for `_p_final' choose-temp.c:88: warning: implicit declaration of function `access' choose-temp.c:100: warning: no previous prototype for `choose_temp_base' choose-temp.c:108: warning: implicit declaration of function `getenv' choose-temp.c:129: warning: implicit declaration of function `malloc' choose-temp.c:144: warning: implicit declaration of function `mktemp' rts-error.c:171: warning: no previous prototype for `malloc_warning' rts-error.c:257: warning: no previous prototype for `_p_error' rts-misc.c:89: warning: no previous prototype for `_p_collect' rts-string.c:193: warning: no previous prototype for `_p_string' rts-string.c:396: warning: no previous prototype for `_p_writestr' rts-wrtinc.c:78: warning: implicit declaration of function `bcopy' rts-string.c:403: warning: `long_curlen' might be used uninitialized in this function rts-string.c:404: warning: `short_curlen' might be used uninitialized in this function rts-string.c:509: warning: no previous prototype for `_p_readstr' rts-string.c:614: warning: no previous prototype for `_p_val_byteint_check' rts-string.c:615: warning: no previous prototype for `_p_val_shortint_check' rts-string.c:616: warning: no previous prototype for `_p_val_integer_check' rts-string.c:617: warning: no previous prototype for `_p_val_medint_check' rts-string.c:618: warning: no previous prototype for `_p_val_longint_check' rts-string.c:619: warning: no previous prototype for `_p_val_bytecard_check' rts-string.c:620: warning: no previous prototype for `_p_val_shortcard_check' rts-string.c:621: warning: no previous prototype for `_p_val_cardinal_check' rts-string.c:622: warning: no previous prototype for `_p_val_medcard_check' rts-string.c:623: warning: no previous prototype for `_p_val_longcard_check' rts-string.c:624: warning: no previous prototype for `_p_val_byteint_nocheck' rts-string.c:625: warning: no previous prototype for `_p_val_shortint_nocheck' rts-string.c:626: warning: no previous prototype for `_p_val_integer_nocheck' rts-string.c:627: warning: no previous prototype for `_p_val_medint_nocheck' rts-string.c:628: warning: no previous prototype for `_p_val_longint_nocheck' rts-string.c:629: warning: no previous prototype for `_p_val_bytecard_nocheck' rts-string.c:630: warning: no previous prototype for `_p_val_shortcard_nocheck' rts-string.c:631: warning: no previous prototype for `_p_val_cardinal_nocheck' rts-string.c:632: warning: no previous prototype for `_p_val_medcard_nocheck' rts-string.c:633: warning: no previous prototype for `_p_val_longcard_nocheck' rts-string.c:662: warning: no previous prototype for `_p_val_shortreal' rts-string.c:663: warning: no previous prototype for `_p_val_real' rts-string.c:664: warning: no previous prototype for `_p_val_longreal' rts-bind.c:247: warning: implicit declaration of function `bcopy' rts-base.p:56: warning: no previous prototype for `__init_Rts_base' rts-assign.p:44: warning: no previous prototype for `__init_Rts_assign' rts-str.p:107: warning: passing arg 1 of `Insert_f' discards `const' from pointer target type rts-str.p:135: warning: no previous prototype for `__init_Rts_str' rts-numtodec.p:70: warning: `First_char' might be used uninitialized in this function rts-numtodec.p:204: warning: `Ch' might be used uninitialized in this function rts-numtodec.p:250: warning: no previous prototype for `__init_Rts_numtodec' rts-intfrac.p:72: warning: no previous prototype for `__init_Rts_intfrac' rts-move.p:94: warning: cast increases required alignment of target type rts-move.p:95: warning: cast increases required alignment of target type rts-move.p:99: warning: cast increases required alignment of target type rts-move.p:100: warning: cast increases required alignment of target type rts-move.p:102: warning: cast increases required alignment of target type rts-move.p:103: warning: cast increases required alignment of target type rts-move.p:106: warning: cast increases required alignment of target type rts-move.p:123: warning: cast increases required alignment of target type rts-move.p:124: warning: cast increases required alignment of target type rts-move.p:147: warning: pointer of type `void *' used in arithmetic rts-move.p:166: warning: cast increases required alignment of target type rts-move.p:170: warning: cast increases required alignment of target type rts-move.p:171: warning: cast increases required alignment of target type rts-move.p:172: warning: cast increases required alignment of target type rts-move.p:173: warning: cast increases required alignment of target type rts-move.p:185: warning: cast increases required alignment of target type rts-move.p:186: warning: cast increases required alignment of target type rts-move.p:208: warning: no previous prototype for `__init_Rts_move' vasprintf.c:119: warning: no previous prototype for `vasprintf' asprintf.c:27: warning: no previous prototype for `asprintf' gpc.pas:331: warning: no previous prototype for `__init_Gpc' /backup/gnu/gcc-2.8.1/p/rts/rts-emath.c:73: warning: type mismatch in implicit declaration for built-in function `sqrtl' /backup/gnu/gcc-2.8.1/p/rts/rts-emath.c:141: warning: type mismatch in implicit declaration for built-in function `sinl' /backup/gnu/gcc-2.8.1/p/rts/rts-emath.c:164: warning: type mismatch in implicit declaration for built-in function `cosl' Various warnings and error messages from fixproto are normal ---end---
Perhaps really the varargs are to blame -- I don't know much about their inner workings. I intend to get rid of them, anyway. If they're the problem here, this might be a reason to get rid of them even earlier than planned...
Maybe stdarg is broken in AIX, I don't know...
Nick