Reference Issue

Hello :slight_smile:

currently, I got it working to reference the c_rtl.fx, but unfortunately, I get this error when compiling with the “C_rtl.fx”:

Unknown namespace c_rtl

I put the c_rtl.fx into the folder where all referenced .fx are, like gc.fx, RTL.fx and so on, he compiles without any lib error, except this line, it gives me just unknown namespace :open_mouth: :open_mouth:

bit strange to me:

Best regard

Shpend

Just putting it there doesn’t do anything. You have to add it to the references list in the project. Also the things inside it need to have a namespace, for example by importing with --forcenamespace.

1 Like

THANX, I also had referenced it, but the “–forcenamespace c_rtl” was missing and it works!!! Thanx!

But, I get, when I compile,: E:0 Severity Code Description Project File Line Suppression State
Error (E0) Internal error: System.InvalidCastException: Unable to cast object of type ‘RemObjects.Oxygene.Code.ParsedGenericParameter’ to type ‘RemObjects.Oxygene.Code.IMutableParsedType’.
at RemObjects.Oxygene.Code.ExplodingGenericsPass.Process()
at RemObjects.Oxygene.Code.IslandTarget.ExplodeGenerics(Compiler acompiler)
at RemObjects.Oxygene.Code.Compiler.Compiler.Compile() ElementsStuff 0
at this codeline:

var ptr:^Byte := ^Byte(c_rtl.malloc(sizeOf(byte) * 10));

But this seems, that it has nothing to do with the c-call, doesnt it?

indeed not. Can you send us a project that shows this?

hmm, interessting, it wasnt that line, sry… because I had 4 older classes which I was working on, and I need to find out where it is, I will send it immediately, to avoid the investigation by yourself not too loose time because its a bit much

When I declare my own used TArray = record, it compiles fine but gives some allocation problems, but when I change it to TArray = class, then it gives:

Severity Code Description Project File Line Suppression State
Error (E0) Internal error: System.InvalidCastException: Unable to cast object of type ‘RemObjects.Oxygene.Code.ParsedGenericParameter’ to type ‘RemObjects.Oxygene.Code.IMutableParsedType’.
at RemObjects.Oxygene.Code.ExplodingGenericsPass.Process()
at RemObjects.Oxygene.Code.IslandTarget.ExplodeGenerics(Compiler acompiler)
at RemObjects.Oxygene.Code.Compiler.Compiler.Compile() ElementsStuff0

Ok the error was, because I since never changed it, “pointer = dynamic.-array” pseudo-code and that is bad obviously because of GC issues, as you told me back then, so I changed it internally to:

f_first := ^TBlock<T>(c_rtl._alloca(sizeOf(T) * cnt));   //allocate on the stack, but raises: 

Severity Code Description Project File Line Suppression State
Error () C:\Program Files (x86)\RemObjects Software\Elements\Bin\lld.exe: error: (import): undefined symbol: __alloca ElementsStuff C:\Program Files (x86)\MSBuild\RemObjects Software\Elements\RemObjects.Elements.Island.Windows.targets

that means you’re not actually linking in the .o/obj/a/lib that contains alloca. What are you doing exactly?

I am currently just “playing” with totall stack-allocation for implementing a short-time-pixel-buffer, that doesnt need any heap-alloc because he just shall be used as a tmp backbuffer :slight_smile:

The point is, c_rtl.Malloc(bla) gets called :confused:

You want (stack) alloca? That’s not an actual api… it’s a compiler intrinsic (since the compiler has to do that).

hmm, but MSDN says, it is in the malloc.h :open_mouth: :open_mouth: and even some guys on stackoverflow said that you can use it and they even made use of it :open_mouth:

https://msdn.microsoft.com/en-us/library/5471dc8s.aspx

Right; but alloca itself is a compiler intrinsic. malloca probably calls that.

hmm, ok, but then they shouldnt have make it a public function then, ok nevermind^^ thx, but I want to ask you, even when I do the same line, just with malloc, I always get 0ptr back?
What I did then is this:

var size := sizeOf(TBlock<T>);
f_first := ^TBlock<T>(c_rtl.malloc(size * 3)); //allocate on heap

and the first line, the debugger isnt able to tell me the size :open_mouth:

Hmm, I see in the malloc.h that malloca is a #define, can I make use of that?

 #ifndef _CRTDBG_MAP_ALLOC
    #undef _malloca
    #define _malloca(size)                                                           \
        __pragma(warning(suppress: 6255 6386))                                       \
        (_MallocaComputeSize(size) != 0                                              \
            ? _MarkAllocaS(malloc(_MallocaComputeSize(size)), _ALLOCA_S_HEAP_MARKER) \
            : NULL)
#endif

You can’t alloca in Elements currently.

what type is TBlock ? record or class?

a sizeof on a class always returns 4 or 8.

TBlock is a record, and I think, except the #define the rest I can implement on my own actually?

Possibly, but you can’t implement alloca.

and now I get: System.NullReferenceException; object-reference is not set to an istance of an object

I don’t. The testcase you sent me is incomplete.

Ok , w8 a min pls, I am now a little bit confused by this, I investigate and summarize all I said before together, that I can see: “do I get internal error and linker error” or not!

I don’t get an internal error; but that might be explained because I dont’ have the fx file you reference from the project. If you can send it I can try it again.