Skip to content

Commit

Permalink
Check if stdio supports tweaking lval and cnt simultaneously.
Browse files Browse the repository at this point in the history
Subject: PATCH (Re: PerlIO - Configure tweak for Linux/glibc?)
Message-ID: <20001023153932.A10786@plum.flirble.org>

p4raw-id: //depot/perl@7427
  • Loading branch information
nwc10 authored and jhi committed Oct 24, 2000
1 parent 1724fb8 commit a7ffa9b
Show file tree
Hide file tree
Showing 22 changed files with 220 additions and 36 deletions.
82 changes: 81 additions & 1 deletion Configure
Expand Up @@ -20,7 +20,7 @@

# $Id: Head.U,v 3.0.1.9 1997/02/28 15:02:09 ram Exp $
#
# Generated on Thu Oct 19 22:28:50 EET DST 2000 [metaconfig 3.0 PL70]
# Generated on Tue Oct 24 21:00:34 EET DST 2000 [metaconfig 3.0 PL70]
# (with additional metaconfig patches by perlbug@perl.org)

cat >/tmp/c1$$ <<EOF
Expand Down Expand Up @@ -536,6 +536,8 @@ d_fstatvfs=''
d_statvfs=''
d_stdio_cnt_lval=''
d_stdio_ptr_lval=''
d_stdio_ptr_lval_nochange_cnt=''
d_stdio_ptr_lval_sets_cnt=''
d_stdiobase=''
d_stdstdio=''
stdio_base=''
Expand Down Expand Up @@ -11479,6 +11481,82 @@ esac
set d_stdio_cnt_lval
eval $setvar


: test whether setting _ptr sets _cnt as a side effect
d_stdio_ptr_lval_sets_cnt="$undef"
d_stdio_ptr_lval_nochange_cnt="$undef"
case "$d_stdio_ptr_lval$d_stdstdio" in
$define$define)
echo "Checking to see what happens if we set the stdio ptr..." >&4
$cat >try.c <<EOP
#include <stdio.h>
/* Can we scream? */
/* Eat dust sed :-) */
#define FILE_ptr(fp) $stdio_ptr
#define FILE_cnt(fp) $stdio_cnt
int main() {
FILE *fp = fopen("try.c", "r");
char c = getc(fp);
char *ptr;
size_t cnt;
if (!(
18 <= FILE_cnt(fp) &&
strncmp(FILE_ptr(fp), "include <stdio.h>\n", 18) == 0
)) {
puts("Fail even to read");
exit (1);
}
ptr = FILE_ptr(fp);
cnt = FILE_cnt(fp);

FILE_ptr(fp)+= 42;

if (FILE_ptr(fp) != (ptr + 42)) {
printf("Fail ptr check %p != %p", FILE_ptr(fp), (ptr + 42));
exit (1);
}
if (FILE_cnt(fp) <= 20) {
printf ("Fail (<20 chars to test)");
exit (1);
}
if (strncmp(FILE_ptr(fp), "Eat dust sed :-) */\n", 20) != 0) {
puts("Fail compare");
exit (1);
}
if (cnt == FILE_cnt(fp)) {
puts("Pass_unchanged");
exit (0);
}
if (FILE_cnt(fp) == (cnt - 42)) {
puts("Pass_changed");
exit (0);
}
printf("Fail count was %d now %d\n", cnt, FILE_cnt(fp));
return 1;

}
EOP
set try
if eval $compile; then
case `./try$exe_ext` in
Pass_changed)
echo "Increasing ptr in your stdio decreases cnt by the same amount. Good." >&4
d_stdio_ptr_lval_sets_cnt="$define" ;;
Pass_unchanged)
echo "Increasing ptr in your stdio leaves cnt unchanged. Good." >&4
d_stdio_ptr_lval_nochange_cnt="$define" ;;
Fail*)
echo "Increasing ptr in your stdio didn't do exactly what I expected. We'll not be doing that then." >&4 ;;
*)
echo "It appears attempting to set ptr in your stdio is a bad plan." >&4 ;;
esac
else
echo "It seems we can't set ptr in your stdio. Nevermind." >&4
fi
$rm -f try.c try
;;
esac

