Skip to content

Commit

Permalink
Merge branch 'develop' into 'main'
Browse files Browse the repository at this point in the history
New GDX release 7.11.4 for GAMS 47.*

See merge request devel/gdx!58
  • Loading branch information
LutzWestermann committed Jun 10, 2024
2 parents 2598d26 + a4a7d85 commit 73c01a9
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ build-dac:

build-wei:
stage: build
tags: [windows]
tags: [pond]
image:
name: $MACHINES_CONTAINER_REG/wei/builder-full:latest
script:
Expand Down Expand Up @@ -252,7 +252,7 @@ test-dac:

test-wei:
stage: test
tags: [windows]
tags: [pond]
image:
name: $MACHINES_CONTAINER_REG/wei/builder-full:latest
needs: [build-wei,install-gamsdist-wei]
Expand Down
2 changes: 2 additions & 0 deletions base-units.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ set(base-units
src/rtl/p3utils.h
src/rtl/sysutils_p3.cpp
src/rtl/sysutils_p3.h
src/rtl/system_p3.cpp
src/rtl/system_p3.h
src/rtl/p3platform.cpp
src/rtl/p3platform.h
src/rtl/math_p3.cpp
Expand Down
2 changes: 2 additions & 0 deletions changelog.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
- 7.11.4:
- Multiple small fixes to infrastructure code and shared modules.
- 7.11.3:
- Reworked internally used file IO streams to utilize low-level WinAPI/POSIX functions instead of the more heavyweight std::fstream.
- Use more efficient integer to string conversion procedure for tracing outputs.
Expand Down
2 changes: 1 addition & 1 deletion src/gdlib/gfileopen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static void ReportRetry( std::string_view Func, std::string_view fn, TfoAction A
// TODO: Reduce usage of std::fstream for performance reasons!
static int TextFileOpenRetry( const std::string &fn, bool ReTry, TfoAction Action, std::fstream &FileHandle, int &IORes )
{
uint32_t Delay {};
uint32_t Delay {10};
int res {};
IORes = 0;
int IORes1;
Expand Down
9 changes: 7 additions & 2 deletions src/gdlib/gmslist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,11 @@ void TGmsList::WrPChar( const char *P, int L )

void TGmsList::WrPCharLn( const int LineNr, const bool ShowLineNr, const char *Ps, const int L, const std::string &DsErrors )
{
auto maybeCaseAction = [this](char ch) {
if( CaseAction == casNone ) return ch;
return CaseAction == casToUpper ? (char) utils::toupper( ch ) : (char) utils::tolower( ch );
};

auto WritePartialLine = [&]( const char *Str, const int Start, const int Length, int &NextPos ) {
int p { Start };
const auto Corr { PageControl == pcFortran ? 1 : 0 };
Expand All @@ -809,7 +814,7 @@ void TGmsList::WrPCharLn( const int LineNr, const bool ShowLineNr, const char *P
if( k == 1 )
{
//SysChWrite( Str[p] );
buf[i++] = Str[p];
buf[i++] = maybeCaseAction(Str[p]);
}
else
{
Expand All @@ -820,7 +825,7 @@ void TGmsList::WrPCharLn( const int LineNr, const bool ShowLineNr, const char *P
}

//SysChWrite( Str[p] );
buf[i++] = Str[p];
buf[i++] = maybeCaseAction(Str[p]);

if( p == FUserRightMargin )
{
Expand Down
6 changes: 5 additions & 1 deletion src/gdlib/statlibobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ void TGMSLogStream::LogClose()
if( FSaveAstat == 4 )
std::fflush( stdout );
#endif
//Ffcon->close();
if( FStatus == sl_file || FSaveAstat == 1 )
{
std::fclose( Ffcon );
Ffcon = nullptr;
}
}
FStatus = sl_closed;
}
Expand Down
17 changes: 16 additions & 1 deletion src/global/modhead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,26 @@
*/

#include "modhead.h"
#include "rtl/sysutils_p3.h"

using namespace std::literals::string_literals;

namespace global::modhead
{
#if defined(__IN_CPPMEX__)
std::ofstream stubofs { "stubwarnings.txt" };
SWStream::SWStream() : std::ofstream { fn }, start { tellp() }
{
}

SWStream::~SWStream()
{
const bool nothingWritten { tellp() == start };
close();
if( nothingWritten )
rtl::sysutils_p3::DeleteFileFromDisk( fn );
}

SWStream stubofs;
#else
std::ofstream stubofs;
#endif
Expand Down
12 changes: 12 additions & 0 deletions src/global/modhead.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,17 @@

namespace global::modhead
{
#if defined( __IN_CPPMEX__ )
class SWStream final : public std::ofstream
{
std::streampos start;
const std::string fn { "stubwarnings.txt" };
public:
SWStream();
~SWStream() override;
};
extern SWStream stubofs;
#else
extern std::ofstream stubofs;
#endif
}
74 changes: 55 additions & 19 deletions src/rtl/p3utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1721,67 +1721,103 @@ T_P3SOCKET p3SockCreateServerSocket( int port, bool reuse )
{
T_P3SOCKET res {};
mkInvalidSock( res );
#if defined(_WIN32)
const auto acceptSocket { socket(AF_INET, SOCK_STREAM, 0) };
#if defined( _WIN32 )
const auto acceptSocket { socket( AF_INET, SOCK_STREAM, 0 ) };
if( INVALID_SOCKET == acceptSocket ) return res;
if (reuse) {
int enable{1};
if( reuse )
{
int enable { 1 };
// without this magic Windows will bar connections to this port for a small time window
// after the socket is closed to avoid delayed packets from a previous connection going to
// any new connections
if( setsockopt( acceptSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &enable, sizeof( int ) ) )
return res;
}
SOCKADDR_IN addr;
(void)std::memset( &addr, 0, sizeof( addr ) );
(void) std::memset( &addr, 0, sizeof( addr ) );
addr.sin_family = AF_INET;
addr.sin_port = htons( port );
addr.sin_addr.s_addr = inet_addr( "127.0.0.1" );
int rc {bind( acceptSocket, (SOCKADDR *) &addr, sizeof(addr)) };
if (rc == SOCKET_ERROR) {
int rc { bind( acceptSocket, (SOCKADDR *) &addr, sizeof( addr ) ) };
if( rc == SOCKET_ERROR )
{
closesocket( acceptSocket );
return res;
}
rc = listen( acceptSocket, 5 );
if (rc == SOCKET_ERROR) {
if( rc == SOCKET_ERROR )
{
closesocket( acceptSocket );
return res;
}
res.wsocket = acceptSocket;
#else
sockaddr_in servaddr {};
const int sockfd {socket(AF_INET, SOCK_STREAM, 0)};
if(sockfd == -1) return res;
if(reuse)
const int sockfd { socket( AF_INET, SOCK_STREAM, 0 ) };
if( sockfd == -1 ) return res;
if( reuse )
{
int enable{1};
int enable { 1 };
// without this magic Linux/Mac will bar connections to this port for a small time window
// after the socket is closed to avoid delayed packets from a previous connection going to
// any new connections
if(setsockopt( sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable) ))
if( setsockopt( sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof( enable ) ) )
return res;
}
(void)std::memset(&servaddr, 0, sizeof(servaddr));
(void) std::memset( &servaddr, 0, sizeof( servaddr ) );
// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
servaddr.sin_port = htons(port);
servaddr.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
servaddr.sin_port = htons( port );

if(bind(sockfd, reinterpret_cast<sockaddr *>( &servaddr ), sizeof(servaddr)))
if( bind( sockfd, reinterpret_cast<sockaddr *>( &servaddr ), sizeof( servaddr ) ) )
{
(void)close(sockfd);
(void) close( sockfd );
return res;
}
if( listen( sockfd, 5 ) )
{
(void)close(sockfd);
(void) close( sockfd );
return res;
}
res.socketfd = sockfd;
#endif
return res;
}

// determine port assigned to socket from OS
// useful in case bind was called with port=0
// RETURNS
// port number on success.
// -1 on failure: e.g. incorrect inputs or networking subsystem not initialized.
// if the function returns a port number >=0 res is not set.
// if the function returns -1:
// *res: errno or WSAGetLastError value
int p3SockGetPort( T_P3SOCKET s, int &res )
{
int result{-1};
sockaddr_in addr {};
int rc;
#if defined(_WIN32)
int addrLen = sizeof(sockaddr_in);
rc = getsockname(s.wsocket, (SOCKADDR*)&addr, &addrLen);
if(rc)
{
res = WSAGetLastError();
return -1;
}
#else
socklen_t addrLen = sizeof(sockaddr_in);
rc = getsockname(s.socketfd, (sockaddr*)&addr, &addrLen);
if(rc)
{
res = errno;
return -1;
}
#endif
result = ntohs(addr.sin_port);
return result;
}
#endif // __IN_CPPMEX__

}// namespace rtl::p3utils
2 changes: 2 additions & 0 deletions src/rtl/p3utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ bool p3SockRecvTimeout(T_P3SOCKET s, char *buf, int count, int &res, int timeOut

T_P3SOCKET p3SockAcceptClientConn(T_P3SOCKET srvSock);
T_P3SOCKET p3SockCreateServerSocket(int port, bool reuse);

int p3SockGetPort(T_P3SOCKET s, int &res);
#endif // __IN_CPPMEX__

// ...
Expand Down
37 changes: 37 additions & 0 deletions src/rtl/system_p3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "system_p3.h"

#if defined(_WIN32)
#include <Windows.h>
#else
#include <unistd.h>
#endif

namespace rtl::system_p3 {

void getdir(uint8_t d, std::string &s)
{
#if defined(_WIN32)
char Drive[3], DirBuf[MAX_PATH], SaveBuf[MAX_PATH];
if (d) {
Drive[0] = 'A' + d - 1;
Drive[1] = ':';
Drive[2] = '\0';
GetCurrentDirectoryA(sizeof(SaveBuf), SaveBuf);
SetCurrentDirectoryA(Drive);
}
GetCurrentDirectoryA(sizeof(DirBuf), DirBuf);
if (d) SetCurrentDirectoryA(SaveBuf);
s.assign(DirBuf);
#else
char DirBuf[512];
if( const char *p { getcwd( DirBuf, sizeof( DirBuf ) ) }; !p )
{
// this is unlikely, and not handled well here: exceptions?
s.clear();
return;
}
s.assign( DirBuf );
#endif
}

}
10 changes: 10 additions & 0 deletions src/rtl/system_p3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <cstdint>
#include <string>

namespace rtl::system_p3 {

void getdir(uint8_t d, std::string &s);

}

0 comments on commit 73c01a9

Please sign in to comment.