From 05652ac4e8b8685fe0c0f4ee2f75516d28bbf892 Mon Sep 17 00:00:00 2001 From: Gaius Mulley Date: Sat, 25 Feb 2023 16:28:19 +0000 Subject: modula-2 module registration process seems to fail with shared libraries [PR108261] The commit adds pathnames to modula-2 which in turn appears in any external symbol. This is necessary to allow different dialects of libraries to coexist (different implementations of SYSTEM and Storage for example in libm2pim and libm2iso). It also makes it easier to debug as the library name forms part of the external mangled name. By default pathnames are not user facing. This commit fixes PR108261. gcc/ChangeLog: PR modula2/108261 * doc/gm2.texi (-fm2-pathname): New option documented. (-fm2-pathnameI): New option documented. (-fm2-prefix=): New option documented. (-fruntime-modules=): Update default module list. gcc/m2/ChangeLog: PR modula2/108261 * Make-lang.in (GM2-COMP-BOOT-DEFS): DynamicStringPath.def remove. DynamicPath.def add. (GM2-COMP-BOOT-MODS): DynamicStringPath.mod remove. DynamicPath.mod add. * Make-maintainer.in (BUILD-BOOT-PPG-H): New dependency. (m2/gm2-ppg-boot/$(SRC_PREFIX)%.o): $(BUILD-BOOT-PPG-H) Add dependency. (PGE-DEF): New definition. (BUILD-BOOT-PG-H): New dependency. (m2/gm2-pg-boot/$(SRC_PREFIX)%.o): $(BUILD-BOOT-PG-H) Add dependency. (BUILD-BOOT-PGE-H): New dependency. (m2/gm2-pge-boot/$(SRC_PREFIX)%.o): $(BUILD-BOOT-PGE-H) Add dependency. (GM2PATH): Add pathname entries. (m2/boot-bin/mc-devel$(exeext)): Add m2/mc-boot-ch/Gm2rtsdummy.o dependency. (m2/boot-bin/mc-opt$(exeext)): Fix -I path. * gm2-compiler/DynamicStringPath.def: Renamed module to DynamicPath. (GetUserPath): Remove. (GetSystemPath): Remove. (SetUserPath): Remove. (SetSystemPath): Remove. (DumpPath): New procedure definition. * gm2-compiler/DynamicStringPath.mod: Renamed module to DynamicPath. (GetUserPath): Remove. (GetSystemPath): Remove. (SetUserPath): Remove. (SetSystemPath): Remove. (DumpPath): Remove Debugging conditional. * gm2-compiler/M2AsmUtil.mod: Import EqualArray, NulName and GetLibName. (Debugging): New declaration. (GetFullSymName): Re-implemented to prefix (mange) libname to any extern variable/procedure which is IsExportQualified. * gm2-compiler/M2Comp.mod (qprintLibName): New procedure. * gm2-compiler/M2Graph.mod (resolveImports): Add libname. * gm2-compiler/M2Options.def (SetM2Prefix): New procedure. (GetM2Prefix): New procedure function. (SetM2PathName): New procedure. (GetM2PathName): New procedure function. * gm2-compiler/M2Options.mod: (SetM2Prefix): New procedure implemented. (GetM2Prefix): New procedure function implemented. (SetM2PathName): New procedure implemented. (GetM2PathName): New procedure function implemented. (RuntimeModuleOverride): Set to DefaultRuntimeModuleOverride. * gm2-compiler/M2Quads.mod: Import GetLibName. (SafeRequestSym) Pass result of GetLibName to RequestDependant. (callRequestDependant): Add libname as a parameter. (BuildM2InitFunction): Add libname as a parameter. (BuildM2FiniFunction): Add libname as a parameter. (BuildM2CtorFunction): Add libname as a parameter. * gm2-compiler/M2Scaffold.mod (LookupModuleSym): Set LibName if a definition source was found. * gm2-compiler/M2Search.def (FindSourceFile): Add named library parameter. (FindSourceDefFile): Add named library parameter. (FindSourceModFile): Add named library parameter. * gm2-compiler/M2Search.mod (FindSourceFile): Reimplement. (FindSourceDefFile): Add named library parameter. (FindSourceModFile): Add named library parameter. * gm2-compiler/SymbolTable.def (MakeProcedureCtorExtern): Add libname parameter. (PutLibName): New procedure. (GetLibName): New procedure function. * gm2-compiler/SymbolTable.mod (MakeProcedureCtorExtern): Add libname parameter. (GenName): Add libname parameter. (InitCtorFields): Add moduleSym as a parameter. (PutCtorExtern): Add libname parameter to GenName. * gm2-gcc/init.cc (_M2_DynamicStringPath_init): Rename function... (_M2_DynamicPath_init): ...to this. (_M2_PathName_init): Added. * gm2-gcc/m2decl.cc (m2decl_DeclareM2linkStaticInitialization): Add m2pim as the manged component of the exported symbol. (m2decl_DeclareM2linkForcedModuleInitOrder): Add m2pim mangle prefix. * gm2-gcc/m2options.h (M2Options_SetM2Prefix): New function. (M2Options_GetM2Prefix): New function. (M2Options_SetM2PathName): New function. (M2Options_GetM2PathName): New function. * gm2-lang.cc (push_back_Ipath): New function. (add_one_import_path): New function. (gm2_langhook_handle_option): Record -I component. Call SetM2PathName when -fm2-pathname= is seen. Record -fm2-pathnameI component. Call SetM2Prefix when -fm2-prefix= is seen. (gm2_langhook_post_options): Iterative over pathname entries and call SetM2PathName, SetSearchPath as appropriate. * gm2-libs-iso/M2RTS.def (ConstructModules): Add libname parameter. (DeconstructModules): Add libname parameter. (RegisterModule): Add libname parameter. (RequestDependant): Add libname parameter. * gm2-libs-iso/M2RTS.mod (ConstructModules): Add libname parameter. (DeconstructModules): Add libname parameter. (RegisterModule): Add libname parameter. (RequestDependant): Add libname parameter. * gm2-libs-min/M2RTS.def (ConstructModules): Add libname parameter. (DeconstructModules): Add libname parameter. (RegisterModule): Add libname parameter. (RequestDependant): Add libname parameter. * gm2-libs-min/M2RTS.mod (ConstructModules): Add libname parameter. (DeconstructModules): Add libname parameter. (RegisterModule): Add libname parameter. (RequestDependant): Add libname parameter. * gm2-libs/M2Dependent.def (ConstructModules): Add libname parameter. (DeconstructModules): Add libname parameter. (RegisterModule): Add libname parameter. (RequestDependant): Add libname parameter. * gm2-libs/M2Dependent.mod (ConstructModules): Add libname parameter. (DeconstructModules): Add libname parameter. (RegisterModule): Add libname parameter. (RequestDependant): Add libname parameter. * gm2-libs/M2RTS.def (ConstructModules): Add libname parameter. (DeconstructModules): Add libname parameter. (RegisterModule): Add libname parameter. (RequestDependant): Add libname parameter. * gm2-libs/M2RTS.mod (ConstructModules): Add libname parameter. (DeconstructModules): Add libname parameter. (RegisterModule): Add libname parameter. (RequestDependant): Add libname parameter. * gm2-libs/RTint.mod (FindVector): Rename variables. (initInputVector): Rename variables. (initOutputVector): Rename variables. (InitTimeVector): Rename variables. (FindVectorNo): Rename variables. (FindPendingVector): Rename variables. (ReArmTimeVector): Rename variables. (GetTimeVector): Rename variables. (AttachVector): Rename variables. (AttachVector): Rename variables. (IncludeVector): Rename variables. (ExcludeVector): Rename variables. (AddFd): Rename variables. (AddFd): Rename variables. (DumpPendingQueue): Rename variables. (stop): Remove. (activatePending): Rename variables. (Listen): Rename variables. * gm2-libs/libc.def (snprintf): New function. * gm2-libs/sckt.def: Change all exported identifiers to be export qualified. * gm2spec.cc (push_back_Ipath): New function. (add_m2_I_path): New function. (lang_specific_driver): Skip -fm2-pathname= and remember pathname. Skip -I and record the path and current pathname. Call add_m2_I_path. * lang-specs.h: Replace %{I*} with %{fm2-pathname*}. * lang.opt (-fm2-pathname=): New entry. (-fm2-pathname): New entry. (-fm2-prefix=): New entry. * mc-boot-ch/GUnixArgs.cc (_M2_UnixArgs_dep): New function. (_M2_UnixArgs_ctor::_M2_UnixArgs_ctor): New method. * mc-boot-ch/Glibc.c (libc_snprintf): New function. * mc-boot-ch/m2rts.h (M2RTS_RequestDependant): Changed prototype. (M2RTS_RegisterModule): Changed prototype. * mc-boot/GDynamicStrings.c: Rebuild. * mc-boot/GFIO.c: Rebuild. * mc-boot/GIndexing.c: Rebuild. * mc-boot/GM2Dependent.c: Rebuild. * mc-boot/GM2Dependent.h: Rebuild. * mc-boot/GM2EXCEPTION.c: Rebuild. * mc-boot/GM2RTS.c: Rebuild. * mc-boot/GM2RTS.h: Rebuild. * mc-boot/GPushBackInput.c: Rebuild. * mc-boot/GRTExceptions.c: Rebuild. * mc-boot/GRTint.c: Rebuild. * mc-boot/GStdIO.c: Rebuild. * mc-boot/GStringConvert.c: Rebuild. * mc-boot/GSysStorage.c: Rebuild. * mc-boot/Gdecl.c: Rebuild. * mc-boot/Gkeyc.c: Rebuild. * mc-boot/Glibc.h: Rebuild. * mc-boot/GmcComment.c: Rebuild. * mc-boot/GmcComp.c: Rebuild. * mc-boot/GmcDebug.c: Rebuild. * mc-boot/GmcMetaError.c: Rebuild. * mc-boot/GmcStack.c: Rebuild. * mc-boot/GnameKey.c: Rebuild. * mc-boot/GsymbolKey.c: Rebuild. * pge-boot/GASCII.c: Rebuild. * pge-boot/GArgs.c: Rebuild. * pge-boot/GAssertion.c: Rebuild. * pge-boot/GDebug.c: Rebuild. * pge-boot/GDynamicStrings.c: Rebuild. * pge-boot/GFIO.c: Rebuild. * pge-boot/GIO.c: Rebuild. * pge-boot/GIndexing.c: Rebuild. * pge-boot/GLists.c: Rebuild. * pge-boot/GM2Dependent.c: Rebuild. * pge-boot/GM2Dependent.h: Rebuild. * pge-boot/GM2EXCEPTION.c: Rebuild. * pge-boot/GM2RTS.c: Rebuild. * pge-boot/GM2RTS.h: Rebuild. * pge-boot/GNameKey.c: Rebuild. * pge-boot/GNumberIO.c: Rebuild. * pge-boot/GOutput.c: Rebuild. * pge-boot/GPushBackInput.c: Rebuild. * pge-boot/GRTExceptions.c: Rebuild. * pge-boot/GSFIO.c: Rebuild. * pge-boot/GStdIO.c: Rebuild. * pge-boot/GStorage.c: Rebuild. * pge-boot/GStrCase.c: Rebuild. * pge-boot/GStrIO.c: Rebuild. * pge-boot/GStrLib.c: Rebuild. * pge-boot/GSymbolKey.c: Rebuild. * pge-boot/GSysExceptions.c (_M2_SysExceptions_finish): Rename this... (_M2_SysExceptions_fini): ... to this. * pge-boot/GSysStorage.c: Rebuild. (_M2_SysStorage_finish): Rename this... (_M2_SysStorage_fini): ... to this. * pge-boot/GUnixArgs.cc: New file. * pge-boot/Gbnflex.c (_M2_bnflex_finish): Rename this... (_M2_bnflex_fini): ... to this. * pge-boot/Gerrno.c (_M2_errno_finish): Rename this... (_M2_errno_fini): ... to this. * pge-boot/Glibc.c (libc_snprintf): New function. * pge-boot/Glibc.h (libc_snprintf): New prototype. * pge-boot/Gpge.c (_M2_pge_finish): Rename this... (_M2_pge_fini): ... to this. * pge-boot/Gtermios.cc (_M2_termios_finish): Rename this... (_M2_termios_fini): ... to this. * pge-boot/main.c (_M2_RTExceptions_finish): Rename this... (_M2_RTExceptions_fini): ... to this. (_M2_M2EXCEPTION_finish): Rename this... (_M2_M2EXCEPTION_fini): ... to this. (_M2_M2RTS_finish): Rename this... (_M2_M2RTS_fini): ... to this. (_M2_SysExceptions_finish): Rename this... (_M2_SysExceptions_fini): ... to this. (_M2_StrLib_finish): Rename this... (_M2_StrLib_fini): ... to this. (_M2_errno_finish): Rename this... (_M2_errno_fini): ... to this. (_M2_termios_finish): Rename this... (_M2_termios_fini): ... to this. (_M2_IO_finish): Rename this... (_M2_IO_fini): ... to this. (_M2_StdIO_finish): Rename this... (_M2_StdIO_fini): ... to this. (_M2_Debug_finish): Rename this... (_M2_Debug_fini): ... to this. (_M2_SysStorage_finish): Rename this... (_M2_SysStorage_fini): ... to this. (_M2_Storage_finish): Rename this... (_M2_Storage_fini): ... to this. (_M2_StrIO_finish): Rename this... (_M2_StrIO_fini): ... to this. (_M2_DynamicStrings_finish): Rename this... (_M2_DynamicStrings_fini): ... to this. (_M2_Assertion_finish): Rename this... (_M2_Assertion_fini): ... to this. (_M2_Indexing_finish): Rename this... (_M2_Indexing_fini): ... to this. (_M2_NameKey_finish): Rename this... (_M2_NameKey_fini): ... to this. (_M2_NumberIO_finish): Rename this... (_M2_NumberIO_fini): ... to this. (_M2_PushBackInput_finish): Rename this... (_M2_PushBackInput_fini): ... to this. (_M2_SymbolKey_finish): Rename this... (_M2_SymbolKey_fini): ... to this. (_M2_UnixArgs_finish): Rename this... (_M2_UnixArgs_fini): ... to this. (_M2_FIO_finish): Rename this... (_M2_FIO_fini): ... to this. (_M2_SFIO_finish): Rename this... (_M2_SFIO_fini): ... to this. (_M2_StrCase_finish): Rename this... (_M2_StrCase_fini): ... to this. (_M2_bnflex_finish): Rename this... (_M2_bnflex_fini): ... to this. (_M2_Lists_finish): Rename this... (_M2_Lists_fini): ... to this. (_M2_Args_finish): Rename this... (_M2_Args_fini): ... to this. (_M2_Output_finish): Rename this... (_M2_Output_fini): ... to this. (_M2_pge_finish): Rename this... (_M2_pge_fini): ... to this. * plugin/m2rte.cc (m2_runtime_error_calls): Change all runtime procedure names to their name mangled counterparts. * gm2-libs-iso/wrapsock.c: Removed. * gm2-libs-iso/wraptime.c: Removed. * mc-boot/Gpth.h: Removed. * gm2-compiler/PathName.def: New file. * gm2-compiler/PathName.mod: New file. libgm2/ChangeLog: PR modula2/108261 * libm2cor/KeyBoardLEDs.cc (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (KeyBoardLEDs_SwitchScroll): EXPORT. (KeyBoardLEDs_SwitchNum): EXPORT. (KeyBoardLEDs_SwitchCaps): EXPORT. (KeyBoardLEDs_SwitchLeds): EXPORT. (_M2_KeyBoardLEDs_init): M2EXPORT. (_M2_KeyBoardLEDs_finish): M2EXPORT. (_M2_KeyBoardLEDs_dep): M2EXPORT. * libm2cor/Makefile.am (libm2cor_la_M2FLAGS): Define path names. * libm2cor/Makefile.in: Rebuild. * libm2iso/ErrnoCategory.cc (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (ErrnoCategory_IsErrnoHard): EXPORT. (ErrnoCategory_IsErrnoSoft): EXPORT. (ErrnoCategory_UnAvailable): EXPORT. (ErrnoCategory_GetOpenResults): EXPORT. (_M2_ErrnoCategory_init): M2EXPORT. (_M2_ErrnoCategory_fini): M2EXPORT. (_M2_ErrnoCategory_dep): M2EXPORT. (_M2_ErrnoCategory_ctor): M2EXPORT. * libm2iso/Makefile.am (libm2iso_la_M2FLAGS): Define path names. * libm2iso/Makefile.in: Rebuild. * libm2iso/RTco.cc (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (newSem): Add module libname prefix to HaltC. (currentThread): Remove variable and replace with a function. (never): Add module libname prefix to HaltC. (initThread): Add module libname prefix to HaltC. * libm2iso/m2rts.h (str): New define. (M2RTS_RequestDependant): Change to the mangled name equivalent. (M2RTS_RegisterModule): Change to the mangled name equivalent. (m2iso_M2RTS_RequestDependant): Add libname parameter. (m2iso_M2RTS_RegisterModule): Add libname parameter. (m2pim_M2RTS_RegisterModule): Add libname parameter. (_M2_M2RTS_init): Rename this... (m2iso_M2_M2RTS_init): ...to this. (M2RTS_ConstructModules): Change to the mangled name equivalent. (M2RTS_Terminate): Change to the mangled name equivalent. (M2RTS_DeconstructModules): Change to the mangled name equivalent. (m2iso_M2RTS_ConstructModules): Add libname parameter. (m2iso_M2RTS_Terminate): Add libname parameter. (m2iso_M2RTS_DeconstructModules): Add libname parameter. (M2RTS_HaltC): Rename this... (m2iso_M2RTS_HaltC): ...to this. * libm2iso/wrapsock.c (EXPORT): New define. (IMPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (m2iso_M2RTS_RequestDependant): Add prototype. (wrapsock_clientOpen): EXPORT. (wrapsock_clientOpenIP): EXPORT. (wrapsock_getClientPortNo): EXPORT. (wrapsock_getClientHostname): EXPORT. (wrapsock_getClientSocketFd): EXPORT. (wrapsock_getClientIP): EXPORT. (wrapsock_getPushBackChar): EXPORT. (wrapsock_setPushBackChar): EXPORT. (wrapsock_getSizeOfClientInfo): EXPORT. (_M2_wrapsock_init): M2EXPORT. (_M2_wrapsock_fini): M2EXPORT. (ctor): M2EXPORT. New function. * libm2iso/wraptime.c: Rename to... * libm2iso/wraptime.cc: ...this. (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (wraptime_InitTimeval): EXPORT. (wraptime_KillTimeval): EXPORT. (wraptime_InitTimezone): EXPORT. (wraptime_KillTimezone): EXPORT. (wraptime_InitTM): EXPORT. (wraptime_KillTM): EXPORT. (wraptime_gettimeofday): EXPORT. (wraptime_settimeofday): EXPORT. (wraptime_GetFractions): EXPORT. (wraptime_localtime_r): EXPORT. (wraptime_GetYear): EXPORT. (wraptime_GetMonth): EXPORT. (wraptime_GetDay): EXPORT. (wraptime_GetHour): EXPORT. (wraptime_GetMinute): EXPORT. (wraptime_GetSecond): EXPORT. (wraptime_GetSummerTime): EXPORT. (wraptime_GetDST): EXPORT. (wraptime_SetTimezone): EXPORT. (wraptime_SetTimeval): EXPORT. (_M2_wraptime_init): M2EXPORT. (_M2_wraptime_fini): M2EXPORT. (ctor): M2EXPORT. New function. * libm2log/Makefile.am (libm2log_la_M2FLAGS): Define path names. * libm2log/Makefile.in: * libm2min/Makefile.am (libm2min_la_M2FLAGS): Define path names. * libm2min/Makefile.in: * libm2pim/Makefile.am (libm2pim_la_M2FLAGS): Define path names. * libm2pim/Makefile.in: * libm2pim/Selective.cc (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (Selective_Select): EXPORT. (Selective_InitTime): EXPORT. (Selective_GetTime): EXPORT. (Selective_SetTime): EXPORT. (Selective_KillTime): EXPORT. (Selective_InitSet): EXPORT. (Selective_KillSet): EXPORT. (Selective_FdZero): EXPORT. (Selective_FdSet): EXPORT. (Selective_FdClr): EXPORT. (Selective_FdIsSet): EXPORT. (Selective_GetTimeOfDay): EXPORT. (Selective_MaxFdsPlusOne): EXPORT. (Selective_WriteCharRaw): EXPORT. (Selective_ReadCharRaw): EXPORT. (_M2_Selective_init): M2EXPORT. (_M2_Selective_fini): M2EXPORT. (_M2_Selective_dep): M2EXPORT. (_M2_Selective_ctor): M2EXPORT. * libm2pim/SysExceptions.cc (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (SysExceptions_InitExceptionHandlers): EXPORT. (_M2_SysExceptions_init): M2EXPORT. (_M2_SysExceptions_fini): M2EXPORT. (_M2_SysExceptions_dep): M2EXPORT. (_M2_SysExceptions_ctor): M2EXPORT. * libm2pim/UnixArgs.cc (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (UnixArgs_GetArgC): EXPORT. (UnixArgs_GetArgV): EXPORT. (UnixArgs_GetEnvV): EXPORT. (_M2_UnixArgs_init): M2EXPORT. (_M2_UnixArgs_fini): M2EXPORT. (_M2_UnixArgs_dep): M2EXPORT. (_M2_UnixArgs_ctor): M2EXPORT. * libm2pim/cgetopt.cc (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (cgetopt_getopt): EXPORT. (cgetopt_getopt_long): EXPORT. (cgetopt_getopt_long_only): EXPORT. (cgetopt_InitOptions): EXPORT. (cgetopt_KillOptions): EXPORT. (cgetopt_SetOption): EXPORT. (cgetopt_GetLongOptionArray): EXPORT. (_M2_cgetopt_init): M2EXPORT. (_M2_cgetopt_fini): M2EXPORT. (_M2_cgetopt_dep): M2EXPORT. (_M2_cgetopt_ctor): M2EXPORT. * libm2pim/dtoa.cc (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (dtoa_strtod): EXPORT. (dtoa_calcmaxsig): EXPORT. (dtoa_calcdecimal): EXPORT. (dtoa_calcsign): EXPORT. (dtoa_dtoa): EXPORT. (_M2_dtoa_init): M2EXPORT. (_M2_dtoa_fini): M2EXPORT. (_M2_dtoa_dep): M2EXPORT. (_M2_dtoa_ctor): M2EXPORT. * libm2pim/errno.cc (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (errno_geterrno): EXPORT. (_M2_errno_init): M2EXPORT. (_M2_errno_fini): M2EXPORT. (_M2_errno_dep): M2EXPORT. (_M2_errno_ctor): M2EXPORT. * libm2pim/ldtoa.cc (EXPORT): New define. (IMPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (dtoa_calcmaxsig): EXPORT. (dtoa_calcdecimal): EXPORT. (dtoa_calcsign): EXPORT. (ldtoa_strtold): EXPORT. (ldtoa_ldtoa): EXPORT. (_M2_ldtoa_init): M2EXPORT. (_M2_ldtoa_fini): M2EXPORT. (_M2_ldtoa_dep): M2EXPORT. (_M2_ldtoa_ctor): M2EXPORT. * libm2pim/sckt.cc (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (tcpServerEstablishPort): EXPORT. (tcpServerEstablish): EXPORT. (tcpServerAccept): EXPORT. (tcpServerPortNo): EXPORT. (tcpServerSocketFd): EXPORT. (getLocalIP): EXPORT. (tcpServerIP): EXPORT. (tcpServerClientIP): EXPORT. (tcpServerClientPortNo): EXPORT. (tcpClientSocket): EXPORT. (tcpClientSocketIP): EXPORT. (tcpClientConnect): EXPORT. (tcpClientPortNo): EXPORT. (tcpClientSocketFd): EXPORT. (tcpClientIP): EXPORT. (_M2_sckt_init): M2EXPORT. (_M2_sckt_finish): M2EXPORT. (_M2_sckt_dep): M2EXPORT. (_M2_sckt_ctor): M2EXPORT. * libm2pim/termios.cc (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (_M2_termios_init): M2EXPORT. (_M2_termios_fini): M2EXPORT. (_M2_termios_dep): M2EXPORT. (_M2_termios_ctor): M2EXPORT. * libm2pim/wrapc.c (EXPORT): New define. (M2EXPORT): New define. (M2LIBNAME): New define. (wrapc_strtime): EXPORT. (wrapc_filesize): EXPORT. (wrapc_filemtime): EXPORT. (wrapc_fileinode): EXPORT. (wrapc_getrand): EXPORT. (wrapc_getusername): EXPORT. (wrapc_getnameuidgid): EXPORT. (wrapc_signbit): EXPORT. (wrapc_signbitl): EXPORT. (wrapc_signbitf): EXPORT. (wrapc_isfinite): EXPORT. (wrapc_isfinitel): EXPORT. (wrapc_isfinitef): EXPORT. (_M2_wrapc_init): M2EXPORT. (_M2_wrapc_fini): M2EXPORT. (_M2_wrapc_ctor): M2EXPORT. gcc/testsuite/ChangeLog: PR modula2/108261 * gm2/examples/callingC/pass/examples-callingC-pass.exp: Tidy up variable access. * gm2/examples/callingC/run/pass/examples-callingC-run-pass.exp: Tidy up variable access. * gm2/examples/cpp/pass/examples-cpp-pass.exp: Tidy up variable access. * gm2/examples/cppDef/pass/examples-cppDef-pass.exp: Tidy up variable access. * gm2/examples/hello/pass/examples-hello-pass.exp: Tidy up variable access. * gm2/examples/map/pass/examples-map-pass.exp: Tidy up variable access. * gm2/iso/check/fail/iso-check-fail.exp: Add pathname. * gm2/link/externalscaffold/pass/link-externalscaffold-pass.exp: Add pathname. * gm2/link/externalscaffold/pass/scaffold.c: Add mangled export name. * gm2/pimlib/base/run/pass/FIO.mod: Updated test code. * gm2/pimlib/base/run/pass/StrLib.mod: Updated test code. * gm2/pimlib/base/run/pass/pimlib-base-run-pass.exp: Remove path. * gm2/projects/pim/run/pass/random/projects-pim-run-pass-random.exp: Tidy up variable access. * gm2/switches/auto-init/fail/switches-auto-init-fail.exp: Add pathname. * gm2/switches/check-all/pim2/fail/switches-check-all-pim2-fail.exp: Add pathname. * gm2/switches/makeall/fail/switches-makeall-fail.exp: Remove -fmakeall. * gm2/switches/makeall/pass/switches-makeall-pass.exp: Remove -fmakeall. * lib/gm2-simple.exp (gm2_keep_executable): New global variable. (gm2_simple_execute): Keep executable if global is true. * lib/gm2-torture.exp: Add ; after global variable access. * lib/gm2.exp: Set up pathnames. * gm2/projects/pim/run/pass/tower/AdvCmd.def: New test. * gm2/projects/pim/run/pass/tower/AdvCmd.mod: New test. * gm2/projects/pim/run/pass/tower/AdvIntroduction.def: New test. * gm2/projects/pim/run/pass/tower/AdvIntroduction.mod: New test. * gm2/projects/pim/run/pass/tower/AdvMap.def: New test. * gm2/projects/pim/run/pass/tower/AdvMap.mod: New test. * gm2/projects/pim/run/pass/tower/AdvMath.def: New test. * gm2/projects/pim/run/pass/tower/AdvMath.mod: New test. * gm2/projects/pim/run/pass/tower/AdvParse.bnf: New test. * gm2/projects/pim/run/pass/tower/AdvParse.def: New test. * gm2/projects/pim/run/pass/tower/AdvParse.mod: New test. * gm2/projects/pim/run/pass/tower/AdvSound.def: New test. * gm2/projects/pim/run/pass/tower/AdvSound.mod: New test. * gm2/projects/pim/run/pass/tower/AdvSystem.def: New test. * gm2/projects/pim/run/pass/tower/AdvSystem.mod: New test. * gm2/projects/pim/run/pass/tower/AdvTreasure.def: New test. * gm2/projects/pim/run/pass/tower/AdvTreasure.mod: New test. * gm2/projects/pim/run/pass/tower/AdvUtil.def: New test. * gm2/projects/pim/run/pass/tower/AdvUtil.mod: New test. * gm2/projects/pim/run/pass/tower/DrawG.def: New test. * gm2/projects/pim/run/pass/tower/DrawG.mod: New test. * gm2/projects/pim/run/pass/tower/DrawL.def: New test. * gm2/projects/pim/run/pass/tower/DrawL.mod: New test. * gm2/projects/pim/run/pass/tower/Dungeon.mod: New test. * gm2/projects/pim/run/pass/tower/Lock.def: New test. * gm2/projects/pim/run/pass/tower/Lock.mod: New test. * gm2/projects/pim/run/pass/tower/ProcArgs.def: New test. * gm2/projects/pim/run/pass/tower/ProcArgs.mod: New test. * gm2/projects/pim/run/pass/tower/Screen.def: New test. * gm2/projects/pim/run/pass/tower/Screen.mod: New test. * gm2/projects/pim/run/pass/tower/SocketControl.c: New test. * gm2/projects/pim/run/pass/tower/SocketControl.def: New test. * gm2/projects/pim/run/pass/tower/Window.def: New test. * gm2/projects/pim/run/pass/tower/Window.mod: New test. * gm2/projects/pim/run/pass/tower/adv.flex: New test. * gm2/projects/pim/run/pass/tower/advflex.c: New test. * gm2/projects/pim/run/pass/tower/advflex.def: New test. * gm2/projects/pim/run/pass/tower/projects-pim-run-pass-tower.exp: New test. * gm2/projects/pim/run/pass/tower/star: New test. Signed-off-by: Gaius Mulley --- libgm2/libm2iso/ErrnoCategory.cc | 27 ++- libgm2/libm2iso/Makefile.am | 19 +- libgm2/libm2iso/Makefile.in | 33 ++- libgm2/libm2iso/RTco.cc | 117 ++++++----- libgm2/libm2iso/m2rts.h | 26 ++- libgm2/libm2iso/wrapsock.c | 52 +++-- libgm2/libm2iso/wraptime.c | 408 ------------------------------------- libgm2/libm2iso/wraptime.cc | 429 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 590 insertions(+), 521 deletions(-) delete mode 100644 libgm2/libm2iso/wraptime.c create mode 100644 libgm2/libm2iso/wraptime.cc (limited to 'libgm2/libm2iso') diff --git a/libgm2/libm2iso/ErrnoCategory.cc b/libgm2/libm2iso/ErrnoCategory.cc index 2db2639..55db89d 100644 --- a/libgm2/libm2iso/ErrnoCategory.cc +++ b/libgm2/libm2iso/ErrnoCategory.cc @@ -25,7 +25,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ #include "config.h" - #include "ChanConsts.h" #if defined(HAVE_ERRNO_H) @@ -38,6 +37,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "m2rts.h" +#define EXPORT(FUNC) m2iso ## _ErrnoCategory_ ## FUNC +#define M2EXPORT(FUNC) m2iso ## _M2_ErrnoCategory_ ## FUNC +#define M2LIBNAME "m2iso" + + #if !defined(FALSE) #define FALSE (1 == 0) #endif @@ -50,7 +54,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see with a hard device error. */ extern "C" int -ErrnoCategory_IsErrnoHard (int e) +EXPORT(IsErrnoHard) (int e) { #if defined(HAVE_ERRNO_H) || defined(HAVE_SYS_ERRNO_H) return ((e == EPERM) || (e == ENOENT) || (e == EIO) || (e == ENXIO) @@ -65,7 +69,7 @@ ErrnoCategory_IsErrnoHard (int e) with a soft device error. */ extern "C" int -ErrnoCategory_IsErrnoSoft (int e) +EXPORT(IsErrnoSoft) (int e) { #if defined(HAVE_ERRNO_H) || defined(HAVE_SYS_ERRNO_H) return ((e == ESRCH) || (e == EINTR) || (e == E2BIG) || (e == ENOEXEC) @@ -79,7 +83,7 @@ ErrnoCategory_IsErrnoSoft (int e) } extern "C" int -ErrnoCategory_UnAvailable (int e) +EXPORT(UnAvailable) (int e) { #if defined(HAVE_ERRNO_H) || defined(HAVE_SYS_ERRNO_H) return ((e == ENOENT) || (e == ESRCH) || (e == ENXIO) || (e == ECHILD) @@ -93,7 +97,7 @@ ErrnoCategory_UnAvailable (int e) OpenResults. */ extern "C" openResults -ErrnoCategory_GetOpenResults (int e) +EXPORT(GetOpenResults) (int e) { if (e == 0) return opened; @@ -157,23 +161,24 @@ ErrnoCategory_GetOpenResults (int e) /* GNU Modula-2 linking fodder. */ extern "C" void -_M2_ErrnoCategory_init (int, char *argv[], char *env[]) +M2EXPORT(init) (int, char **, char **) { } extern "C" void -_M2_ErrnoCategory_fini (int, char *argv[], char *env[]) +M2EXPORT(fini) (int, char **, char **) { } extern "C" void -_M2_ErrnoCategory_dep (void) +M2EXPORT(dep) (void) { } extern "C" void __attribute__((__constructor__)) -_M2_ErrnoCategory_ctor (void) +M2EXPORT(ctor) (void) { - M2RTS_RegisterModule ("ErrnoCategory", _M2_ErrnoCategory_init, _M2_ErrnoCategory_fini, - _M2_ErrnoCategory_dep); + m2iso_M2RTS_RegisterModule ("ErrnoCategory", M2LIBNAME, + M2EXPORT(init), M2EXPORT(fini), + M2EXPORT(dep)); } diff --git a/libgm2/libm2iso/Makefile.am b/libgm2/libm2iso/Makefile.am index cc9a477..dddced4 100644 --- a/libgm2/libm2iso/Makefile.am +++ b/libgm2/libm2iso/Makefile.am @@ -15,7 +15,7 @@ # along with this program; see the file COPYING3. If not see # . -SUFFIXES = .c .mod .def .o .obj .lo .a .la +SUFFIXES = .c .cc .mod .def .o .obj .lo .a .la ACLOCAL_AMFLAGS = -I . -I .. -I ../config @@ -178,15 +178,18 @@ M2MODS = ChanConsts.mod CharClass.mod \ toolexeclib_LTLIBRARIES = libm2iso.la libm2iso_la_SOURCES = $(M2MODS) \ - ErrnoCategory.cc wrapsock.c \ - wraptime.c RTco.cc + ErrnoCategory.cc wraptime.cc RTco.cc wrapsock.c +# wrapsock.cc C_INCLUDES = -I.. -I$(toplevel_srcdir)/libiberty -I$(toplevel_srcdir)/include libm2isodir = libm2iso libm2iso_la_DEPENDENCIES = SYSTEM.def $(addsuffix .lo, $(basename $(libm2iso_la_SOURCES))) libm2iso_la_CFLAGS = $(C_INCLUDES) -I. -I.. -I$(GM2_SRC)/gm2-libs-iso -I$(GM2_SRC)/gm2-libs -DBUILD_GM2_LIBS -I@srcdir@/../ -I../../../gcc -I$(GCC_DIR) -I$(GCC_DIR)/../include -I../../libgcc -I$(GCC_DIR)/../libgcc -I$(MULTIBUILDTOP)../../gcc/include -libm2iso_la_M2FLAGS = -I. -Ilibm2iso -I$(GM2_SRC)/gm2-libs-iso -I$(GM2_SRC)/gm2-libs -fiso -fextended-opaque -fm2-g -g -Wreturn-type -fcase +libm2iso_la_M2FLAGS = \ + -fm2-pathname=m2iso -I. -Ilibm2iso -I$(GM2_SRC)/gm2-libs-iso \ + -fm2-pathname=m2pim -I$(GM2_SRC)/gm2-libs \ + -fiso -fextended-opaque -fm2-g -g -Wreturn-type -fcase -fm2-prefix=m2iso if TARGET_DARWIN libm2iso_la_link_flags = -Wl,-undefined,dynamic_lookup else @@ -207,17 +210,15 @@ SYSTEM.def: Makefile -I$(GM2_SRC)/gm2-libs-iso -I$(GM2_SRC)/gm2-libs \ "$(GM2_FOR_TARGET)" $@ -## add these to the .mod.o rule when optimization is fixed $(CFLAGS_FOR_TARGET) $(LIBCFLAGS) - .mod.lo: $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(GM2_FOR_TARGET) -c $(CFLAGS_FOR_TARGET) $(LIBCFLAGS) $(libm2iso_la_M2FLAGS) $< -o $@ -.c.lo: - $(LIBTOOL) --tag=CC --mode=compile $(CC) -c $(CFLAGS) $(LIBCFLAGS) $(libm2iso_la_CFLAGS) $< -o $@ - .cc.lo: $(LIBTOOL) --tag=CXX --mode=compile $(CXX) -c -I$(srcdir) $(CXXFLAGS) $(LIBCFLAGS) $(libm2iso_la_CFLAGS) $< -o $@ +.c.lo: + $(LIBTOOL) --tag=CC --mode=compile $(CC) -c -I$(srcdir) $(CFLAGS) $(LIBCFLAGS) $(libm2iso_la_CFLAGS) $< -o $@ + install-data-local: force mkdir -p $(DESTDIR)$(inst_libdir)/$(M2LIBDIR) for i in $(M2DEFS) $(M2MODS) ; do \ diff --git a/libgm2/libm2iso/Makefile.in b/libgm2/libm2iso/Makefile.in index b96136a..e28e9dd 100644 --- a/libgm2/libm2iso/Makefile.in +++ b/libgm2/libm2iso/Makefile.in @@ -179,8 +179,8 @@ libm2iso_la_LIBADD = @BUILD_ISOLIB_TRUE@ TextIO.lo WholeConv.lo WholeIO.lo \ @BUILD_ISOLIB_TRUE@ WholeStr.lo @BUILD_ISOLIB_TRUE@am_libm2iso_la_OBJECTS = $(am__objects_1) \ -@BUILD_ISOLIB_TRUE@ ErrnoCategory.lo libm2iso_la-wrapsock.lo \ -@BUILD_ISOLIB_TRUE@ libm2iso_la-wraptime.lo RTco.lo +@BUILD_ISOLIB_TRUE@ ErrnoCategory.lo wraptime.lo RTco.lo \ +@BUILD_ISOLIB_TRUE@ libm2iso_la-wrapsock.lo libm2iso_la_OBJECTS = $(am_libm2iso_la_OBJECTS) @BUILD_ISOLIB_TRUE@am_libm2iso_la_rpath = -rpath $(toolexeclibdir) AM_V_P = $(am__v_P_@AM_V@) @@ -408,7 +408,7 @@ toolexeclibdir = @toolexeclibdir@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -SUFFIXES = .c .mod .def .o .obj .lo .a .la +SUFFIXES = .c .cc .mod .def .o .obj .lo .a .la ACLOCAL_AMFLAGS = -I . -I .. -I ../config # Multilib support. @@ -556,14 +556,18 @@ FLAGS_TO_PASS = $(AM_MAKEFLAGS) @BUILD_ISOLIB_TRUE@toolexeclib_LTLIBRARIES = libm2iso.la @BUILD_ISOLIB_TRUE@libm2iso_la_SOURCES = $(M2MODS) \ -@BUILD_ISOLIB_TRUE@ ErrnoCategory.cc wrapsock.c \ -@BUILD_ISOLIB_TRUE@ wraptime.c RTco.cc +@BUILD_ISOLIB_TRUE@ ErrnoCategory.cc wraptime.cc RTco.cc wrapsock.c +# wrapsock.cc @BUILD_ISOLIB_TRUE@C_INCLUDES = -I.. -I$(toplevel_srcdir)/libiberty -I$(toplevel_srcdir)/include @BUILD_ISOLIB_TRUE@libm2isodir = libm2iso @BUILD_ISOLIB_TRUE@libm2iso_la_DEPENDENCIES = SYSTEM.def $(addsuffix .lo, $(basename $(libm2iso_la_SOURCES))) @BUILD_ISOLIB_TRUE@libm2iso_la_CFLAGS = $(C_INCLUDES) -I. -I.. -I$(GM2_SRC)/gm2-libs-iso -I$(GM2_SRC)/gm2-libs -DBUILD_GM2_LIBS -I@srcdir@/../ -I../../../gcc -I$(GCC_DIR) -I$(GCC_DIR)/../include -I../../libgcc -I$(GCC_DIR)/../libgcc -I$(MULTIBUILDTOP)../../gcc/include -@BUILD_ISOLIB_TRUE@libm2iso_la_M2FLAGS = -I. -Ilibm2iso -I$(GM2_SRC)/gm2-libs-iso -I$(GM2_SRC)/gm2-libs -fiso -fextended-opaque -fm2-g -g -Wreturn-type -fcase +@BUILD_ISOLIB_TRUE@libm2iso_la_M2FLAGS = \ +@BUILD_ISOLIB_TRUE@ -fm2-pathname=m2iso -I. -Ilibm2iso -I$(GM2_SRC)/gm2-libs-iso \ +@BUILD_ISOLIB_TRUE@ -fm2-pathname=m2pim -I$(GM2_SRC)/gm2-libs \ +@BUILD_ISOLIB_TRUE@ -fiso -fextended-opaque -fm2-g -g -Wreturn-type -fcase -fm2-prefix=m2iso + @BUILD_ISOLIB_TRUE@@TARGET_DARWIN_FALSE@libm2iso_la_link_flags = @BUILD_ISOLIB_TRUE@@TARGET_DARWIN_TRUE@libm2iso_la_link_flags = -Wl,-undefined,dynamic_lookup @BUILD_ISOLIB_TRUE@libm2iso_la_LINK = $(LINK) -version-info $(libtool_VERSION) $(libm2iso_la_link_flags) @@ -575,7 +579,7 @@ all: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: -.SUFFIXES: .c .mod .def .o .obj .lo .a .la .cc +.SUFFIXES: .c .cc .mod .def .o .obj .lo .a .la $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ @@ -653,7 +657,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ErrnoCategory.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RTco.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libm2iso_la-wrapsock.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libm2iso_la-wraptime.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wraptime.Plo@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -683,13 +687,6 @@ libm2iso_la-wrapsock.lo: wrapsock.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libm2iso_la_CFLAGS) $(CFLAGS) -c -o libm2iso_la-wrapsock.lo `test -f 'wrapsock.c' || echo '$(srcdir)/'`wrapsock.c -libm2iso_la-wraptime.lo: wraptime.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libm2iso_la_CFLAGS) $(CFLAGS) -MT libm2iso_la-wraptime.lo -MD -MP -MF $(DEPDIR)/libm2iso_la-wraptime.Tpo -c -o libm2iso_la-wraptime.lo `test -f 'wraptime.c' || echo '$(srcdir)/'`wraptime.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libm2iso_la-wraptime.Tpo $(DEPDIR)/libm2iso_la-wraptime.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='wraptime.c' object='libm2iso_la-wraptime.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libm2iso_la_CFLAGS) $(CFLAGS) -c -o libm2iso_la-wraptime.lo `test -f 'wraptime.c' || echo '$(srcdir)/'`wraptime.c - .cc.o: @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @@ -911,12 +908,12 @@ uninstall-am: uninstall-toolexeclibLTLIBRARIES @BUILD_ISOLIB_TRUE@.mod.lo: @BUILD_ISOLIB_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(GM2_FOR_TARGET) -c $(CFLAGS_FOR_TARGET) $(LIBCFLAGS) $(libm2iso_la_M2FLAGS) $< -o $@ -@BUILD_ISOLIB_TRUE@.c.lo: -@BUILD_ISOLIB_TRUE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) -c $(CFLAGS) $(LIBCFLAGS) $(libm2iso_la_CFLAGS) $< -o $@ - @BUILD_ISOLIB_TRUE@.cc.lo: @BUILD_ISOLIB_TRUE@ $(LIBTOOL) --tag=CXX --mode=compile $(CXX) -c -I$(srcdir) $(CXXFLAGS) $(LIBCFLAGS) $(libm2iso_la_CFLAGS) $< -o $@ +@BUILD_ISOLIB_TRUE@.c.lo: +@BUILD_ISOLIB_TRUE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) -c -I$(srcdir) $(CFLAGS) $(LIBCFLAGS) $(libm2iso_la_CFLAGS) $< -o $@ + @BUILD_ISOLIB_TRUE@install-data-local: force @BUILD_ISOLIB_TRUE@ mkdir -p $(DESTDIR)$(inst_libdir)/$(M2LIBDIR) @BUILD_ISOLIB_TRUE@ for i in $(M2DEFS) $(M2MODS) ; do \ diff --git a/libgm2/libm2iso/RTco.cc b/libgm2/libm2iso/RTco.cc index 8b8a4dc..33da586 100644 --- a/libgm2/libm2iso/RTco.cc +++ b/libgm2/libm2iso/RTco.cc @@ -32,8 +32,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include #include -#define EXPORT(FUNC) RTco_ ## FUNC -#define M2EXPORT(FUNC) _M2_RTco_ ## FUNC +#define EXPORT(FUNC) m2iso ## _RTco_ ## FUNC +#define M2EXPORT(FUNC) m2iso ## _M2_RTco_ ## FUNC +#define M2LIBNAME "m2iso" /* This implementation of RTco.cc uses a single lock for mutex across the whole module. It also forces context switching between threads @@ -104,12 +105,9 @@ static threadSem **semArray = NULL; static __gthread_mutex_t lock; /* This is the only mutex for the whole module. */ static int initialized = FALSE; -static int currentThread = 0; - extern "C" int EXPORT(init) (void); - extern "C" void M2EXPORT(dep) (void) { @@ -184,8 +182,8 @@ newSem (void) = (threadSem *)malloc (sizeof (threadSem)); nSemaphores += 1; if (nSemaphores == SEM_POOL) - M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, - "too many semaphores created"); + m2iso_M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, + "too many semaphores created"); #else threadSem *sem = (threadSem *)malloc (sizeof (threadSem)); @@ -233,6 +231,18 @@ EXPORT(initSemaphore) (int value) return sid; } +static int +currentThread (void) +{ + int tid; + + for (tid = 0; tid < nThreads; tid++) + if (pthread_self () == threadArray[tid].p) + return tid; + m2iso_M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, + "failed to find currentThread"); +} + extern "C" int EXPORT(currentThread) (void) { @@ -240,7 +250,7 @@ EXPORT(currentThread) (void) EXPORT(init) (); __gthread_mutex_lock (&lock); - tid = currentThread; + tid = currentThread (); tprintf ("currentThread %d\n", tid); __gthread_mutex_unlock (&lock); return tid; @@ -253,9 +263,10 @@ EXPORT(currentInterruptLevel) (void) { EXPORT(init) (); __gthread_mutex_lock (&lock); + int current = currentThread (); tprintf ("currentInterruptLevel %d\n", - threadArray[currentThread].interruptLevel); - int level = threadArray[currentThread].interruptLevel; + threadArray[current].interruptLevel); + int level = threadArray[current].interruptLevel; __gthread_mutex_unlock (&lock); return level; } @@ -268,9 +279,10 @@ EXPORT(turnInterrupts) (unsigned int newLevel) { EXPORT(init) (); __gthread_mutex_lock (&lock); - unsigned int old = threadArray[currentThread].interruptLevel; + int current = currentThread (); + unsigned int old = threadArray[current].interruptLevel; tprintf ("turnInterrupts from %d to %d\n", old, newLevel); - threadArray[currentThread].interruptLevel = newLevel; + threadArray[current].interruptLevel = newLevel; __gthread_mutex_unlock (&lock); return old; } @@ -278,8 +290,8 @@ EXPORT(turnInterrupts) (unsigned int newLevel) static void never (void) { - M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, - "the main thread should never call here"); + m2iso_M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, + "the main thread should never call here"); } static void * @@ -313,10 +325,10 @@ execThread (void *t) __gthread_mutex_unlock (&lock); tp->proc (); /* Now execute user procedure. */ #if 0 - M2RTS_CoroutineException ( __FILE__, __LINE__, __COLUMN__, __FUNCTION__, "coroutine finishing"); + m2iso_M2RTS_CoroutineException ( __FILE__, __LINE__, __COLUMN__, __FUNCTION__, "coroutine finishing"); #endif - M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, - "execThread should never finish"); + m2iso_M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, + "execThread should never finish"); return NULL; } @@ -326,8 +338,8 @@ newThread (void) #if defined(POOL) nThreads += 1; if (nThreads == THREAD_POOL) - M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, - "too many threads created"); + m2iso_M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, + "too many threads created"); return nThreads - 1; #else if (nThreads == 0) @@ -364,15 +376,15 @@ initThread (void (*proc) (void), unsigned int stackSize, /* Set thread creation attributes. */ result = pthread_attr_init (&attr); if (result != 0) - M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, - "failed to create thread attribute"); + m2iso_M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, + "failed to create thread attribute"); if (stackSize > 0) { result = pthread_attr_setstacksize (&attr, stackSize); if (result != 0) - M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, - "failed to set stack size attribute"); + m2iso_M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, + "failed to set stack size attribute"); } tprintf ("initThread [%d] function = 0x%p (arg = 0x%p)\n", tid, proc, @@ -380,7 +392,7 @@ initThread (void (*proc) (void), unsigned int stackSize, result = pthread_create (&threadArray[tid].p, &attr, execThread, (void *)&threadArray[tid]); if (result != 0) - M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, "thread_create failed"); + m2iso_M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, "thread_create failed"); tprintf (" created thread [%d] function = 0x%p 0x%p\n", tid, proc, (void *)&threadArray[tid]); return tid; @@ -408,62 +420,61 @@ EXPORT(transfer) (int *p1, int p2) { __gthread_mutex_lock (&lock); { + int current = currentThread (); if (!initialized) - M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, - "cannot transfer to a process before the process has been created"); - if (currentThread == p2) + m2iso_M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, + "cannot transfer to a process before the process has been created"); + if (current == p2) { /* Error. */ - M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, - "attempting to transfer to ourself"); + m2iso_M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, + "attempting to transfer to ourself"); } else { - *p1 = currentThread; - int old = currentThread; - tprintf ("start, context switching from: %d to %d\n", currentThread, p2); + *p1 = current; + int old = current; + tprintf ("start, context switching from: %d to %d\n", current, p2); /* Perform signal (p2 sem). Without the mutex lock as we have already obtained it above. */ if (threadArray[p2].waiting) { /* p2 is blocked on the condition variable, release it. */ - tprintf ("p1 = %d cond_signal to p2 (%d)\n", currentThread, p2); + tprintf ("p1 = %d cond_signal to p2 (%d)\n", current, p2); __gthread_cond_signal (&threadArray[p2].run_counter); - tprintf ("after p1 = %d cond_signal to p2 (%d)\n", currentThread, p2); + tprintf ("after p1 = %d cond_signal to p2 (%d)\n", current, p2); } else { /* p2 hasn't reached the condition variable, so bump value ready for p2 to test. */ tprintf ("no need for thread %d to cond_signal - bump %d value (pre) = %d\n", - currentThread, p2, threadArray[p2].value); + current, p2, threadArray[p2].value); threadArray[p2].value++; } /* Perform wait (old sem). Again without obtaining mutex as we've already claimed it. */ if (threadArray[old].value == 0) { - currentThread = p2; /* Record we are about to wait on the condition variable. */ threadArray[old].waiting = true; __gthread_cond_wait (&threadArray[old].run_counter, &lock); threadArray[old].waiting = false; /* We are running again. */ - currentThread = old; } else { tprintf ("(currentThread = %d) no need for thread %d to cond_wait - taking value (pre) = %d\n", - currentThread, old, threadArray[old].value); + current, old, threadArray[old].value); /* No need to block as we have been told a signal has effectively already been recorded. We remove the signal notification without blocking. */ threadArray[old].value--; } - tprintf ("end, context back to %d\n", currentThread); - if (currentThread != old) - M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, - "wrong process id"); + tprintf ("end, context back to %d\n", current); + if (current != old) + m2iso_M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, + "wrong process id"); } } __gthread_mutex_unlock (&lock); @@ -494,15 +505,15 @@ EXPORT(init) (void) semArray = (threadSem **)malloc (sizeof (threadSem *) * SEM_POOL); #endif /* Create a thread control block for the main program (or process). */ - currentThread = newThread (); /* For the current initial thread. */ - threadArray[currentThread].p = pthread_self (); - threadArray[currentThread].tid = currentThread; - __GTHREAD_COND_INIT_FUNCTION (&threadArray[currentThread].run_counter); - threadArray[currentThread].interruptLevel = 0; + int tid = newThread (); /* For the current initial thread. */ + threadArray[tid].p = pthread_self (); + threadArray[tid].tid = tid; + __GTHREAD_COND_INIT_FUNCTION (&threadArray[tid].run_counter); + threadArray[tid].interruptLevel = 0; /* The line below shouldn't be necessary as we are already running. */ - threadArray[currentThread].proc = never; - threadArray[currentThread].waiting = false; /* We are running. */ - threadArray[currentThread].value = 0; /* No signal from anyone yet. */ + threadArray[tid].proc = never; + threadArray[tid].waiting = false; /* We are running. */ + threadArray[tid].value = 0; /* No signal from anyone yet. */ tprintf ("RTco initialized completed\n"); __gthread_mutex_unlock (&lock); } @@ -512,7 +523,7 @@ EXPORT(init) (void) extern "C" void __attribute__((__constructor__)) M2EXPORT(ctor) (void) { - M2RTS_RegisterModule ("RTco", - M2EXPORT(init), M2EXPORT(fini), - M2EXPORT(dep)); + m2iso_M2RTS_RegisterModule ("RTco", M2LIBNAME, + M2EXPORT(init), M2EXPORT(fini), + M2EXPORT(dep)); } diff --git a/libgm2/libm2iso/m2rts.h b/libgm2/libm2iso/m2rts.h index 1f3bc2d..97612c1 100644 --- a/libgm2/libm2iso/m2rts.h +++ b/libgm2/libm2iso/m2rts.h @@ -25,19 +25,25 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ +#define str(X) #X + typedef void (*proc_con) (int, char **, char **); typedef void (*proc_dep) (void); -extern "C" void M2RTS_RequestDependant (const char *modulename, const char *dependancy); -extern "C" void M2RTS_RegisterModule (const char *modulename, +extern "C" void m2iso_M2RTS_RequestDependant (const char *modulename, const char *libname, const char *dependancy); +extern "C" void m2iso_M2RTS_RegisterModule (const char *modulename, const char *libname, + proc_con init, proc_con fini, proc_dep dependencies); +extern "C" void m2pim_M2RTS_RegisterModule (const char *modulename, const char *libname, + proc_con init, proc_con fini, proc_dep dependencies); +extern "C" void M2RTS_RegisterModule (const char *modulename, const char *libname, proc_con init, proc_con fini, proc_dep dependencies); -extern "C" void _M2_M2RTS_init (void); +extern "C" void m2iso_M2_M2RTS_init (void); -extern "C" void M2RTS_ConstructModules (const char *, - int argc, char *argv[], char *envp[]); -extern "C" void M2RTS_Terminate (void); -extern "C" void M2RTS_DeconstructModules (void); +extern "C" void m2iso_M2RTS_ConstructModules (const char *modulename, const char *libname, + int argc, char *argv[], char *envp[]); +extern "C" void m2iso_M2RTS_Terminate (void); +extern "C" void m2iso_M2RTS_DeconstructModules (void); -extern "C" void M2RTS_HaltC (const char *filename, int line, - const char *functionname, const char *desc) - __attribute__ ((noreturn)); +extern "C" void m2iso_M2RTS_HaltC (const char *filename, int line, + const char *functionname, const char *desc) + __attribute__ ((noreturn)); diff --git a/libgm2/libm2iso/wrapsock.c b/libgm2/libm2iso/wrapsock.c index 79c2d89..1582f24 100644 --- a/libgm2/libm2iso/wrapsock.c +++ b/libgm2/libm2iso/wrapsock.c @@ -26,6 +26,20 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "config.h" +#define EXPORT(FUNC) m2iso ## _wrapsock_ ## FUNC +#define IMPORT(MODULE,FUNC) m2iso ## _ ## MODULE ## _ ## FUNC +#define M2EXPORT(FUNC) m2iso ## _M2_wrapsock_ ## FUNC +#define M2LIBNAME "m2iso" + +/* This module should be rewritten to use C++. */ + +typedef void (*proc_con) (int, char **, char **); +typedef void (*proc_dep) (void); + +extern void m2iso_M2RTS_RequestDependant (const char *modulename, const char *libname, const char *dependancy); +extern void m2iso_M2RTS_RegisterModule (const char *modulename, const char *libname, + proc_con init, proc_con fini, proc_dep dependencies); + #if defined(HAVE_SYS_TYPES_H) #include "sys/types.h" #endif @@ -106,7 +120,7 @@ static openResults clientConnect (clientInfo *c); structure, c, will have its fields initialized. */ openResults -wrapsock_clientOpen (clientInfo *c, char *hostname, unsigned int length, +EXPORT(clientOpen) (clientInfo *c, char *hostname, unsigned int length, int portNo) { /* remove SIGPIPE which is raised on the server if the client is killed. */ @@ -133,7 +147,7 @@ wrapsock_clientOpen (clientInfo *c, char *hostname, unsigned int length, structure, c, will have its fields initialized. */ openResults -wrapsock_clientOpenIP (clientInfo *c, unsigned int ip, int portNo) +EXPORT(clientOpenIP) (clientInfo *c, unsigned int ip, int portNo) { /* remove SIGPIPE which is raised on the server if the client is killed. */ signal (SIGPIPE, SIG_IGN); @@ -166,7 +180,7 @@ clientConnect (clientInfo *c) /* getClientPortNo - returns the portNo from structure, c. */ int -wrapsock_getClientPortNo (clientInfo *c) +EXPORT(getClientPortNo) (clientInfo *c) { return c->portNo; } @@ -175,7 +189,7 @@ wrapsock_getClientPortNo (clientInfo *c) which the client is connecting. */ void -wrapsock_getClientHostname (clientInfo *c, char *hostname, unsigned int high) +EXPORT(getClientHostname) (clientInfo *c, char *hostname, unsigned int high) { strncpy (hostname, c->hostname, high + 1); } @@ -183,7 +197,7 @@ wrapsock_getClientHostname (clientInfo *c, char *hostname, unsigned int high) /* getClientSocketFd - returns the sockFd from structure, c. */ int -wrapsock_getClientSocketFd (clientInfo *c) +EXPORT(getClientSocketFd) (clientInfo *c) { return c->sockFd; } @@ -191,7 +205,7 @@ wrapsock_getClientSocketFd (clientInfo *c) /* getClientIP - returns the sockFd from structure, s. */ unsigned int -wrapsock_getClientIP (clientInfo *c) +EXPORT(getClientIP) (clientInfo *c) { #if 0 printf("client ip = %s\n", inet_ntoa (c->sa.sin_addr.s_addr)); @@ -203,7 +217,7 @@ wrapsock_getClientIP (clientInfo *c) available. */ unsigned int -wrapsock_getPushBackChar (clientInfo *c, char *ch) +EXPORT(getPushBackChar) (clientInfo *c, char *ch) { if (c->hasChar > 0) { @@ -218,7 +232,7 @@ wrapsock_getPushBackChar (clientInfo *c, char *ch) character. */ unsigned int -wrapsock_setPushBackChar (clientInfo *c, char ch) +EXPORT(setPushBackChar) (clientInfo *c, char ch) { if (c->hasChar == MAXPBBUF) return FALSE; @@ -230,21 +244,35 @@ wrapsock_setPushBackChar (clientInfo *c, char ch) /* getSizeOfClientInfo - returns the sizeof (opaque data type). */ unsigned int -wrapsock_getSizeOfClientInfo (void) +EXPORT(getSizeOfClientInfo) (void) { return sizeof (clientInfo); } #endif -/* GNU Modula-2 link fodder. */ + +/* GNU Modula-2 linking hooks. */ + +void +M2EXPORT(init) (int, char **, char **) +{ +} void -_M2_wrapsock_init (void) +M2EXPORT(fini) (int, char **, char **) { } void -_M2_wrapsock_fini (void) +M2EXPORT(dep) (void) +{ +} + +void __attribute__((__constructor__)) +M2EXPORT(ctor) (void) { + m2iso_M2RTS_RegisterModule ("wrapsock", M2LIBNAME, + M2EXPORT(init), M2EXPORT(fini), + M2EXPORT(dep)); } diff --git a/libgm2/libm2iso/wraptime.c b/libgm2/libm2iso/wraptime.c deleted file mode 100644 index 6d6929b..0000000 --- a/libgm2/libm2iso/wraptime.c +++ /dev/null @@ -1,408 +0,0 @@ -/* wraptime.c provides access to time related system calls. - -Copyright (C) 2009-2022 Free Software Foundation, Inc. -Contributed by Gaius Mulley . - -This file is part of GNU Modula-2. - -GNU Modula-2 is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3, or (at your option) -any later version. - -GNU Modula-2 is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -. */ - -#include "config.h" - -#if defined(HAVE_SYS_TYPES_H) -#include "sys/types.h" -#endif - -#if defined(HAVE_SYS_TIME_H) -#include "sys/time.h" -#endif - -#if defined(HAVE_TIME_H) -#include "time.h" -#endif - -#if defined(HAVE_MALLOC_H) -#include "malloc.h" -#endif - -#if defined(HAVE_LIMITS_H) -#include "limits.h" -#endif - -#if !defined(TRUE) -#define TRUE (1 == 1) -#endif - -#if !defined(FALSE) -#define FALSE (1 == 0) -#endif - -#if !defined(NULL) -#define NULL (void *)0 -#endif - -/* InitTimeval returns a newly created opaque type. */ - -#if defined(HAVE_TIMEVAL) && defined(HAVE_MALLOC_H) -struct timeval * -wraptime_InitTimeval (void) -{ - return (struct timeval *)malloc (sizeof (struct timeval)); -} -#else -void * -wraptime_InitTimeval (void) -{ - return NULL; -} -#endif - -/* KillTimeval deallocates the memory associated with an opaque type. */ - -struct timeval * -wraptime_KillTimeval (void *tv) -{ -#if defined(HAVE_MALLOC_H) - free (tv); -#endif - return NULL; -} - -/* InitTimezone returns a newly created opaque type. */ - -#if defined(HAVE_STRUCT_TIMEZONE) && defined(HAVE_MALLOC_H) -struct timezone * -wraptime_InitTimezone (void) -{ - return (struct timezone *)malloc (sizeof (struct timezone)); -} -#else -void * -wraptime_InitTimezone (void) -{ - return NULL; -} -#endif - -/* KillTimezone - deallocates the memory associated with an opaque - type. */ - -struct timezone * -wraptime_KillTimezone (struct timezone *tv) -{ -#if defined(HAVE_MALLOC_H) - free (tv); -#endif - return NULL; -} - -/* InitTM - returns a newly created opaque type. */ - -#if defined(HAVE_STRUCT_TM) && defined(HAVE_MALLOC_H) -struct tm * -wraptime_InitTM (void) -{ - return (struct tm *)malloc (sizeof (struct tm)); -} -#else -void * -wraptime_InitTM (void) -{ - return NULL; -} -#endif - -/* KillTM - deallocates the memory associated with an opaque type. */ - -struct tm * -wraptime_KillTM (struct tm *tv) -{ -#if defined(HAVE_MALLOC_H) - free (tv); -#endif - return NULL; -} - -/* gettimeofday - calls gettimeofday(2) with the same parameters, tv, - and, tz. It returns 0 on success. */ - -#if defined(HAVE_STRUCT_TIMEZONE) && defined(HAVE_GETTIMEOFDAY) -int -wraptime_gettimeofday (void *tv, struct timezone *tz) -{ - return gettimeofday (tv, tz); -} -#else -int -wraptime_gettimeofday (void *tv, void *tz) -{ - return -1; -} -#endif - -/* settimeofday - calls settimeofday(2) with the same parameters, tv, - and, tz. It returns 0 on success. */ - -#if defined(HAVE_STRUCT_TIMEZONE) && defined(HAVE_SETTIMEOFDAY) -int -wraptime_settimeofday (void *tv, struct timezone *tz) -{ - return settimeofday (tv, tz); -} -#else -int -wraptime_settimeofday (void *tv, void *tz) -{ - return -1; -} -#endif - -/* wraptime_GetFractions - returns the tv_usec field inside the - timeval structure. */ - -#if defined(HAVE_TIMEVAL) -unsigned int -wraptime_GetFractions (struct timeval *tv) -{ - return (unsigned int)tv->tv_usec; -} -#else -unsigned int -wraptime_GetFractions (void *tv) -{ - return (unsigned int)-1; -} -#endif - -/* localtime_r - returns the tm parameter, m, after it has been - assigned with appropriate contents determined by, tv. Notice that - this procedure function expects, timeval, as its first parameter - and not a time_t (as expected by the posix equivalent). */ - -#if defined(HAVE_TIMEVAL) -struct tm * -wraptime_localtime_r (struct timeval *tv, struct tm *m) -{ - return localtime_r (&tv->tv_sec, m); -} -#else -struct tm * -wraptime_localtime_r (void *tv, struct tm *m) -{ - return m; -} -#endif - -/* wraptime_GetYear - returns the year from the structure, m. */ - -#if defined(HAVE_STRUCT_TM) -unsigned int -wraptime_GetYear (struct tm *m) -{ - return m->tm_year; -} -#else -unsigned int -wraptime_GetYear (void *m) -{ - return (unsigned int)-1; -} -#endif - -/* wraptime_GetMonth - returns the month from the structure, m. */ - -#if defined(HAVE_STRUCT_TM) -unsigned int -wraptime_GetMonth (struct tm *m) -{ - return m->tm_mon; -} -#else -unsigned int -wraptime_GetMonth (void *m) -{ - return (unsigned int)-1; -} -#endif - -/* wraptime_GetDay - returns the day of the month from the structure, - m. */ - -#if defined(HAVE_STRUCT_TM) -unsigned int -wraptime_GetDay (struct tm *m) -{ - return m->tm_mday; -} -#else -unsigned int -wraptime_GetDay (void *m) -{ - return (unsigned int)-1; -} -#endif - -/* wraptime_GetHour - returns the hour of the day from the structure, - m. */ - -#if defined(HAVE_STRUCT_TM) -unsigned int -wraptime_GetHour (struct tm *m) -{ - return m->tm_hour; -} -#else -unsigned int -wraptime_GetHour (void *m) -{ - return (unsigned int)-1; -} -#endif - -/* wraptime_GetMinute - returns the minute within the hour from the - structure, m. */ - -#if defined(HAVE_STRUCT_TM) -unsigned int -wraptime_GetMinute (struct tm *m) -{ - return m->tm_min; -} -#else -unsigned int -wraptime_GetMinute (void *m) -{ - return (unsigned int)-1; -} -#endif - -/* wraptime_GetSecond - returns the seconds in the minute from the - structure, m. The return value will always be in the range 0..59. - A leap minute of value 60 will be truncated to 59. */ - -#if defined(HAVE_STRUCT_TM) -unsigned int -wraptime_GetSecond (struct tm *m) -{ - if (m->tm_sec == 60) - return 59; - else - return m->tm_sec; -} -#else -unsigned int -wraptime_GetSecond (void *m) -{ - return (unsigned int)-1; -} -#endif - -/* wraptime_GetSummerTime - returns true if summer time is in effect. */ - -#if defined(HAVE_STRUCT_TIMEZONE) -unsigned int -wraptime_GetSummerTime (struct timezone *tz) -{ - return tz->tz_dsttime != 0; -} -#else -unsigned int -wraptime_GetSummerTime (void *tz) -{ - return FALSE; -} -#endif - -/* wraptime_GetDST - returns the number of minutes west of GMT. */ - -#if defined(HAVE_STRUCT_TIMEZONE) -int -wraptime_GetDST (struct timezone *tz) -{ - return tz->tz_minuteswest; -} -#else -int -wraptime_GetDST (void *tz) -{ -#if defined(INT_MIN) - return INT_MIN; -#else - return (int)((unsigned int)-1); -#endif -} -#endif - -/* SetTimezone - set the timezone field inside timeval, tv. */ - -#if defined(HAVE_STRUCT_TIMEZONE) -void -wraptime_SetTimezone (struct timezone *tz, int zone, int minuteswest) -{ - tz->tz_dsttime = zone; - tz->tz_minuteswest = minuteswest; -} -#else -void -wraptime_SetTimezone (void *tz, int zone, int minuteswest) -{ -} -#endif - -/* SetTimeval - sets the fields in tm, t, with: second, minute, hour, - day, month, year, fractions. */ - -#if defined(HAVE_TIMEVAL) -void -wraptime_SetTimeval (struct tm *t, unsigned int second, unsigned int minute, - unsigned int hour, unsigned int day, unsigned int month, - unsigned int year, unsigned int yday, unsigned int wday, - unsigned int isdst) -{ - t->tm_sec = second; - t->tm_min = minute; - t->tm_hour = hour; - t->tm_mday = day; - t->tm_mon = month; - t->tm_year = year; - t->tm_yday = yday; - t->tm_wday = wday; - t->tm_isdst = isdst; -} -#else -void -wraptime_SetTimeval (void *t, unsigned int second, unsigned int minute, - unsigned int hour, unsigned int day, unsigned int month, - unsigned int year, unsigned int yday, unsigned int wday, - unsigned int isdst) -{ -} -#endif - -/* init - init/finish functions for the module */ - -void -_M2_wraptime_init () -{ -} -void -_M2_wraptime_fini () -{ -} diff --git a/libgm2/libm2iso/wraptime.cc b/libgm2/libm2iso/wraptime.cc new file mode 100644 index 0000000..3cdc385 --- /dev/null +++ b/libgm2/libm2iso/wraptime.cc @@ -0,0 +1,429 @@ +/* wraptime.c provides access to time related system calls. + +Copyright (C) 2009-2022 Free Software Foundation, Inc. +Contributed by Gaius Mulley . + +This file is part of GNU Modula-2. + +GNU Modula-2 is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GNU Modula-2 is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "config.h" +#include + +#define EXPORT(FUNC) m2iso ## _wraptime_ ## FUNC +#define M2EXPORT(FUNC) m2iso ## _M2_wraptime_ ## FUNC +#define M2LIBNAME "m2iso" + +#if defined(HAVE_SYS_TYPES_H) +#include "sys/types.h" +#endif + +#if defined(HAVE_SYS_TIME_H) +#include "sys/time.h" +#endif + +#if defined(HAVE_TIME_H) +#include "time.h" +#endif + +#if defined(HAVE_MALLOC_H) +#include "malloc.h" +#endif + +#if defined(HAVE_LIMITS_H) +#include "limits.h" +#endif + +#if !defined(TRUE) +#define TRUE (1 == 1) +#endif + +#if !defined(FALSE) +#define FALSE (1 == 0) +#endif + +#if !defined(NULL) +#define NULL (void *)0 +#endif + +/* InitTimeval returns a newly created opaque type. */ + +#if defined(HAVE_TIMEVAL) && defined(HAVE_MALLOC_H) +extern "C" struct timeval * +EXPORT(InitTimeval) (void) +{ + return (struct timeval *)malloc (sizeof (struct timeval)); +} +#else +extern "C" void * +EXPORT(InitTimeval) (void) +{ + return NULL; +} +#endif + +/* KillTimeval deallocates the memory associated with an opaque type. */ + +extern "C" struct timeval * +EXPORT(KillTimeval) (void *tv) +{ +#if defined(HAVE_MALLOC_H) + free (tv); +#endif + return NULL; +} + +/* InitTimezone returns a newly created opaque type. */ + +#if defined(HAVE_STRUCT_TIMEZONE) && defined(HAVE_MALLOC_H) +extern "C" struct timezone * +EXPORT(InitTimezone) (void) +{ + return (struct timezone *)malloc (sizeof (struct timezone)); +} +#else +extern "C" void * +EXPORT(InitTimezone) (void) +{ + return NULL; +} +#endif + +/* KillTimezone - deallocates the memory associated with an opaque + type. */ + +extern "C" struct timezone * +EXPORT(KillTimezone) (struct timezone *tv) +{ +#if defined(HAVE_MALLOC_H) + free (tv); +#endif + return NULL; +} + +/* InitTM - returns a newly created opaque type. */ + +#if defined(HAVE_STRUCT_TM) && defined(HAVE_MALLOC_H) +extern "C" struct tm * +EXPORT(InitTM) (void) +{ + return (struct tm *)malloc (sizeof (struct tm)); +} +#else +extern "C" void * +EXPORT(InitTM) (void) +{ + return NULL; +} +#endif + +/* KillTM - deallocates the memory associated with an opaque type. */ + +extern "C" struct tm * +EXPORT(KillTM) (struct tm *tv) +{ +#if defined(HAVE_MALLOC_H) + free (tv); +#endif + return NULL; +} + +/* gettimeofday - calls gettimeofday(2) with the same parameters, tv, + and, tz. It returns 0 on success. */ + +#if defined(HAVE_STRUCT_TIMEZONE) && defined(HAVE_GETTIMEOFDAY) +extern "C" int +EXPORT(gettimeofday) (void *tv, struct timezone *tz) +{ + return gettimeofday (tv, tz); +} +#else +extern "C" int +EXPORT(gettimeofday) (void *tv, void *tz) +{ + return -1; +} +#endif + +/* settimeofday - calls settimeofday(2) with the same parameters, tv, + and, tz. It returns 0 on success. */ + +#if defined(HAVE_STRUCT_TIMEZONE) && defined(HAVE_SETTIMEOFDAY) +extern "C" int +EXPORT(settimeofday) (void *tv, struct timezone *tz) +{ + return settimeofday (tv, tz); +} +#else +extern "C" int +EXPORT(settimeofday) (void *tv, void *tz) +{ + return -1; +} +#endif + +/* wraptime_GetFractions - returns the tv_usec field inside the + timeval structure. */ + +#if defined(HAVE_TIMEVAL) +extern "C" unsigned int +EXPORT(GetFractions) (struct timeval *tv) +{ + return (unsigned int)tv->tv_usec; +} +#else +extern "C" unsigned int +EXPORT(GetFractions) (void *tv) +{ + return (unsigned int)-1; +} +#endif + +/* localtime_r - returns the tm parameter, m, after it has been + assigned with appropriate contents determined by, tv. Notice that + this procedure function expects, timeval, as its first parameter + and not a time_t (as expected by the posix equivalent). */ + +#if defined(HAVE_TIMEVAL) +extern "C" struct tm * +EXPORT(localtime_r) (struct timeval *tv, struct tm *m) +{ + return localtime_r (&tv->tv_sec, m); +} +#else +extern "C" struct tm * +EXPORT(localtime_r) (void *tv, struct tm *m) +{ + return m; +} +#endif + +/* wraptime_GetYear - returns the year from the structure, m. */ + +#if defined(HAVE_STRUCT_TM) +extern "C" unsigned int +EXPORT(GetYear) (struct tm *m) +{ + return m->tm_year; +} +#else +extern "C" unsigned int +EXPORT(GetYear) (void *m) +{ + return (unsigned int)-1; +} +#endif + +/* wraptime_GetMonth - returns the month from the structure, m. */ + +#if defined(HAVE_STRUCT_TM) +extern "C" unsigned int +EXPORT(GetMonth) (struct tm *m) +{ + return m->tm_mon; +} +#else +extern "C" unsigned int +EXPORT(GetMonth) (void *m) +{ + return (unsigned int)-1; +} +#endif + +/* wraptime_GetDay - returns the day of the month from the structure, + m. */ + +#if defined(HAVE_STRUCT_TM) +extern "C" unsigned int +EXPORT(GetDay) (struct tm *m) +{ + return m->tm_mday; +} +#else +extern "C" unsigned int +EXPORT(GetDay) (void *m) +{ + return (unsigned int)-1; +} +#endif + +/* wraptime_GetHour - returns the hour of the day from the structure, + m. */ + +#if defined(HAVE_STRUCT_TM) +extern "C" unsigned int +EXPORT(GetHour) (struct tm *m) +{ + return m->tm_hour; +} +#else +extern "C" unsigned int +EXPORT(GetHour) (void *m) +{ + return (unsigned int)-1; +} +#endif + +/* wraptime_GetMinute - returns the minute within the hour from the + structure, m. */ + +#if defined(HAVE_STRUCT_TM) +extern "C" unsigned int +EXPORT(GetMinute) (struct tm *m) +{ + return m->tm_min; +} +#else +extern "C" unsigned int +EXPORT(GetMinute) (void *m) +{ + return (unsigned int)-1; +} +#endif + +/* wraptime_GetSecond - returns the seconds in the minute from the + structure, m. The return value will always be in the range 0..59. + A leap minute of value 60 will be truncated to 59. */ + +#if defined(HAVE_STRUCT_TM) +extern "C" unsigned int +EXPORT(GetSecond) (struct tm *m) +{ + if (m->tm_sec == 60) + return 59; + else + return m->tm_sec; +} +#else +extern "C" unsigned int +EXPORT(GetSecond) (void *m) +{ + return (unsigned int)-1; +} +#endif + +/* wraptime_GetSummerTime - returns true if summer time is in effect. */ + +#if defined(HAVE_STRUCT_TIMEZONE) +extern "C" unsigned int +EXPORT(GetSummerTime) (struct timezone *tz) +{ + return tz->tz_dsttime != 0; +} +#else +extern "C" unsigned int +EXPORT(GetSummerTime) (void *tz) +{ + return FALSE; +} +#endif + +/* wraptime_GetDST - returns the number of minutes west of GMT. */ + +#if defined(HAVE_STRUCT_TIMEZONE) +extern "C" int +EXPORT(GetDST) (struct timezone *tz) +{ + return tz->tz_minuteswest; +} +#else +extern "C" int +EXPORT(GetDST) (void *tz) +{ +#if defined(INT_MIN) + return INT_MIN; +#else + return (int)((unsigned int)-1); +#endif +} +#endif + +/* SetTimezone - set the timezone field inside timeval, tv. */ + +#if defined(HAVE_STRUCT_TIMEZONE) +extern "C" void +EXPORT(SetTimezone) (struct timezone *tz, int zone, int minuteswest) +{ + tz->tz_dsttime = zone; + tz->tz_minuteswest = minuteswest; +} +#else +extern "C" void +EXPORT(SetTimezone) (void *tz, int zone, int minuteswest) +{ +} +#endif + +/* SetTimeval - sets the fields in tm, t, with: second, minute, hour, + day, month, year, fractions. */ + +#if defined(HAVE_TIMEVAL) +extern "C" void +EXPORT(SetTimeval) (struct tm *t, unsigned int second, unsigned int minute, + unsigned int hour, unsigned int day, unsigned int month, + unsigned int year, unsigned int yday, unsigned int wday, + unsigned int isdst) +{ + t->tm_sec = second; + t->tm_min = minute; + t->tm_hour = hour; + t->tm_mday = day; + t->tm_mon = month; + t->tm_year = year; + t->tm_yday = yday; + t->tm_wday = wday; + t->tm_isdst = isdst; +} +#else +extern "C" void +EXPORT(SetTimeval) (void *t, unsigned int second, unsigned int minute, + unsigned int hour, unsigned int day, unsigned int month, + unsigned int year, unsigned int yday, unsigned int wday, + unsigned int isdst) +{ +} +#endif + +/* init - init/finish functions for the module */ + +/* GNU Modula-2 linking hooks. */ + +extern "C" void +M2EXPORT(init) (int, char **, char **) +{ +} + +extern "C" void +M2EXPORT(fini) (int, char **, char **) +{ +} + +extern "C" void +M2EXPORT(dep) (void) +{ +} + +extern "C" void __attribute__((__constructor__)) +M2EXPORT(ctor) (void) +{ + m2iso_M2RTS_RegisterModule ("wraptime", M2LIBNAME, + M2EXPORT(init), M2EXPORT(fini), + M2EXPORT(dep)); +} -- cgit v1.1