News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

[10.28] - Alloca compile error

Started by Milko, February 28, 2013, 04:36:37 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Milko

Hello James

Also in branch Jamespetts/Master I have the "alloca" error.

Giuseppe

jamespetts

Hmm - that's very odd, since I am able to compile the master branch on a Linux machine, being my server, and the automatic compile for Linux works. May I ask - what version of GCC do you use?

Milko

#2
Hello James

I'm using GCC 4.5.0. What's your version?

EDIT: also using 4.6.2 I obtain the alloca error. Trying to apply Bernd's alloca solution?

Giuseppe

jamespetts

Hmm - the version of GCC that I use on the Bridgewater-Brunel server, on which I compile the Linux binaries that I use there, is 4.6.3. However, that is the non-GUI version, so it is possible that that does not deal with the method in question. I do not know what version of GCC is used by the automatic compile servers; I am not sure why different results are given.

Bernd's fix should solve this, however, by using malloc() instead. You could try compiling the 112.x-merge branch and seeing whether that helps?

Milko

Hello James

Quote from: jamespetts on March 04, 2013, 09:48:57 PM
Bernd's fix should solve this, however, by using malloc() instead. You could try compiling the 112.x-merge branch and seeing whether that helps?

I'm able to compile 112.x-merge also using gcc 4.5.0, no alloca error.

Bernd fixed the alloca problem in this commit https://github.com/jamespetts/simutrans-experimental/commit/2eafa0cea341868ba67ee5207a1c04e3ff4d0ac7

Giuseppe

Milko

Hello

I have the "alloca" problem compiling 11.x branch in freight_list_sorter.cc

Giuseppe

jamespetts

Can you post the exact error message that you get?

Milko

Hello James

In attach.

Giuseppe

jamespetts

That error is very odd, since "alloca" is found only in code surrounded by "#ifdef _MSC_VER", which means that that code should only be compiled if you are running MS Visual Studio, not if you are running GCC. What are your compile options? Are you doing this in MinGW?

Milko

Hello James

I'm using MinGW and branch 11.x (not 112.x-merge).

Giuseppe

jamespetts

Yes, that code is there on the 11.x branch, as that is what I compiled the latest RC from. You might need to look up how to disable _MSC_VER code from being compiled when using MinGW, as I don't think that I know how to do that. If you can do that, you should be able to compile it.

Alternatively, you could just download and install MSVC Express for free, which is what I use.

Milko

Hello James

Looking the code:

branch in freight_list_sorter.cc use alloca (the MSVC command) and not ALLOCA (the macro), we need to use the ALLOCA macro for compatibility with MIngW.

Giuseppe

jamespetts

If I recall correctly, there was a problem with the ALLOCA macro in this setting, which is why it was not used here. Is it not sufficient to find a way of distinguishing between MSVC++ and MinGW when compiling for the purposes of the relevant preprocessor directives?

Milko

Hello James

Quote from: jamespetts on July 04, 2013, 10:09:30 AM
If I recall correctly, there was a problem with the ALLOCA macro in this setting, which is why it was not used here. Is it not sufficient to find a way of distinguishing between MSVC++ and MinGW when compiling for the purposes of the relevant preprocessor directives?

Yes .... but I'm not able to do ...

Is possible to use the preprocessor in this way?

# if compiler = mingw (the new code)

wlist = (ware_t*) malloc(warray_size);

# else (the actual code)

if(warray_size >= max_stack_size)
{
    // Too large for the stack - use the heap (much slower)
    wlist = (ware_t*) malloc(warray_size);
}
else
{
    // Old method - use the stack, but will cause stack overflows if
    // warray_size is too large
    wlist = (ware_t*) alloca(warray_size);
}

Giuseppe

jamespetts

Hmm - is "# if compiler = mingw" the right syntax here? Google doesn't produce any results for that. We also need to make sure that what is inside the "# if compiler = mingw" (or however it is expressed) also compiles with GCC, but not with MSVC++.

Milko

Hello

Quote from: jamespetts on July 08, 2013, 08:29:11 PM
Hmm - is "# if compiler = mingw" the right syntax here? Google doesn't produce any results for that. We also need to make sure that what is inside the "# if compiler = mingw" (or however it is expressed) also compiles with GCC, but not with MSVC++.

No, it's not the correct sintax, it was only a way that I used to express what you could do, but the way to tell the preprocessor to separate the code depending on the compiler I do not know ....