: see if _base is also standard
val="$undef"
case "$d_stdstdio" in
Expand Down Expand Up @@ -15580,6 +15658,8 @@ d_statfs_s='$d_statfs_s'
d_statvfs='$d_statvfs'
d_stdio_cnt_lval='$d_stdio_cnt_lval'
d_stdio_ptr_lval='$d_stdio_ptr_lval'
d_stdio_ptr_lval_nochange_cnt='$d_stdio_ptr_lval_nochange_cnt'
d_stdio_ptr_lval_sets_cnt='$d_stdio_ptr_lval_sets_cnt'
d_stdio_stream_array='$d_stdio_stream_array'
d_stdiobase='$d_stdiobase'
d_stdstdio='$d_stdstdio'
Expand Down
9 changes: 9 additions & 0 deletions Porting/Glossary
Expand Up @@ -1478,6 +1478,15 @@ d_stdio_ptr_lval (d_stdstdio.U):
This variable conditionally defines STDIO_PTR_LVALUE if the
FILE_ptr macro can be used as an lvalue.

d_stdio_ptr_lval_nochange_cnt (d_stdstdio.U):
This symbol is defined if using the FILE_ptr macro as an lvalue
to increase the pointer by n leaves File_cnt(fp) unchanged.

d_stdio_ptr_lval_sets_cnt (d_stdstdio.U):
This symbol is defined if using the FILE_ptr macro as an lvalue
to increase the pointer by n has the side effect of decreasing the
value of File_cnt(fp) by n.

d_stdio_stream_array (stdio_streams.U):
This variable tells whether there is an array holding
the stdio streams.
Expand Down
6 changes: 4 additions & 2 deletions Porting/config.sh
Expand Up @@ -8,7 +8,7 @@

# Package name : perl5
# Source directory : /m/fs/work/work/permanent/perl/pp4/perl
# Configuration time: Fri Oct 13 02:12:22 EET DST 2000
# Configuration time: Tue Oct 24 21:07:39 EET DST 2000
# Configured by : jhi
# Target system : osf1 alpha.hut.fi v4.0 878 alpha

Expand Down Expand Up @@ -62,7 +62,7 @@ ccsymbols='__alpha=1 __LANGUAGE_C__=1 __osf__=1 __unix__=1 _LONGLONG=1 _SYSTYPE_
ccversion='V5.6-082'
cf_by='jhi'
cf_email='yourname@yourhost.yourplace.com'
cf_time='Fri Oct 13 02:12:22 EET DST 2000'
cf_time='Tue Oct 24 21:07:39 EET DST 2000'
charsize='1'
chgrp=''
chmod=''
Expand Down Expand Up @@ -336,6 +336,8 @@ d_statfs_s='define'
d_statvfs='define'
d_stdio_cnt_lval='define'
d_stdio_ptr_lval='define'
d_stdio_ptr_lval_nochange_cnt='undef'
d_stdio_ptr_lval_sets_cnt='undef'
d_stdio_stream_array='define'
d_stdiobase='define'
d_stdstdio='define'
Expand Down
13 changes: 12 additions & 1 deletion Porting/config_H
Expand Up @@ -17,7 +17,7 @@
/*
* Package name : perl5
* Source directory : /m/fs/work/work/permanent/perl/pp4/perl
* Configuration time: Fri Oct 13 02:12:22 EET DST 2000
* Configuration time: Tue Oct 24 21:07:39 EET DST 2000
* Configured by : jhi
* Target system : osf1 alpha.hut.fi v4.0 878 alpha
*/
Expand Down Expand Up @@ -2028,12 +2028,23 @@
* This symbol is defined if the FILE_cnt macro can be used as an
* lvalue.
*/
/* STDIO_PTR_LVAL_SETS_CNT:
* This symbol is defined if using the FILE_ptr macro as an lvalue
* to increase the pointer by n has the side effect of decreasing the
* value of File_cnt(fp) by n.
*/
/* STDIO_PTR_LVAL_NOCHANGE_CNT:
* This symbol is defined if using the FILE_ptr macro as an lvalue
* to increase the pointer by n leaves File_cnt(fp) unchanged.
*/
#define USE_STDIO_PTR /**/
#ifdef USE_STDIO_PTR
#define FILE_ptr(fp) ((fp)->_ptr)
#define STDIO_PTR_LVALUE /**/
#define FILE_cnt(fp) ((fp)->_cnt)
#define STDIO_CNT_LVALUE /**/
/*#define STDIO_PTR_LVAL_SETS_CNT / **/
/*#define STDIO_PTR_LVAL_NOCHANGE_CNT / **/
#endif

