how to avoid loops when loading modules in lua - module

I have a situation where I need to use two modules... both of which load / reference another module. So I'm getting an error about a loop.
Here's the code in module1:
require("posix")
posix.setenv("PATH", "/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin")
and in module 2 I have the same thing:
require("posix")
local ts = posix.stat(spath, "ctime")
I found this post:
Lua: How to avoid Circular Requires
I tried to apply what the above post said and I changed my logic in both modules to look like this:
posix = posix or require("posix")
But I'm still getting the error message.
Any suggestions would be appreciated.
EDIT 1
tester.lua
local main =require("main")
main.lua
module (..., package.seeall)
-- Load libraries
require("commonfunctions")
require("luasql.postgres")
require("session")
commonfunctions.lua
posix = posix or require "posix"
session.lua
posix = posix or require "posix"
Error Message
lua: /usr/share/acf/lib//session.lua:15: loop or previous error loading module 'posix'
stack traceback:
[C]: in function 'require'
/usr/share/lib//session.lua:15: in main chunk
[C]: in function 'require'
/usr/share/myapp/main.lua:10: in main chunk
[C]: in function 'require'
/usr/share/lua/5.1/posix.lua:2: in main chunk
[C]: in function 'require'
/usr/share/acf/lib//commonfunctions.lua:4: in main chunk
[C]: in function 'require'
./kamfmfm-model.lua:3: in main chunk
[C]: in function 'require'
tester.lua:6: in main chunk
[C]: ?

Related

using txm_module_manager_memory_load to load Module in ThreadX

