Cython file write - cython

I have a sample '.pyx' file
Here, certain mmap operation has been done (via C mmap) and the and 'data_len' has been returned
I want to read from the offset start upto the data_len area, AND dump it to a random file
I am doing this by the following: BUT, getting Syntax error while doing 'write' operation
cdef void *startmmaparea
def do_dump()
offset= <char *> startmmaparea
...
with open('abc.bin','wb') as fdes:
fdes.write(offset.read(data_len))
...
expected to write the mmap content to the file. but getting Syntax error in the 'write' op
Can I write the using the read() as I have done above ?
- Can anyone help me with what I am doing wrong here ?

Related

Error accessing a module function

I have a problem with basic module usage in Lua. I have one file "helloworld.lua" and a second file "main.lua". I would like to call a function from the first file inside the second file. But I am getting an error:
attempt to call field 'printText' (a nil value)
My actual code is below. Can someone tell me where the problem is?
helloworld.lua
local module = {}
function module.printText()
print("Hello world")
end
return module
main.lua
hello = require("helloworld")
hello.printText()
As mentioned in the comments, this is the right way to do it. This could be a problem if there is a conflicting helloworld module, or if you have a running lua state and are modifying the files without starting a new one.
require will only load the module passed with a string once. Check package.loaded["helloworld"]. You can set this to nil so that require will load the file again:
package.loaded["helloworld"] = nil
hello = require("helloworld") -- will load it for sure

My function in Octave doesn't work

I'm working with Octave4.2.1 and I have written this function (in the file OctaveFunction.m):
function y = squareNumber(x)
y = x^2;
endfunction
but if I call the function, I get this error:
error: 'squareNumber' undefined near line 1 column 1
and if I try to call the function in this way:
OctaveFunction squareNumber(4)
I get another error:
warning: function name 'squareNumber' does not agree with function filename 'C:\Users\HOME\Desktop\OctaveFunction.m'
error: for x^A, A must be a square matrix. Use .^ for elementwise power.
error: called from
OctaveFunction at line 2 column 7
Where did I go wrong? Thank you!
I think the main problem is that your file name does not match the function name. If you were to match these, this should resolve your first error.
Regarding the elementwise power error: If given the proper input (4) this should not lead to an error, as 4 is obviously a square matrix.
Hence it seems that some undesired input is fed to your function, but again this problem is likely to disappear if you rename the file to match the functionname, and call the function as usual. (so without OctaveFunction).
You Must rename your file such as your function name
for example: your file name is (main.m) and your function name is (main)

2to3 bug: tuple index out of range, fix_raise

I have found what looks like a not tested case to me. When trying to convert following code with 2to3:
def test(arg):
raise()
The execution stops ungracefully with no indication why, nor what file caused the problem, this is very annoying if you are trying to convert a whole folder of python 2 scripts. The following is thrown:
...
exc= exc.children[1].children[0].clone()
IndexError: tuple out of range
I am expecting to obtain a BadInput exception. Clearly, given the source code just above, it is expecting raise("something") and since there is no check that "children" inside the tuple of raise () is even present, this causes error.
Please correct me if I am wrong, of course raise() is incorrect, but this should not crash the execution, likewise the following:
def test(arg):
print 1.method()
Throws BadInput exception with a clear indication what happened.

How long is a line after a readline(fh, line) call?

I have written a JSON parser in VHDL. The parser core uses two nested loops:
1. loop over all lines until EOF
2. loop over every char until line of end
For clearance: Its not a hardware parser. the parser used to read synthesis settings at synthesis time to configure instantiated entities like a baudrate in a UART module.)
The inner loop looks like this: loopj : for j in CurrentLine.all'range loop
Source: JSON.pkg.vhdl
This code works in XST 14.7, iSim 14.7 and GHDL, but not in Vivado. Vivado does not support .all. The error message is this one:
ERROR: [Synth 8-27] access type dereference not supported [D:/git/GitHub/JSON-for-VHDL/vhdl/JSON.pkg.vhdl:293]
Updated code, due to the hint from kraigher:
#Paebbles Have you tried foo'range instead of foo.all'range? I think I remember that it should implicitly work. - kraigher
I tried it before, but got an error. Maybe this error was related to another one. Now its working. So my current loopj line looks like this:
loopj : for j in CurrentLine'range loop
This line works fine in XST, iSim, GHDL and QuestaSim, but Vivado still has problems:
INFO: [Synth 8-638] synthesizing module 'Boards2' [.../Boards2.vhdl:16]
ERROR: [Synth 8-278] expression 0 out of range [.../JSON.pkg.vhdl:293]
ERROR: [Synth 8-421] mismatched array sizes in rhs and lhs of assignment [.../Boards2.vhdl:20]
ERROR: [Synth 8-285] failed synthesizing module 'Boards2' [.../Boards2.vhdl:16]
How can a expression be out of range? This message is very strange.
Is there another way to get a range for a loop, depending on how long the current line is?

MailCore2 MCHTMLCleaner error

While using MailCore2, I started getting an error in MCHTMLCleaner.cc and method HTMLCleaner::cleanHTML. The specific line that is throwing the error is:
rc = tidySetErrorBuffer(tdoc, &errbuf);
and the error being printed is:
'Assertion failed: (option_defs[ optId ].type == TidyInteger), function SetOptionInt, file ../../src/config.c, line 381'
In config.c on line 381 is:
Bool status = ( optId < N_TIDY_OPTIONS );
Occasionally, this will crash the app, which seems contrary to the entire idea of a try/catch block that would make the most sense here.
More often than not, this code/file will not stop the app and instead just print out an error.
What is causing this to crash? Has anyone else experienced this? IS the HTML actually being cleaned or is nothing being returned for you?
Here is a link to the specific file in question on GitHub.