/* USE_STDIO_BASE:
Expand Down
11 changes: 11 additions & 0 deletions config_h.SH
Expand Up @@ -2048,12 +2048,23 @@ sed <<!GROK!THIS! >$CONFIG_H -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un
* This symbol is defined if the FILE_cnt macro can be used as an
* lvalue.
*/
/* STDIO_PTR_LVAL_SETS_CNT:
* This symbol is defined if using the FILE_ptr macro as an lvalue
* to increase the pointer by n has the side effect of decreasing the
* value of File_cnt(fp) by n.
*/
/* STDIO_PTR_LVAL_NOCHANGE_CNT:
* This symbol is defined if using the FILE_ptr macro as an lvalue
* to increase the pointer by n leaves File_cnt(fp) unchanged.
*/
#$d_stdstdio USE_STDIO_PTR /**/
#ifdef USE_STDIO_PTR
#define FILE_ptr(fp) $stdio_ptr
#$d_stdio_ptr_lval STDIO_PTR_LVALUE /**/
#define FILE_cnt(fp) $stdio_cnt
#$d_stdio_cnt_lval STDIO_CNT_LVALUE /**/
#$d_stdio_ptr_lval_sets_cnt STDIO_PTR_LVAL_SETS_CNT /**/
#$d_stdio_ptr_lval_nochange_cnt STDIO_PTR_LVAL_NOCHANGE_CNT /**/
#endif
/* USE_STDIO_BASE:
Expand Down
5 changes: 4 additions & 1 deletion configure.com
Expand Up @@ -4373,7 +4373,6 @@ $ d_mbstowcs="define"
$ d_mbtowc="define"
$ d_stdiobase="define"
$ d_stdio_cnt_lval="define"
$ d_stdio_ptr_lval="define"
$ d_stdstdio="define"
$ d_wcstombs="define"
$ d_mblen="define"
Expand Down Expand Up @@ -4402,6 +4401,8 @@ $ i_locale="undef"
$ d_locconv="undef"
$ d_setlocale="undef"
$ ENDIF
$ d_stdio_ptr_lval_sets_cnt="undef"
$ d_stdio_ptr_lval_nochange_cnt="undef"
$!
$! Sockets?
$ if Has_Socketshr .OR. Has_Dec_C_Sockets
Expand Down Expand Up @@ -4935,6 +4936,8 @@ $ WC "d_statfs_s='undef'"
$ WC "d_statfsflags='undef'"
$ WC "d_stdio_cnt_lval='" + d_stdio_cnt_lval + "'"
$ WC "d_stdio_ptr_lval='" + d_stdio_ptr_lval + "'"
$ WC "d_stdio_ptr_lval_sets_cnt='" + d_stdio_ptr_lval_sets_cnt + "'"
$ WC "d_stdio_ptr_lval_nochange_cnt='" + d_stdio_ptr_lval_nochange_cnt + "'"
$ WC "d_stdio_stream_array='undef'"
$ WC "d_stdiobase='" + d_stdiobase + "'"
$ WC "d_stdstdio='" + d_stdstdio + "'"
Expand Down
2 changes: 2 additions & 0 deletions epoc/config.sh
Expand Up @@ -324,6 +324,8 @@ d_statfsflags='define'
d_statvfs='undef'
d_stdio_cnt_lval='define'
d_stdio_ptr_lval='define'
d_stdio_ptr_lval_sets_cnt='undef'
d_stdio_ptr_lval_nochange_cnt='undef'
d_stdio_stream_array='undef'
d_stdiobase='undef'
d_stdstdio='undef'
Expand Down
16 changes: 11 additions & 5 deletions iperlsys.h
Expand Up @@ -186,13 +186,19 @@ struct IPerlStdIOInfo

#ifdef USE_STDIO_PTR
# define PerlIO_has_cntptr(f) 1
# ifdef STDIO_CNT_LVALUE
# define PerlIO_canset_cnt(f) 1
# ifdef STDIO_PTR_LVALUE
# ifdef STDIO_PTR_LVALUE
# ifdef STDIO_CNT_LVALUE
# define PerlIO_canset_cnt(f) 1
# ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
# define PerlIO_fast_gets(f) 1
# endif
# else /* STDIO_CNT_LVALUE */
# define PerlIO_canset_cnt(f) 0
# endif
# else /* STDIO_PTR_LVALUE */
# ifdef STDIO_PTR_LVAL_SETS_CNT
# define PerlIO_fast_gets(f) 1
# endif
# else
# define PerlIO_canset_cnt(f) 0
# endif
#else /* USE_STDIO_PTR */
# define PerlIO_has_cntptr(f) 0
Expand Down
8 changes: 6 additions & 2 deletions perlio.c
Expand Up @@ -176,10 +176,14 @@ PerlIO_set_ptrcnt(PerlIO *f, STDCHAR *ptr, int cnt)
#else
Perl_croak(aTHX_ "Cannot set 'ptr' of FILE * on this system");
#endif
#if defined(USE_STDIO_PTR) && defined(STDIO_CNT_LVALUE)
#if defined(USE_STDIO_PTR) && defined(STDIO_CNT_LVALUE) && defined (STDIO_PTR_LVAL_NOCHANGE_CNT)
FILE_cnt(f) = cnt;
#else
Perl_croak(aTHX_ "Cannot set 'cnt' of FILE * on this system");
#if defined(STDIO_PTR_LVAL_SETS_CNT)
assert (FILE_cnt(f) == cnt);
#else
Perl_croak(aTHX_ "Cannot set 'cnt' of FILE * on this system when setting 'ptr'");
#endif
#endif
}

