Skip to content

Commit

Permalink
a version supporting IDL_IDLBridge objects and methods. (gnudatalangu…
Browse files Browse the repository at this point in the history
  • Loading branch information
GillesDuvert authored Aug 22, 2024
1 parent 1c36114 commit bc3197a
Show file tree
Hide file tree
Showing 25 changed files with 1,629 additions and 355 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ exists_fun.cpp
fftw.cpp
file.cpp
fmtnode.cpp
gdl2gdl.cpp
gdlarray.cpp
gdleventhandler.cpp
gdlexception.cpp
Expand Down
12 changes: 9 additions & 3 deletions src/basic_pro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace lib {
// }

void exitgdl(EnvT* e) {

if (iAmMaster){
#if defined(HAVE_LIBREADLINE)

// we manage the ASCII "history" file (located in ~/.gdl/)
Expand Down Expand Up @@ -206,14 +206,20 @@ namespace lib {
}
}
#endif

}
sem_onexit();

//flush & close still opened files.

for (int p = 0; p < maxLun; ++p) { //and NOT userlun!
fileUnits[p].Flush();
}
}
//before stopping a client, acknowledge the last ("EXIT") command otherwise the master is hanged.
if (signalOnCommandReturn) { //cout is NOT a tty. We just send GDL_SIGUSR2 to parent
signalOnCommandReturn = false;
gdl_ipc_sendsignalToParent();
// std::cout<<"signalOnCommandReturn is now "<<signalOnCommandReturn<<std::endl;
}

BaseGDL* status = e->GetKW(1);
if (status == NULL) exit(EXIT_SUCCESS);
Expand Down
4 changes: 2 additions & 2 deletions src/basic_pro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ namespace lib {
void print_os(std::ostream* os, EnvT* e, int parOffset, SizeT width);

// in read.cpp
void read(EnvT* e);
void readf(EnvT* e);
void read_pro(EnvT* e);
void readf_pro(EnvT* e);
void reads(EnvT* e);
void read_is(std::istream* is, EnvT* e, int parOffset);

Expand Down
7 changes: 2 additions & 5 deletions src/dcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@

#include <assert.h>

//do we print all spurious informations (like "Compiled module XXX")
volatile bool iAmSilent;

using namespace std;

DCompiler::DCompiler(const string& f, EnvBaseT* e, const std::string& sub)
Expand Down Expand Up @@ -255,7 +252,7 @@ void DCompiler::EndPro() // inserts in proList
}

if(!(pro->isHidden() || pro->isGdlHidden())) { if ( subRoutine == "" || subRoutine == pro->ObjectFileName())
if (!iAmSilent) Message( "Compiled module: "+pro->ObjectName()+"."); }
Message( "Compiled module: "+pro->ObjectName()+"."); }

// reset pro // will be deleted otherwise
if( env != NULL)
Expand Down Expand Up @@ -322,7 +319,7 @@ void DCompiler::EndFun() // inserts in funList
}

if(!(pro->isHidden() || pro->isGdlHidden())) { if (subRoutine == "" || subRoutine == pro->ObjectFileName())
if (!iAmSilent) Message( "Compiled module: "+pro->ObjectName()+"."); }
Message( "Compiled module: "+pro->ObjectName()+"."); }
// reset pro // will be deleted otherwise
if( env != NULL) pro=dynamic_cast<DSubUD*>(env->GetPro()); else pro=NULL;
}
Expand Down
2 changes: 0 additions & 2 deletions src/dcompiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#include "dcommon.hpp"
#include "dnode.hpp"

extern volatile bool iAmSilent;

class GDLInterpreter;

