Skip to content

Commit

Permalink
GH-86 Revise saving of source-path by INCLUDED.
Browse files Browse the repository at this point in the history
  • Loading branch information
SirWumpus committed Dec 16, 2024
1 parent 1657d59 commit 4f6fbc2
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ dnl #endif
AC_CHECK_FUNCS([chdir getcwd mkdir rmdir closedir opendir readdir])
AC_CHECK_FUNCS([chmod chown chroot fchmod stat fstat link rename symlink unlink umask utime])
AC_CHECK_FUNCS([close creat dup dup2 ftruncate chsize truncate lseek open pipe read write])
AC_CHECK_FUNCS([isatty getdtablesize])
AC_CHECK_FUNCS([isatty getdtablesize readlink readlinkat])
AC_FUNC_CHOWN
])

Expand Down
6 changes: 6 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ AC_SUBST(CC_O)
AC_SUBST(CC_O_NAME)
AC_SUBST(LIBEXT)

AC_CHECK_HEADERS([ctype.h errno.h inttypes.h limits.h stdarg.h stddef.h stdint.h stdio.h unistd.h sys/ioctl.h])
AC_CHECK_HEADERS([ctype.h errno.h inttypes.h limits.h stdarg.h stddef.h stdint.h stdio.h fcntl.h unistd.h sys/ioctl.h])

AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
Expand Down
1 change: 1 addition & 0 deletions src/config.h.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ struct winsize {
/*
* File Locking
*/
#undef HAVE_FCNTL_H
#undef HAVE_SYS_FILE_H
#undef HAVE_FCNTL
#undef HAVE_FLOCK
Expand Down
4 changes: 3 additions & 1 deletion src/post4.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,6 @@ p4Free(P4_Ctx *ctx)
if (ctx->block_fd != NULL) {
(void) fclose(ctx->block_fd);
}
/* Data stack in allocated, because Java can grow it. */
free(ctx->ds.base - P4_GUARD_CELLS/2);
free(ctx->fs.base - P4_GUARD_CELLS/2);
free(ctx->rs.base - P4_GUARD_CELLS/2);
Expand Down Expand Up @@ -938,6 +937,7 @@ p4Create(P4_Options *opts)
if ((ctx->input = p4CreateInput()) == NULL) {
goto error0;
}
ctx->input->path = "/dev/stdin";
p4ResetInput(ctx, stdin);

if ((ctx->block = calloc(1, sizeof (*ctx->block))) == NULL) {
Expand Down Expand Up @@ -2568,6 +2568,7 @@ p4EvalFile(P4_Ctx *ctx, const char *file)
str = p4FindFilePath(p4_path, strlen(p4_path), file, strlen(file));
if (0 < str.length && (fp = fopen(str.string, "r")) != NULL) {
p4ResetInput(ctx, fp);
ctx->input->path = file;
rc = p4Repl(ctx, P4_THROW_OK);
(void) fclose(fp);
free(str.string);
Expand All @@ -2591,6 +2592,7 @@ p4EvalString(P4_Ctx *ctx, const char *str, size_t len)
input->length = len;
input->offset = 0;
input->blk = 0;
input->path = "about:input/string";
rc = p4Repl(ctx, P4_THROW_OK);
P4_INPUT_POP(ctx->input);
return rc;
Expand Down
1 change: 1 addition & 0 deletions src/post4.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ typedef struct {
P4_Uint blk; /* If 0< then buffer is a block and this is the block number. */
P4_Size length; /* Length of input in buffer. */
P4_Size offset; /* Offset of unconsumed input. */
const char * path;
char * buffer;
char data[P4_INPUT_SIZE];
} P4_Input;
Expand Down
23 changes: 12 additions & 11 deletions src/post4.p4
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ BEGIN-STRUCTURE p4_input
FIELD: in.blk
FIELD: in.length
FIELD: in.offset
FIELD: in.path \ pointer
FIELD: in.buffer \ pointer
/pad +FIELD in.data
END-STRUCTURE
Expand Down Expand Up @@ -1998,14 +1999,12 @@ VARIABLE SCR
\ X/Open PATH_MAX, see limits.h
1024 CONSTANT path_max

VARIABLE _source_path_length
path_max BUFFER: _source_path
VARIABLE _source_base_path_length
path_max BUFFER: _source_base_path

\ (S: -- sd.path )
: source-path _source_path _source_path_length @ ;
: source-base-path _source_base_path _source_base_path_length @ ;
: source-path _input_ptr @ in.path @ DUP strlen ; $02 _pp!
: source-base-path _source_base_path _source_base_path_length @ ; $02 _pp!

\ (S: ( sd.path caddr uaddr -- )
: set-filepath
Expand All @@ -2014,19 +2013,21 @@ path_max BUFFER: _source_base_path
; $20 _pp!

\ (S: sd.path -- )
: set-source-path _source_path _source_path_length set-filepath ;
: set-source-base-path _source_base_path _source_base_path_length set-filepath ;
: set-source-base-path _source_base_path _source_base_path_length set-filepath ; $20 _pp!

\ (S: i*x caddr u fd -- j*x )
: _include_file
_input_push -rot DROP _input_ptr @ in.path !
DUP >R ['] _eval_file CATCH R> CLOSE-FILE DROP _input_pop THROW
; $30 _pp!

\ (S: i*x fd -- j*x )
\ *** An uncaught exception within the include file will leak the file
\ *** handle and some memory.
: INCLUDE-FILE
_input_push DUP >R ['] _eval_file CATCH
R> CLOSE-FILE DROP _input_pop THROW
; $10 _pp!
: INCLUDE-FILE s" " _include_file ; $10 _pp!

\ (S: i*x caddr u -- j*x )
: INCLUDED 2DUP set-source-path R/O OPEN-FILE THROW INCLUDE-FILE ; $20 _pp!
: INCLUDED 2DUP R/O OPEN-FILE THROW _include_file ; $20 _pp!

\ (S: i*x caddr u -- j*x )
: included-path
Expand Down
1 change: 1 addition & 0 deletions test/data/source_path.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cr source-path type cr
2 changes: 1 addition & 1 deletion test/file.p4
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test_group_end

.( GH-86 source-base-path ) test_group
t{ source-base-path s" source-base-path" evaluate compare 0= -> true }t
ts{ source-path s" ../test/data/empty.p4" included source-path compare 0= -> true }t
ts{ source-path s" ../test/data/source_path.p4" included source-path compare 0= -> true }t
test_group_end

rm_file_access
Expand Down

0 comments on commit 4f6fbc2

Please sign in to comment.