Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RUN-PROGRAM failing if an output file doesn't exist. #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ivan4th
Copy link

@ivan4th ivan4th commented Dec 12, 2014

If a pathname is passed as :OUTPUT or as :ERROR to RUN-PROGRAM, the
target file is created if it doesn't exist. The problem was that when
:IF-OUTPUT-EXISTS / :IF-ERROR-EXISTS is also specified, RUN-PROGRAM
signaled an error if the file cannot be found. This behavior is caused
by NIL being passed as :IF-DOES-NOT-EXIST argument to OPEN, so let's fix
it by explicitly passing :IF-DOES-NOT-EXIST :CREATE.

An example:

(sb-ext:run-program
 "ls" '("/tmp/")
 :search t
 :output #p"/tmp/out.txt"
 :if-output-exists :overwrite)

If /tmp/out.txt doesn't exist, an error is signalled unless you remove :if-output-exists :overwrite.

If a pathname is passed as :OUTPUT or as :ERROR to RUN-PROGRAM, the
target file is created if it doesn't exist. The problem was that when
:IF-OUTPUT-EXISTS / :IF-ERROR-EXISTS is also specified, RUN-PROGRAM
signaled an error if the file cannot be found. This behavior is caused
by NIL being passed as :IF-DOES-NOT-EXIST argument to OPEN, so let's fix
it by explicitly passing :IF-DOES-NOT-EXIST :CREATE.
@attila-lendvai
Copy link
Contributor

still happens on:

(lisp-implementation-version)
"1.2.15.6.hu.dwim.2-64928b0"

@epipping
Copy link

epipping commented Sep 1, 2016

There is no bug here. You should be passing :supersede instead of :overwrite if you don't want an error to be raised. Please see also https://bugs.launchpad.net/sbcl/+bug/789817/comments/1

@epipping
Copy link

epipping commented Oct 26, 2016

I still think that this is not the right fix but withdraw my claim that there is no bug here. Please see also https://bugs.launchpad.net/sbcl/+bug/789817/comments/2

@attila-lendvai
Copy link
Contributor

still happens on 1.3.12

lichtblau pushed a commit that referenced this pull request May 22, 2018
The concept remains, but the previous implementation caused the compiler to trip
over its own shoelaces while trying to walk (pun intended), and caused code
analyzers to go awry.  It's near impossible to produce a minimal reduction
because by definition all examples seem to involve a lot of hair: macros that
expand inside-out by MACROEXPANDing their arguments, and somehow accidentally
misled the compiler to thinking that the inside code was toplevel.

The failures in previously working code were several. One was an attempt by
the compiler to call GET-DEFINED-FUN on macrolets (redacted backtrace below),
which causes an error in source-path finding, which we might want to fix as a
bug in its own right, except that it goes away after this patch.

Attempting to hack around that in IR1-CONVERT-LAMBDALIKE by simply never calling
GET-DEFINED-FUN on things named (MACROLET x) produces a different error, which
is the attempt to store (MACROLET mumble) into a %DEBUG-NAME of a CLAMBDA:
 'The value (MACROLET mumble) is not of type (OR NULL (NOT (SATISFIES SB-INT:LEGAL-FUN-NAME-P)))
 when setting slot SB-C::%DEBUG-NAME of structure SB-C::CLAMBDA'

So this changes removes MACROLET as a legal fun name, which makes it never reach
the named lambda case in IR1-CONVERT-LAMBDALIKE, and moreover, MAKE-MACRO-LAMBDA
never returns a top-level-ish lambda from a type derivation perspective.
I can't explain why these never mattered, because it sure looks as if named
macro lambdas always went through the named-lambda path that global functions
did. But at exactly the change which introduced TOP-LEVEL-NAMED-LAMBDA,
without this patch, we would see in various guises:

 SB-INT:INVALID-ARRAY-INDEX-ERROR: Invalid index 41 for (SIMPLE-VECTOR 1), should be
 a non-negative integer below 1. while executing: COMPILE
Unhandled SB-INT:INVALID-ARRAY-INDEX-ERROR in thread #<SB-THREAD:THREAD "main thread" RUNNING {10006F05B3}>:
Invalid index 41 for (SIMPLE-VECTOR 1), should be a non-negative integer below 1.
Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {10006F05B3}>
0: (SB-C::FIND-SOURCE-ROOT 41 #<SB-C::SOURCE-INFO {100F483203}>)
1: (SB-C::FIND-ORIGINAL-SOURCE (#1=(SB-C::%FUNCALL #2=#:G23 . #3=(#:G22))
    #4=(LET ((#5=#:VAL26 #1#)) (UNLESS #5# (RETURN-FROM #6=#:BLOCK24 NIL)))
         (BLOCK #7=#:WRAPPER25 . #8=(#4#)) ...))
2: (SB-C::FIND-ERROR-CONTEXT ((MACROLET DEFINE-mumble)) NIL)
3: (SB-C::NOTE-UNDEFINED-REFERENCE (MACROLET DEFINE-mumble) :FUNCTION)
4: (SB-C::FIND-GLOBAL-FUN (MACROLET DEFINE-mumble) NIL)
5: (SB-C::FIND-FREE-FUN (MACROLET DEFINE-mumble) "shouldn't happen! (defined-fun)")
6: (SB-C::GET-DEFINED-FUN (MACROLET DEFINE-mumble) (#:EXPR #:ENV))
7: (SB-C::IR1-CONVERT-LAMBDALIKE (SB-INT:NAMED-LAMBDA (MACROLET DEFINE-mumble)
     (#1=#:EXPR #2=#:ENV) (DECLARE (IGNORE #2#))
       (DECLARE (OPTIMIZE (SB-EXT:INHIBIT-WARNINGS 1))) ...))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants