<commit_before>/***********************************************************************
**
**  REBOL [R3] Language Interpreter and Run-time Environment
**
**  Copyright 2012 REBOL Technologies
**  Copyright 2014 Atronix Engineering, Inc.
**  REBOL is a trademark of REBOL Technologies
**
**  Licensed under the Apache License, Version 2.0 (the "License");
**  you may not use this file except in compliance with the License.
**  You may obtain a copy of the License at
**
**  http://www.apache.org/licenses/LICENSE-2.0
**
**  Unless required by applicable law or agreed to in writing, software
**  distributed under the License is distributed on an "AS IS" BASIS,
**  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
**  See the License for the specific language governing permissions and
**  limitations under the License.
**
************************************************************************
**
**  Module:  p-signal.c
**  Summary: signal port interface
**  Section: ports
**  Author:  <NAME>
**  Notes:
**
***********************************************************************/

#include "sys-core.h"

#ifdef HAS_POSIX_SIGNAL
#include <sys/signal.h>

static void update(REBREQ *req, REBINT len, REBVAL *arg)
{
    const siginfo_t *sig = cast(siginfo_t *, req->common.data);
    int i = 0;
    const REBYTE signal_no[] = "signal-no";
    const REBYTE code[] = "code";
    const REBYTE source_pid[] = "source-pid";
    const REBYTE source_uid[] = "source-uid";

    Extend_Series(VAL_SERIES(arg), len);

    for (i = 0; i < len; i ++) {
        REBCTX *obj = Alloc_Context(2);
        REBVAL *val = Append_Context(
            obj, NULL, Make_Word(signal_no, LEN_BYTES(signal_no))
        );
        SET_INTEGER(val, sig[i].si_signo);

        val = Append_Context(
            obj, NULL, Make_Word(code, LEN_BYTES(code))
        );
        SET_INTEGER(val, sig[i].si_code);
        val = Append_Context(
            obj, NULL, Make_Word(source_pid, LEN_BYTES(source_pid))
        );
        SET_INTEGER(val, sig[i].si_pid);
        val = Append_Context(
            obj, NULL, Make_Word(source_uid, LEN_BYTES(source_uid))
        );
        SET_INTEGER(val, sig[i].si_uid);

        Val_Init_Object(VAL_ARRAY_AT_HEAD(arg, VAL_LEN_HEAD(arg) + i), obj);
    }

    SET_SERIES_LEN(VAL_SERIES(arg), VAL_LEN_HEAD(arg) + len);

    req->actual = 0; /* avoid duplicate updates */
}

static int sig_word_num(REBVAL *word)
{
    switch (VAL_WORD_CANON(word)) {
        case SYM_SIGALRM:
            return SIGALRM;
        case SYM_SIGABRT:
            return SIGABRT;
        case SYM_SIGBUS:<commit_msg>Properly initialize the object!<commit_after>/***********************************************************************
**
**  REBOL [R3] Language Interpreter and Run-time Environment
**
**  Copyright 2012 REBOL Technologies
**  Copyright 2014 Atronix Engineering, Inc.
**  REBOL is a trademark of REBOL Technologies
**
**  Licensed under the Apache License, Version 2.0 (the "License");
**  you may not use this file except in compliance with the License.
**  You may obtain a copy of the License at
**
**  http://www.apache.org/licenses/LICENSE-2.0
**
**  Unless required by applicable law or agreed to in writing, software
**  distributed under the License is distributed on an "AS IS" BASIS,
**  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
**  See the License for the specific language governing permissions and
**  limitations under the License.
**
************************************************************************
**
**  Module:  p-signal.c
**  Summary: signal port interface
**  Section: ports
**  Author:  <NAME>
**  Notes:
**
***********************************************************************/

#include "sys-core.h"

#ifdef HAS_POSIX_SIGNAL
#include <sys/signal.h>

static void update(REBREQ *req, REBINT len, REBVAL *arg)
{
    const siginfo_t *sig = cast(siginfo_t *, req->common.data);
    int i = 0;
    const REBYTE signal_no[] = "signal-no";
    const REBYTE code[] = "code";
    const REBYTE source_pid[] = "source-pid";
    const REBYTE source_uid[] = "source-uid";

    Extend_Series(VAL_SERIES(arg), len);

    for (i = 0; i < len; i ++) {
        REBCTX *obj = Alloc_Context(8);
        REBVAL *val = Append_Context(
            obj, NULL, Make_Word(signal_no, LEN_BYTES(signal_no))
        );
        SET_INTEGER(val, sig[i].si_signo);

        val = Append_Context(
            obj, NULL, Make_Word(code, LEN_BYTES(code))
        );
        SET_INTEGER(val, sig[i].si_code);
        val = Append_Context(
            obj, NULL, Make_Word(source_pid, LEN_BYTES(source_pid))
        );
        SET_INTEGER(val, sig[i].si_pid);
        val = Append_Context(
            obj, NULL, Make_Word(source_uid, LEN_BYTES(source_uid))
        );
        SET_INTEGER(val, sig[i].si_uid);

        // context[0] is an instance value of the OBJECT!/PORT!/ERROR!/MODULE!
        //
        VAL_INIT_WRITABLE_DEBUG(CTX_VALUE(obj));
        VAL_RESET_HEADER(CTX_VALUE(obj), REB_OBJECT);

        CTX_VALUE(obj)->payload.any_context.context = obj;
        VAL_CONTEXT_SPEC(CTX_VALUE(obj)) = NULL;
        VAL_CONTEXT_STACKVARS(CTX_VALUE(obj)) = NULL;

        val = Alloc_Tail_Array(VAL_ARRAY(arg));
        Val_Init_Object(val, obj);
    }

    req->actual = 0; /* avoid duplicate updates */
}

static int sig_word_num(REBVAL *word)
{
    switch (VAL_WORD_CANON(word)) {
        case SYM_SIGALRM:
            return SIGALRM;
        case SYM_SIGABRT:
            return SIGABRT;
        case SYM_SIGBUS:
{'fraction_non_alphanumeric': 0.18651362984218078, 'fraction_numerical': 0.006276901004304161, 'mean_word_length': 3.3132250580046403, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1506121', 'n_tokens_mistral': 1786, 'n_tokens_neox': 1733, 'n_words': 462}