Skip to content

Commit

Permalink
Merge pull request #457 from jstuder-gh/sig_hash_to_arr
Browse files Browse the repository at this point in the history
Change getsignals output from hash to array
  • Loading branch information
AlexDaniel committed Jun 12, 2018
2 parents f9fa88d + 5cea99a commit de99ca5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions docs/ops.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2481,16 +2481,16 @@ Changing the hash doesn't affect the environment variables
## getsignals
* `getsignals(--> Mu)`

Returns a hash containing signal names mapped to the proper signum integer on
the host platform (MacOSX, Linux, BSD, etc).
Returns a list containing signal names interleaved with the associated signum
integer on the host platform (MacOSX, Linux, BSD, etc).

If the current backend does not support the registering of a signal handler for
a given signal, the hash value will be a negative integer. For instance, the JVM
only supports signal handlers for SIGINT and SIGKILL, so all the values will be
negative except 2 (SIGINT) and 9 (SIGKILL). If a signal is not available on the
host system, the hash value will be set to 0.

The complete list of hash keys is as follows:
The complete list of signal entries is as follows:

* SIGHUP
* SIGINT
Expand Down
2 changes: 1 addition & 1 deletion src/vm/js/Operations.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class QAST::OperationsJS {
add_simple_op('chmod', $T_VOID, [$T_STR, $T_INT], :side_effects);

add_simple_op('getenvhash', $T_OBJ, [], :side_effects);
add_simple_op('getsignals', $T_OBJ, [], :side_effects);
add_simple_op('getsignals', $T_OBJ, [], :side_effects, :takes_hll);
add_simple_op('cwd', $T_STR, [], :side_effects);


Expand Down
10 changes: 7 additions & 3 deletions src/vm/js/nqp-runtime/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const Hash = require('./hash.js');

const core = require('./core.js');

const hll = require('./hll.js');

const child_process = require('child_process');

const NQPObject = require('./nqp-object.js');
Expand Down Expand Up @@ -548,7 +550,7 @@ op.permit = function(handle, channel, permits) {
};

let sigCache = null;
op.getsignals = function() {
op.getsignals = function(currentHLL) {
if (sigCache) {
return sigCache;
}
Expand All @@ -575,10 +577,12 @@ op.getsignals = function() {
'SIGUSR2', 'SIGTHR', 'SIGSTKFLT', 'SIGPWR', 'SIGBREAK',
];

const res = new Hash();
const arr = [];
for (const k of sigWanted) {
res.content.set( k, new NQPInt(k in osSigs ? osSigs[k] : 0) );
arr.push( new NQPStr(k), new NQPInt(k in osSigs ? osSigs[k] : 0) );
}

const res = hll.slurpyArray(currentHLL, arr);
sigCache = res;
return res;
};
14 changes: 8 additions & 6 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/IOOps.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static Map<String, Integer> build() {
}
private static final Map<String, Integer> sigSupported = SigSupported.build();

private static final List<String> sigKeys = Arrays.asList(
public static final List<String> sigKeys = Arrays.asList(
"SIGHUP", "SIGINT", "SIGQUIT", "SIGILL", "SIGTRAP", "SIGABRT",
"SIGEMT", "SIGFPE", "SIGKILL", "SIGBUS", "SIGSEGV", "SIGSYS",
"SIGPIPE", "SIGALRM", "SIGTERM", "SIGURG", "SIGSTOP", "SIGTSTP",
Expand Down Expand Up @@ -132,16 +132,18 @@ public static Map<String, Integer> process() {
public static SixModelObject getsignals(ThreadContext tc) {
if (sigCache != null) return sigCache;

SixModelObject hashType = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig.hashType;
SixModelObject listType = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig.listType;
SixModelObject strType = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig.strBoxType;
SixModelObject intType = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig.intBoxType;
SixModelObject res = hashType.st.REPR.allocate(tc, hashType.st);
SixModelObject res = listType.st.REPR.allocate(tc, listType.st);

Map<String, Integer> sigWanted = SigProcess.process();

// Box the hash values for HLL
for (String sig : sigWanted.keySet()) {
// Box the list values for HLL
for (String sig : SigProcess.sigKeys) {
long signum = (long)sigWanted.get(sig);
res.bind_key_boxed( tc, sig, Ops.box_i(signum, intType, tc) );
res.push_boxed( tc, Ops.box_s(sig, strType, tc) );
res.push_boxed( tc, Ops.box_i(signum, intType, tc) );
}
sigCache = res;
return res;
Expand Down

0 comments on commit de99ca5

Please sign in to comment.