Expand Down
16 changes: 13 additions & 3 deletions perlsdio.h
Expand Up @@ -97,20 +97,30 @@

#ifdef STDIO_CNT_LVALUE
#define PerlIO_canset_cnt(f) 1
#define PerlIO_set_cnt(f,c) (FILE_cnt(f) = (c))
#ifdef STDIO_PTR_LVALUE
#ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
#define PerlIO_fast_gets(f) 1
#endif
#define PerlIO_set_cnt(f,c) (FILE_cnt(f) = (c))
#else
#endif /* STDIO_PTR_LVALUE */
#else /* STDIO_CNT_LVALUE */
#define PerlIO_canset_cnt(f) 0
#define PerlIO_set_cnt(f,c) abort()
#endif

#ifdef STDIO_PTR_LVALUE
#define PerlIO_set_ptrcnt(f,p,c) (FILE_ptr(f) = (p), PerlIO_set_cnt(f,c))
#ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
#define PerlIO_set_ptrcnt(f,p,c) STMT_START {FILE_ptr(f) = (p), PerlIO_set_cnt(f,c)} STMT_END
#else
#ifdef STDIO_PTR_LVAL_SETS_CNT
/* assert() may pre-process to ""; potential syntax error (FILE_ptr(), ) */
#define PerlIO_set_ptrcnt(f,p,c) STMT_START {FILE_ptr(f) = (p); assert(FILE_cnt(f) == (c))} STMT_END
#define PerlIO_fast_gets(f) 1
#else
#define PerlIO_set_ptrcnt(f,p,c) abort()
#endif
#endif
#endif

#else /* USE_STDIO_PTR */

Expand Down
8 changes: 4 additions & 4 deletions perlsfio.h
Expand Up @@ -52,10 +52,10 @@ extern int _stdprintf _ARG_((const char*, ...));
#define PerlIO_has_cntptr(f) 1
#define PerlIO_get_ptr(f) ((f)->next)
#define PerlIO_get_cnt(f) ((f)->endr - (f)->next)
#define PerlIO_canset_cnt(f) 1
#define PerlIO_fast_gets(f) 1
#define PerlIO_set_ptrcnt(f,p,c) ((f)->next = (unsigned char *)(p))
#define PerlIO_set_cnt(f,c) 1
#define PerlIO_canset_cnt(f) 0
#define PerlIO_fast_gets(f) 1
#define PerlIO_set_ptrcnt(f,p,c) STMT_START {(f)->next = (unsigned char *)(p); assert(FILE_cnt(f) == (c))} STMT_END
#define PerlIO_set_cnt(f,c) Perl_croak(aTHX_ "Cannot set 'cnt' of FILE * on this system");

#define PerlIO_has_base(f) 1
#define PerlIO_get_base(f) ((f)->data)
Expand Down
6 changes: 4 additions & 2 deletions pod/Makefile.SH
Expand Up @@ -73,7 +73,9 @@ converters: $(CONVERTERS)
regen_pods: perlmodlib.pod toc
buildtoc: buildtoc.PL perl.pod ../MANIFEST
$(PERL) -I ../lib buildtoc.PL
$(PERL) buildtoc.PL
perltoc.pod: buildtoc
man: pod2man $(MAN)
Expand All @@ -82,7 +84,7 @@ html: pod2html $(HTML)
tex: pod2latex $(TEX)
toc: buildtoc
$(PERL) -I../lib buildtoc
$(PERL) buildtoc
.SUFFIXES: .pm .pod
Expand Down

0 comments on commit a7ffa9b

Please sign in to comment.