Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/al/proc-launch-argvs-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
CuppoJava committed Oct 7, 2024
2 parents b81e307 + b380d13 commit 634999a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion compiler/params.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public defn compiler-flags () :
to-tuple(COMPILE-FLAGS)

;========= Stanza Configuration ========
public val STANZA-VERSION = [0 18 94]
public val STANZA-VERSION = [0 18 95]
public var STANZA-INSTALL-DIR:String = ""
public var OUTPUT-PLATFORM:Symbol = `platform
public var STANZA-PKG-DIRS:List<String> = List()
Expand Down
20 changes: 14 additions & 6 deletions core/core.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -10312,16 +10312,11 @@ defn process-env-var-mode (env-vars:Tuple<KeyValue<String,String>>|False,
env-var-mode:ref<EnvVarMode>) -> ref<Process> :
ensure-valid-env-var-names!(env-vars)
ensure-valid-stream-specifiers(input, output, error)
val args = to-tuple(args0)
val proc = new Process{0, null, null, null, null, null, false, false, false, false}
val input_v = value(input).value
val output_v = value(output).value
val error_v = value(error).value
val nargs = args.length
val argvs:ptr<ptr<byte>> = call-c clib/stz_malloc((nargs + 1) * sizeof(ptr<?>))
argvs[nargs] = null
for (var i:long = 0, i < nargs, i = i + 1) :
argvs[i] = addr!(args.items[i].chars)


;Create the array of environment variable strings.
val full-env-vars = process-env-var-mode(env-vars, env-var-mode)
Expand All @@ -10333,10 +10328,23 @@ defn process-env-var-mode (env-vars:Tuple<KeyValue<String,String>>|False,
(working-dir:ref<String>) : working-dir-chars = addr!(working-dir.chars)
(working-dir:ref<False>) : working-dir-chars = null

;Pack the given arguments into flat memory as required by launch_process.
;Do this as close to launch_process as possible to avoid pointers becoming
;stale from garbage collection moving references around
val args = to-tuple(args0)
val nargs = args.length
val argvs:ptr<ptr<byte>> = call-c clib/stz_malloc((nargs + 1) * sizeof(ptr<?>))
argvs[nargs] = null
for (var i:long = 0, i < nargs, i = i + 1) :
argvs[i] = addr!(args.items[i].chars)

;Launch the process
val launch_succ = call-c clib/launch_process(addr!(filename.chars), argvs,
input_v, output_v, error_v, working-dir-chars, env-var-string, addr!([proc]))

;Free the argvs array
call-c clib/free(argvs)

;Free the memory created using malloc.
free-linux-env-var-string(env-var-string)

Expand Down

0 comments on commit 634999a

Please sign in to comment.