class DCompiler: public GDLTokenTypes
Expand Down
2 changes: 1 addition & 1 deletion src/devicex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DeviceX : public GraphicsMultiDevice {
public:

DeviceX(std::string name_="X") : GraphicsMultiDevice( -1, XC_crosshair, 3, 0) {
name = name_;
name = name_;
DLongGDL origin(dimension(2));
DLongGDL zoom(dimension(2));
zoom[0] = 1;
Expand Down
40 changes: 33 additions & 7 deletions src/dinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,12 +1088,14 @@ DInterpreter::CommandCode DInterpreter::ExecuteLine( istream* in, SizeT lineOffs
// command
if( firstChar == ".")
{
if (!iAmMaster) return CC_OK;
return ExecuteCommand( line.substr(1));
}

// online help (if possible, start a browser)
if( firstChar == "?")
{
if (!iAmMaster) return CC_OK;
// later, we will have to check whether we have X11/Display or not
// on some computing nodes on supercomputers, this is de-activated.
if (line.substr(1).length() > 0) {
Expand All @@ -1108,6 +1110,7 @@ DInterpreter::CommandCode DInterpreter::ExecuteLine( istream* in, SizeT lineOffs
// shell command
if( firstChar == "#")
{
if (!iAmMaster) return CC_OK;
if (line.substr(1).length() > 0) {
line=line.substr(1);
StrTrim(line);
Expand Down Expand Up @@ -1167,6 +1170,7 @@ DInterpreter::CommandCode DInterpreter::ExecuteLine( istream* in, SizeT lineOffs
// shell command
if( firstChar == "$")
{
if (!iAmMaster) return CC_OK;
ExecuteShellCommand( line.substr(1));
return CC_OK;
}
Expand All @@ -1175,6 +1179,7 @@ DInterpreter::CommandCode DInterpreter::ExecuteLine( istream* in, SizeT lineOffs
// during compilation this is handled by the interpreter
if( firstChar == "@" && callStack.size() <= 1)
{
if (!iAmMaster) return CC_OK;
string fileRaw = line.substr(1);
StrTrim( fileRaw);

Expand Down Expand Up @@ -1447,7 +1452,19 @@ void ControlCHandler(int)
sigControlC = true;
signal(SIGINT,ControlCHandler);
}

//for child: make it send a SIGUSR2 at end of command processed
void SignalMasterHandler(int)
{
std::cout<<"SignalMasterHandler received!";
signal(GDL_SIGUSR1,SignalMasterHandler);
}
//for child: make it send a SIGUSR2 at end of command processed
void SignalChildHandler(int)
{
// std::cout<<"signalOnCommandReturn was "<<signalOnCommandReturn<<std::endl;
signalOnCommandReturn=true;
signal(GDL_SIGUSR1,SignalChildHandler);
}
string DInterpreter::GetLine()
{
clog << flush; cout << flush;
Expand All @@ -1467,11 +1484,13 @@ string DInterpreter::GetLine()
//report last math exceptions
GDLCheckFPExceptionsAtLineLevel();
#if defined(HAVE_LIBREADLINE)

if (!iAmMaster) cline = NoReadline(actualPrompt);
else {
if( edit_input != 0)
cline = readline(const_cast<char*>(actualPrompt.c_str()));
else
cline = NoReadline(actualPrompt);
}
#else

cline = NoReadline(actualPrompt);
Expand Down Expand Up @@ -1761,7 +1780,7 @@ RetCode DInterpreter::InterpreterLoop(const string& startup,
ExecuteFile(*it);
batch_files.clear(); // not needed anymore...
}

if (iAmMaster) {
#if defined(HAVE_LIBREADLINE)

// initialize readline (own version - not pythons one)
Expand Down Expand Up @@ -1808,8 +1827,11 @@ RetCode DInterpreter::InterpreterLoop(const string& startup,
historyIntialized = true;

#endif


}
else {
signalOnCommandReturn = false;
gdl_ipc_acknowledge_suprocess_started(getpid());
}
bool runCmd = false; // should tree from $MAIN$ be executed?
bool continueCmd = false; // .CONTINUE command given already?

Expand All @@ -1822,8 +1844,12 @@ RetCode DInterpreter::InterpreterLoop(const string& startup,
RunDelTree();
} else {
DInterpreter::CommandCode ret = ExecuteLine();

// stop steppig when at main level
if (signalOnCommandReturn) { //cout is NOT a tty. We just send GDL_SIGUSR2 to parent
signalOnCommandReturn = false;
gdl_ipc_sendsignalToParent();
// std::cout<<"signalOnCommandReturn is now "<<signalOnCommandReturn<<std::endl;
}
// stop stepping when at main level
stepCount = 0;
debugMode = DEBUG_CLEAR;

Expand Down
19 changes: 18 additions & 1 deletion src/dinterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
#include <fstream>
#include <csignal>

#if defined(_WIN32) && !defined(__CYGWIN__)
#define GDL_SIGUSR1 SIGABRT //working replacement avoidng changing code?
#define GDL_SIGUSR2 SIGILL
extern int gdl_ipc_sendsignalToParent();
extern void gdl_ipc_acknowledge_suprocess_started(long long pid);
#else
#define GDL_SIGUSR1 SIGUSR1
#define GDL_SIGUSR2 SIGUSR2
extern int gdl_ipc_sendsignalToParent();
extern int gdl_ipc_sendCtrlCToChild(int pid);
extern int gdl_ipc_sendsignalToChild(int pid);
extern int gdl_ipc_SetReceiverForChildSignal(void (* handler)(int sig, siginfo_t *siginfo, void *context));
extern void gdl_ipc_acknowledge_suprocess_started(pid_t pid);
#endif

#include <cfenv>

#include "GDLLexer.hpp"
Expand All @@ -44,6 +59,8 @@
#define AUTO_PRINT_EXPR

void ControlCHandler(int);
void SignalChildHandler(int);
void SignalMasterHandler(int);

extern bool lineEdit; // = false;
extern bool historyIntialized;
Expand Down Expand Up @@ -83,7 +100,7 @@ class DInterpreter: public GDLInterpreter
{
#if defined(HAVE_LIBREADLINE)
// seems to cause valgrind to complain
clear_history(); // for testing of memory leaks (in GDL)
if (iAmMaster) clear_history(); // for testing of memory leaks (in GDL)
#endif
}

Expand Down
Loading

0 comments on commit bc3197a

Please sign in to comment.