I am trying to load 2 modules differently:
Module_1 using txm_module_manager_memory_load
Module_2 using txm_module_manager_in_place_load
Results: Just after loading them and starting Module_1, it throws a UsageFault error (Module 2 didn't start yet), both modules share the same byte_pool created from txm_module_manager_initialize.
I could not catch the error since all APIs return TX_SUCCESS
Referring to the x-cube-azrtos-h7 TX-MPU example, what would change to app_threadX to load Module_1 properly?
Or is it about something to specify in link file STM32H7xx_FLASH.ld?
EDIT: the following is the latest threads status and "_txm_module_manager_memory_fault_info" value :
ThreadX will allocate some memory from the byte pool created in txm_module_manager_initialize and copy Module_1 from wherever it is located into that allocated memory. I assume txm_module_manager_memory_load returns TX_SUCCESS, as does txm_module_manager_start when you start Module_1. Can you step through the scheduler and when it schedules a thread from Module_1 (the first thread it will schedule is the "Module Start Thread" that gets created in txm_module_manager_start), how far into the module execution does the usage fault occur?

Error occurred when loading a custom Julia module

I have been puzzled by how to define and use custom module in Julia.
For example, I defined a module named myMoldule to wrap a mutable struct Param and a function add in D:\\run\\defineModule.jl:
module myMoldule
export Param, add
mutable struct Param
x ::Int64
y ::Int64
end
function add(x::Int64, y::Int64)
sum ::Int64
sum = x + y
return sum
end
end
and used this module in D:\\run\\useModule.jl like:
include("D:\\run\\defineModule.jl")
using .myMoldule
function testModule()
param = Param(1, 2)
sum = add(param.x, param.y)
println(sum)
end
An error occurred when running testModule() as follows:
julia> testModule()
ERROR: UndefVarError: Param not defined
Stacktrace:
[1] testModule() at D:\run\useModule.jl:8
[2] top-level scope at none:1
Note that I used the absolute path in the include(...) to avoid using LOAD_PATH stuff, and added . before the module name (i.e., using .myMoldule).
What seems to be the problem?
P.S.: Julia version information:
julia> versioninfo()
Julia Version 1.5.2
Commit 539f3ce943 (2020-09-23 23:17 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-8700K CPU # 3.70GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
JULIA_DEPOT_PATH = C:\Users\f\.julia;C:\opt\JuliaPro-1.5.2-1\Julia-1.5.2\local\share\julia;C:\opt\JuliaPro-1.5.2-1\Julia-1.5.2\share\julia
JULIA_LOAD_PATH = #;#v#.#;#stdlib
JULIA_NUM_THREADS = 6
JULIA_PKG_SERVER = pkg.juliahub.com
Corrections to be made:
sum is a function in Base you should use a different name
no need to declare sum variable (and it should be named something like mysum)
Remove space before ::
Module names should start with a CapitalLetter
You have a typo in module name perhaps you are loading a different module than you think?
Once corrected your code works.
The issue happens because you are using .MyModule1, not in the MyModule2, and thus you import Param to the Main module but not to the MyModule2, thus Module2 does not see Param.
If you will put using ..MyModule1 (two dots instead of one as you there is one more level) into MyModule2 this issue will go.
However, your code still will not work, since julia's include function just runs all the content of the included file, thus even you included the same file, you will create different instances of the modules. This warning WARNING: replacing module... indicates that somewhere in your code you might use the different version of the module (in you case, Main.Module1 and Main.Module2.Module1).
The common practice in julia is to include all the files in one place (they should be included only once). For instance, you can put all the includes in the file useModule.jl:
include("./defineModule1.jl")
include("./defineModule2.jl")
using .MyModule1
using .MyModule2
function testModule()
param = Param(1, 2)
# call myAdd to get the sum of param.x and param.y
sumValue = myAdd(param)
println(sumValue)
# call mySubtract to get the difference of param.x and param.y
difValue = mySubtract(param)
println(difValue)
end
Do not include files in other places. e.g.
defineModule2.jl content:
module MyModule2
using ..MyModule1
export myAdd, mySubtract
function myAdd(param::Param)
return param.x + param.y
end
function mySubtract(param::Param)
return param.x - param.y
end
end # end of module
Questioner's note: The following new question voted downwards (perhaps) was extended form the original one and was well answered by Vitaliy Yakovchuk.
I fixed all the issues pointed out by Przemyslaw Szufel. In my case above, it's not the improper ways of naming that cause the issue.
Now, I have a better exmaple to clarify my issue.
Suppose that, to meet the needs, I have to seperate my julia source code into two modules, e.g., define of a mutable struct Param in defineModule1.jl and define of functions in defineModule2.jl. The code scripts are as follows:
"D:\\run\\defineModule1.jl":
module MyModule1
export Param
mutable struct Param
x::Int64
y::Int64
end
end # end of module
"D:\\run\\defineModule2.jl":
include("D:\\run\\defineModule1.jl"); using .MyModule1
module MyModule2
export myAdd, mySubtract
function myAdd(param::Param)
return param.x + param.y
end
function mySubtract(param::Param)
return param.x - param.y
end
end # end of module
Note that Param is not defined here, and to make Param available, a line include("D:\\run\\defineModule1.jl"); using .MyModule1 is added as the first line of this file.
"D:\\run\\useModule.jl":
include("D:\\run\\defineModule1.jl"); using .MyModule1
include("D:\\run\\defineModule2.jl"); using .MyModule2
function testModule()
param = Param(1, 2)
# call myAdd to get the sum of param.x and param.y
sumValue = myAdd(param)
println(sumValue)
# call mySubtract to get the difference of param.x and param.y
difValue = mySubtract(param)
println(difValue)
end
Note that both function myAdd(param) and mySubtract(param) in the script defineModule2.jl need the predefined mutable struct Param in defineModule1.jl.
This is what I got when I run D:\\run\\useModule.jl:
julia> include("D:\\run\\useModule.jl")
WARNING: replacing module MyModule1.
WARNING: replacing module MyModule1.
WARNING: replacing module MyModule2.
ERROR: LoadError: LoadError: UndefVarError: Param not defined
Stacktrace:
[1] top-level scope at D:\run\defineModule2.jl:7
[2] include(::String) at .\client.jl:457
[3] top-level scope at D:\run\useModule.jl:2
[4] include(::String) at .\client.jl:457
[5] top-level scope at none:1
in expression starting at D:\run\defineModule2.jl:7
in expression starting at D:\run\useModule.jl:2
I believed that, by using the following lines in the beginning of "D:\run\useModule.jl", the mutable struct Param should have be found:
include("D:\\run\\defineModule1.jl"); using .MyModule1
include("D:\\run\\defineModule2.jl"); using .MyModule2
...
Still, error LoadError: UndefVarError: Param not defined is reported.
So, Why can't Param be found by D:\\run\\useModule.jl?

I need help upgrading OroCommerce to 4.1.1

I just upgraded from 3.1.17 to 4.1.1 and I'm finding a problem with my shopping lists.
When I get to /customer/shoppinglist/5064 I see this:
Looking at my log files from production I see:
[2020-06-23 17:42:56] request.CRITICAL: Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\UndefinedMethodError: "Attempted to call an undefined method named "getDigitalAsset" of class "Proxies\__CG__\Oro\Bundle\AttachmentBundle\Entity\File"." at /usr/share/nginx/html/oroapp/vendor/oro/platform/src/Oro/Bundle/DigitalAssetBundle/Provider/FileTitleProvider.php line 47 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Attempted to call an undefined method named \"getDigitalAsset\" of class \"Proxies\\__CG__\\Oro\\Bundle\\AttachmentBundle\\Entity\\File\". at /usr/share/nginx/html/oroapp/vendor/oro/platform/src/Oro/Bundle/DigitalAssetBundle/Provider/FileTitleProvider.php:47)"} []
I went to look at the code and I see that in fact there is no method getDigitalAsset in oro/platform/src/Oro/Bundle/DigitalAssetBundle/Provider/FileTitleProvider.php, nor in the proxy... how can this be?
I checked this on my VM (where the problem is not happening) and I see that there's this definition in the proxy class:
/**
* {#inheritDoc}
*/
public function getDigitalAsset()
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getDigitalAsset', []);
return parent::getDigitalAsset();
}
But again, I don't see a method called getDigitalAsset in the parent class.
I had some issues when doing the upgrade (I realized my nodejs wasn't upgraded as I thought it was), could that have anything to do with the issue?
Thanks
Edit:
I went through my platform upgrade again and found that there were some problems that prevented it from finishing completely.
This is what I found:
> loading Oro\Bundle\CMSBundle\Migrations\Data\ORM\LoadImageSlider
In LoadImageSlider.php line 117:
Attempted to call an undefined method named "setMainImage" of class "Oro\Bundle\CMSBundle\Entity\ImageSlide".
I commented out the loop inside the load method and re-run the upgrade. Then I got:
> loading Oro\Bundle\CMSBundle\Migrations\Data\ORM\LoadImageSlider
In QueryException.php line 65:
[Semantical Error] line 0, col 117 near 'digitalAsset': Error: Class Oro\Bundle\AttachmentBundle\Entity\File has no association named digitalAsset
In QueryException.php line 43:
SELECT file, digitalAsset, sourceFile FROM Oro\Bundle\AttachmentBundle\Entity\File file INNER JOIN file.digitalAsset digitalAsset INNER JOIN digitalAsset.sourceFile sourceFile WHERE file.parentEntityClass = :parentEntityClass
AND file.parentEntityId = :parentEntityId AND file.parentEntityFieldName =
:parentEntityFieldName
Finally I was able to complete the upgrade by commenting out the whole body of the load method
I had some issues when doing the upgrade (I realized my nodejs wasn't upgraded as I thought it was), could that have anything to do with the issue?
It looks like you have multiple versions of nodejs installed. To make an application use the right one, you can provide the absolute path to the executable with the AssetBundle configuration, like:
# config/config.yml
oro_asset:
nodejs_path: /usr/local/node
npm_path: /usr/local/npm

How do I get Boost.Serialization to work with PhysicsFS

I would like to use PhysFS in conjunction with Boost.Serialization. I found an implementation here which uses Boost.Iostreams to create a PhysFS file stream. It works for basic operations, buy if I try ti use it with Boost.Serialization, I get the following error during runtime:
/usr/include/boost/iostreams/detail/optional.hpp:55: T& boost::iostreams::detail::optional<T>::operator*() [with T = boost::iostreams::detail::concept_adapter<PhysFS::FileDevice>]: Assertion `initialized_' failed.
Aborted
here is an example of the code.
PhysFS::init(argv[0]);
PhysFS::setWriteDir(".");
PhysFS::FileStream ofs("test.xml", PhysFS::OM_WRITE);
boost::archive::xml_oarchive xml(ofs);
vec2 vec(3.1415, 2.5);
xml << BOOST_SERIALIZATION_NVP(vec);
ofs.close();
PhysFS::deinit();
Is there any way to get a working file stream wrapper for PhysFS that will work with libraries like Boost.Serialization?
My mistake was calling ofs.close(), and also calling PhysFS::deinit before the destruction of ofs.

Fortran Module Version Fatal Error

I have a very scary error on Fortran 95:
Fatal Error: While reading module 'list5.mod' found module version 0, expected 6
I have included the main structure of my module. I highly doubt it has anything to do with the substance inside my module since it has given me error messages on those and I have been able to fix them which means it is able to go through my module fine it is just something small related to the way I use the module. Perhaps?
MODULE list5
IMPLICIT NONE
CONTAINS
----
END MODULE
The main program is structured something like this:
PROGRAM mainlist
USE list5
IMPLICIT NONE
!Variable Declaration
INTEGER:: opt
INTEGER, PARAMETER:: maxitems=50
INTEGER:: size=0
CHARACTER(20):: itemarray(50)
INTEGER:: quantityarray(50)
INTEGER:: totalquantity, i=0
REAL:: totalprice=0, pricearray(50)=0
CHARACTER(20), DIMENSION(:)::Item
CHARACTER(20):: ItemSought
LOGICAL:: Found
INTEGER:: Location
INTEGER:: NumItems=0, SmallestItem=0
!Select statement for the menu
DO
opt=choices()
SELECT CASE (opt)
CASE(1)
size=size+1
CALL getItemData(itemarray,pricearray,quantityarray)
CASE(2)
CALL getFileItems(size,itemarray,pricearray,quantityarray)
CASE(3)
CALL pickItemRandomly (size)
CASE(4)
CALL calcListTotals
(pricearray,quantityarray,totalprice,totalquantity)
CALL printList(size,itemarray,pricearray,quantityarray,totalprice, totalquantity)
CASE(5)
CALL sortByItem(itemarray, pricearray, quantityarray)
CASE(6)
CALL sortByPrice(itemarray, pricearray, quantityarray)
CASE(7)
CALL writeListtoFile(size,itemarray, pricearray, quantityarray)
CASE(8)
CALL search(itemarray, ItemSought, Found, Location)
CASE(9)
STOP
END SELECT
END DO
END PROGRAM
Any suggestions at all?? I really need to solve this so any help would be appreciated. Thanks so much!!
As Rook says, the issue is with compiler versions; somehow the .mod file from by compiling list5 the first time around was generated by an older compiler. Clear out all your .o and .mod files, and try again, first compiling list5.f90 (or whatever the file containing module list5 is) and then compiling the main program.