Giuseppe

jamespetts

Hmm - I'm not sure how to do that either here. Can anyone else assist with this one...?

TurfIt

alloca can used with MinGW by "#include <malloc.h>"

I attempted to compile the 11.x branch obtained from github, but it seems github has broken the ability to download anything but the master branch. Compiling the master branch of course gives the alloca error since the ifdef _MSC_VER code is not there. Perhaps Milko doesn't actually have the current 11.x?  (The _MSC_VER check if the correct way to do this - well besides enabling alloca in MinGW)

jamespetts

Turfit - how did you try to download it? Can't you just checkout the repository into a local working directory?

TurfIt

github website - click 'download zip'. Used to provide the current code for the selected branch. Since they've murdered the UI of the site, it only gives the master branch now. (no I don't have a working git client)

Junna

Quote from: TurfIt on July 08, 2013, 10:53:38 PM
github website - click 'download zip'. Used to provide the current code for the selected branch. Since they've murdered the UI of the site, it only gives the master branch now. (no I don't have a working git client)

Try pasting the link to the desired location in another browser (to the branch). This was what I had to do.

Milko

Hello Turtif and James

Quote from: TurfIt on July 08, 2013, 09:51:00 PMalloca can used with MinGW by "#include <malloc.h>" I attempted to compile the 11.x branch obtained from github, but it seems github has broken the ability to download anything but the master branch. Compiling the master branch of course gives the alloca error since the ifdef _MSC_VER code is not there. Perhaps Milko doesn't actually have the current 11.x? (The _MSC_VER check if the correct way to do this - well besides enabling alloca in MinGW)

WOW adding - #include "malloc.h" - to freight_list_sorter.cc solve the alloca problem and I am able to build the project. James may you add the malloc.h in the project?

I have last 11.x branch, I have no problem to download from github.

Giuseppe

TurfIt

Quote from: Milko on July 09, 2013, 06:57:13 PM
I have last 11.x branch, I have no problem to download from github.
Given that the error you attached shows alloca on line 145, and the latest 11.x has alloca on 152, you cannot be compiling the latest 11.x.

jamespetts

I have now added the suggested line to freight_list_sorter.cc. Thank you for investigating that!

Milko

Sorry James

But now there is another problem, see the attach (i'm using 11.x last commit - 8c6737a7fa)

Giuseppe

jamespetts

Hmm - this appears to be an issue with sprintf_s and MinGW. I don't know a great deal about the interaction between the two; does anybody know much about sprintf_s? Do you have the latest version of MinGW?

Milko

Hello

Looking in internet:

snprintf_s is not a standard C++ command, sprintf_s has a standard equivalent: snprintf. Many people say that snprintf is not safe on MSVC so MSVC usually use snprintf_s.

in this article http://www.mail-archive.com/pd-dev@iem.at/msg03426.html people suggest to use sprintf and to force tell MSVC to use snprintf_s using the command:

#ifdef MSW #define snprinf sprintf_s #endif
Giuseppe

jamespetts

Hmm - but we want GCC based compilers to use snprintf and MSVC++ to use sprintf_s, rather than having GCC based compilers using sprintf and MSVC++ using sprintf_s.

Milko

Hello James

Quote from: jamespetts on July 10, 2013, 09:28:45 PM
Hmm - but we want GCC based compilers to use snprintf and MSVC++ to use sprintf_s, rather than having GCC based compilers using sprintf and MSVC++ using sprintf_s.

We want GCC based compilers to use snprintf and MSVC++ to use sprintf_s  :) , GCC sprintf is similar to snprintf but is not the same.

James, I add to simworld.h these lines (these lines swap the two functions depending on the MSVC compiler or another compiler):
#ifdef _MSC_VER
#define snprintf sprintf_s
#else
#define sprintf_s snprintf
#endif
MingW (and I also believe other compilers compatible with standard C) is able to compile and I obtain a working build. May you test in MSVC?

If it works in MSVC and if you think (they also accept other opinions) there are no other impacts on other compilers may become the solution to the problem?

Giuseppe

jamespetts

Ahh, thank you for that - that does work. I have pushed this to my 11.x branch.

Milko

Hello

Quote from: jamespetts on July 11, 2013, 10:11:37 PM
Ahh, thank you for that - that does work. I have pushed this to my 11.x branch.

Splendid!
Giuseppe