<commit_before># This file is part of NIT (http://www.nitlanguage.org).
#
# Copyright 2011 <NAME> <<EMAIL>>
#
# 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 to manage standard C signals
#
# Common usage imply 5 steps:
#
# 1. Implement the `SignalHandler` interface
# 2. `redef receive_signal_unsafe` to handle `sigsegv`
# 3. `redef receive_signal` to handle other signals safely
# 4, Notify what signals to handle with `handle_signal`
# 5. If using the safe handler method, routinely call `check_signals`
#
# Usage example:
#
# ~~~~
# class MyReceiver
#	super SignalHandler
#
#	redef fun receive_signal(signal)
#	do
#		print "received safely {signal}"
#		if signal == sigalarm then print "Alarm!"
#	end
#	redef fun receive_signal_unsafe( signal ) do print "received unsafely {signal}"
# end
#
# var r = new MyReceiver
#
# # Handle `sigsegv` signal unsafely (the only way for this one)
# r.handle_signal(sigsegv, false)
#
# # Handle `sigint` and `sigalarm` safely
# r.handle_signal(sigint, true)
# r.handle_signal(sigalarm, true)
#
# # Ask system to receive a `sigalarm` signal in 1 second
# set_alarm(1)
#
# loop
#	# Check signals and callback `receive_signal`
#	var hit = check_signals
#
#	if hit then break
# end
# ~~~~
module signals

`{
	#undef _POSIX_SOURCE
	#define _POSIX_SOURCE 1
	#include <signal.h>
	#include <stdio.h>

	/*
	*/
	void (*nit_SignalHandler_receive_signal)(void* self, long signal);

	/*
		Structure to manage each possible signals
		are used in an array of 32 maximum signals.
		This array is global to the software.
	*/
	struct nit_signals_ent {
		char raised; /* !=0 if has been raised */
		void* handler; /* instance to receive call */
		char safely; /* if !=0 then manage signal safely, otherwise react when raised */
	} nit_signals_list[32] = {0x0};

	/* Receiver to all signals
		If unsafe, it calls directly the Nit receiver,
		otherwise it marks the signal as raised and returns.
	*/
	void receiver(int sig)
	{
		if (sig < 32 && sig >=0)
		{
			if (nit_signals_list[sig].safely) {<commit_msg>lib/signals: fix missing import and initializer for GCC<commit_after># This file is part of NIT (http://www.nitlanguage.org).
#
# Copyright 2011 <NAME> <<EMAIL>>
#
# 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 to manage standard C signals
#
# Common usage imply 5 steps:
#
# 1. Implement the `SignalHandler` interface
# 2. `redef receive_signal_unsafe` to handle `sigsegv`
# 3. `redef receive_signal` to handle other signals safely
# 4, Notify what signals to handle with `handle_signal`
# 5. If using the safe handler method, routinely call `check_signals`
#
# Usage example:
#
# ~~~~
# class MyReceiver
#	super SignalHandler
#
#	redef fun receive_signal(signal)
#	do
#		print "received safely {signal}"
#		if signal == sigalarm then print "Alarm!"
#	end
#	redef fun receive_signal_unsafe( signal ) do print "received unsafely {signal}"
# end
#
# var r = new MyReceiver
#
# # Handle `sigsegv` signal unsafely (the only way for this one)
# r.handle_signal(sigsegv, false)
#
# # Handle `sigint` and `sigalarm` safely
# r.handle_signal(sigint, true)
# r.handle_signal(sigalarm, true)
#
# # Ask system to receive a `sigalarm` signal in 1 second
# set_alarm(1)
#
# loop
#	# Check signals and callback `receive_signal`
#	var hit = check_signals
#
#	if hit then break
# end
# ~~~~
module signals

`{
	#undef _POSIX_SOURCE
	#define _POSIX_SOURCE 1
	#include <signal.h>
	#include <stdio.h>
	#include <unistd.h>

	/*
	*/
	void (*nit_SignalHandler_receive_signal)(void* self, long signal);

	/*
		Structure to manage each possible signals
		are used in an array of 32 maximum signals.
		This array is global to the software.
	*/
	struct nit_signals_ent {
		char raised; /* !=0 if has been raised */
		void* handler; /* instance to receive call */
		char safely; /* if !=0 then manage signal safely, otherwise react when raised */
	} nit_signals_list[32] = {{0}};

	/* Receiver to all signals
		If unsafe, it calls directly the Nit receiver,
		otherwise it marks the signal as raised and returns.
	*/
	void receiver(int sig)
	{
		if (sig < 32 && sig >=0)
		{
			if (nit_signals_list[sig].safely) {
{'fraction_non_alphanumeric': 0.10263414634146341, 'fraction_numerical': 0.010731707317073172, 'mean_word_length': 4.110667996011964, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3776235', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1612, 'n_words': 643}