Everything works fine until i get 'Unhandled Memory Exception Error'
My specs are: winxpPro sp2 AMD 64X2 dualcore 4400 and 2gb ram [300gb free disk].
I'm not postulating that your module is to blame for the error. Mainly i'm looking for assistance from someone who has more experience with C and this lib than I do. I've been working on this error non-stop for close to 2 days now.
Here are a few of my observations:
If im calling a C function the error consistantly fails at the 509th iteration on the function 'tcc_relocate'.
If the c program just has a 'main' function and i'm calling 'tcc_run' the program fails on that command after the same number of iterations.
Using 'printf' from the c function has no effect on the error.
the return type of the C function has no effect on the error.
Here is another example program. i'm bypassing the mod and the lib file altogether. Also the DLL should not be remaining in memory after each iteration. So my conjecture is that something outside of the GC is being accumulated, but I'm not sure if its in the DLL or in Bmax.
Is there something related to ZStrings that need to expunged manually??
Is there something about the 'tcc_relocate' command thats leaking memory?
Strict
Framework brl.basic
Import pub.win32
'''Import Cower.TCC
SeedRnd(MilliSecs())
Const TCC_OUTPUT_MEMORY% = 0
Const TCC_OUTPUT_EXE% = 1
Const TCC_OUTPUT_DLL% = 2
Const TCC_OUTPUT_OBJ% = 3
' Output formats
Const TCC_FORMAT_ELF% = 0
Const TCC_FORMAT_BINARY% = 1
Const TCC_FORMAT_COFF% = 2
Global count%
Global MyProgram$
MyProgram$ = "float arr(float a)~n"+..
"{~n"+..
" printf(~qhello\n~q);~n"+..
" return a*2.0+1.0;~n"+..
"}~n"
For Local I = 0 To 10000
Test
GCCollect
Next
Function Test()
Local Handle = loadlibrarya("E:\Dev\BlitzMax\tmp\libtcc.dll")
Local tcc_new@ Ptr() = getprocaddress(handle,"tcc_new")
Local tcc_delete(state@ Ptr) = getprocaddress(handle,"tcc_delete")
'Local tcc_enable_debug(state@ Ptr) = getprocaddress(handle,"tcc_enable_debug") '// This function does not exist in the dll//
Local tcc_set_error_func(state@ Ptr, opaque@ Ptr, error_func(opaque@ Ptr, msg@ Ptr)) = getprocaddress(handle,"tcc_set_error_func")
Local tcc_set_warning%(state@ Ptr, name$z, value%) = getprocaddress(handle,"tcc_set_warning")
Local tcc_add_include_path%(state@ Ptr, pathname$z) = getprocaddress(handle,"tcc_add_include_path")
Local tcc_add_sysinclude_path%(state@ Ptr, pathname$z) = getprocaddress(handle,"tcc_add_sysinclude_path")
Local tcc_define_symbol(state@ Ptr, pathname$z) = getprocaddress(handle,"tcc_define_symbol")
Local tcc_undefine_symbol(state@ Ptr, pathname$z) = getprocaddress(handle,"tcc_undefine_symbol")
Local tcc_add_file%(state@ Ptr, filename$z) = getprocaddress(handle,"tcc_add_file")
Local tcc_compile_string%(state@ Ptr, buf$z) = getprocaddress(handle,"tcc_compile_string")
Local tcc_set_output_type%(state@ Ptr, output_type%) = getprocaddress(handle,"tcc_set_output_type")
Local tcc_add_library_path%(state@ Ptr, path$z) = getprocaddress(handle,"tcc_add_library_path")
Local tcc_add_library%(state@ Ptr, libraryname$z) = getprocaddress(handle,"tcc_add_library")
Local tcc_add_symbol%(state@ Ptr, name$z, value%) = getprocaddress(handle,"tcc_add_symbol")
Local tcc_output_file%(state@ Ptr, filename$z) = getprocaddress(handle,"tcc_output_file")
Local tcc_run%(state@ Ptr, argc%, argv@ Ptr) = getprocaddress(handle,"tcc_run")
Local tcc_relocate%(state@ Ptr) = getprocaddress(handle,"tcc_relocate")
Local tcc_get_symbol%(state@ Ptr, value% Var, name$z) = getprocaddress(handle,"tcc_get_symbol")
Local val%
Local func#(a#)
Local s@ Ptr = tcc_new()
tcc_set_output_type( s, TCC_OUTPUT_MEMORY )
Print "CS> " + tcc_compile_string( s, MyProgram )
'// Comment out these next 5 lines and no error occurs//
'// randomly call relocate and the function//
'// everytime relocate is called it accumulates the error //
'// now instead of failing on 509th iteration, it is now roughly 900 to 1100
If Rand(1,2) > 1 Then tcc_relocate( s )
tcc_get_symbol( s, val, "arr" ) '// Val is 0 if relocate was not called //
Print val + " <func"
func = Byte Ptr(val)
If val > 0 Then Print "arr= " + func(32.1)
'//
tcc_delete(s)
s = Null
func = Null
Handle = 0
GCCollect
Print "count= " + count + "~n"
count:+1
End Function