www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - extern(C++) and shared

reply deadalnix <deadalnix gmail.com> writes:
I have this function :
extern(C++) void* __dsfml_start_thread(EntryPoint entryPoint, void* 
userData);

If EntryPoint is defined as follow :
alias extern(C++) void* function(void*) EntryPoint;

The function mangle in _Z20__dsfml_start_threadPFPvS_ES_

if alias extern(C++) void* function(shared void*) EntryPoint;
_Z20__dsfml_start_threadPFPvPvES_

Both demangle using c++filt in __dsfml_start_thread(void* (*)(void*), 
void*), which is what is expected.

But the definition without shared will be the only one to link successfully.

Is the mangling of shared types is consistent in C++ ? shared doesn't 
exists in C++, so I guess we should expect the same mangling in both 
cases. Unless it exists some magic on the C++ side that I'm not aware of ?
Nov 26 2011
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2011-11-27 01:20, deadalnix wrote:
 I have this function :
 extern(C++) void* __dsfml_start_thread(EntryPoint entryPoint, void*
 userData);

 If EntryPoint is defined as follow :
 alias extern(C++) void* function(void*) EntryPoint;

 The function mangle in _Z20__dsfml_start_threadPFPvS_ES_

 if alias extern(C++) void* function(shared void*) EntryPoint;
 _Z20__dsfml_start_threadPFPvPvES_

 Both demangle using c++filt in __dsfml_start_thread(void* (*)(void*),
 void*), which is what is expected.

 But the definition without shared will be the only one to link
 successfully.

 Is the mangling of shared types is consistent in C++ ? shared doesn't
 exists in C++, so I guess we should expect the same mangling in both
 cases. Unless it exists some magic on the C++ side that I'm not aware of ?
Have you tried with __gshared instead? -- /Jacob Carlborg
Nov 27 2011
next sibling parent Jude Young <10equals2 gmail.com> writes:
On Sun 27 Nov 2011 05:02:09 AM CST, Jacob Carlborg wrote:
 On 2011-11-27 01:20, deadalnix wrote:
 I have this function :
 extern(C++) void* __dsfml_start_thread(EntryPoint entryPoint, void*
 userData);

 If EntryPoint is defined as follow :
 alias extern(C++) void* function(void*) EntryPoint;

 The function mangle in _Z20__dsfml_start_threadPFPvS_ES_

 if alias extern(C++) void* function(shared void*) EntryPoint;
 _Z20__dsfml_start_threadPFPvPvES_

 Both demangle using c++filt in __dsfml_start_thread(void* (*)(void*),
 void*), which is what is expected.

 But the definition without shared will be the only one to link
 successfully.

 Is the mangling of shared types is consistent in C++ ? shared doesn't
 exists in C++, so I guess we should expect the same mangling in both
 cases. Unless it exists some magic on the C++ side that I'm not aware
 of ?
Have you tried with __gshared instead?
yeah, I've seen this. __gshared alias extern(C++) void* function(void*) EntryPoint might work. I've had TLS errors when it wasn't __gshared.
Nov 27 2011
prev sibling parent reply deadalnix <deadalnix gmail.com> writes:
Le 27/11/2011 12:02, Jacob Carlborg a écrit :
 On 2011-11-27 01:20, deadalnix wrote:
 I have this function :
 extern(C++) void* __dsfml_start_thread(EntryPoint entryPoint, void*
 userData);

 If EntryPoint is defined as follow :
 alias extern(C++) void* function(void*) EntryPoint;

 The function mangle in _Z20__dsfml_start_threadPFPvS_ES_

 if alias extern(C++) void* function(shared void*) EntryPoint;
 _Z20__dsfml_start_threadPFPvPvES_

 Both demangle using c++filt in __dsfml_start_thread(void* (*)(void*),
 void*), which is what is expected.

 But the definition without shared will be the only one to link
 successfully.

 Is the mangling of shared types is consistent in C++ ? shared doesn't
 exists in C++, so I guess we should expect the same mangling in both
 cases. Unless it exists some magic on the C++ side that I'm not aware
 of ?
Have you tried with __gshared instead?
It doesn't compile at all with __gshared. I have the following error : basic type expected, not __gshared
Nov 27 2011
parent reply Jude Young <10equals2 gmail.com> writes:
On Sun 27 Nov 2011 05:54:27 AM CST, deadalnix wrote:
 Le 27/11/2011 12:02, Jacob Carlborg a écrit :
 On 2011-11-27 01:20, deadalnix wrote:
 I have this function :
 extern(C++) void* __dsfml_start_thread(EntryPoint entryPoint, void*
 userData);

 If EntryPoint is defined as follow :
 alias extern(C++) void* function(void*) EntryPoint;

 The function mangle in _Z20__dsfml_start_threadPFPvS_ES_

 if alias extern(C++) void* function(shared void*) EntryPoint;
 _Z20__dsfml_start_threadPFPvPvES_

 Both demangle using c++filt in __dsfml_start_thread(void* (*)(void*),
 void*), which is what is expected.

 But the definition without shared will be the only one to link
 successfully.

 Is the mangling of shared types is consistent in C++ ? shared doesn't
 exists in C++, so I guess we should expect the same mangling in both
 cases. Unless it exists some magic on the C++ side that I'm not aware
 of ?
Have you tried with __gshared instead?
It doesn't compile at all with __gshared. I have the following error : basic type expected, not __gshared
extern (C++) { __gshared type function(blah) blah; alias foo bar;? } that doesn't work?
Nov 27 2011
parent deadalnix <deadalnix gmail.com> writes:
Le 27/11/2011 13:17, Jude Young a écrit :
 On Sun 27 Nov 2011 05:54:27 AM CST, deadalnix wrote:
 Le 27/11/2011 12:02, Jacob Carlborg a écrit :
 On 2011-11-27 01:20, deadalnix wrote:
 I have this function :
 extern(C++) void* __dsfml_start_thread(EntryPoint entryPoint, void*
 userData);

 If EntryPoint is defined as follow :
 alias extern(C++) void* function(void*) EntryPoint;

 The function mangle in _Z20__dsfml_start_threadPFPvS_ES_

 if alias extern(C++) void* function(shared void*) EntryPoint;
 _Z20__dsfml_start_threadPFPvPvES_

 Both demangle using c++filt in __dsfml_start_thread(void* (*)(void*),
 void*), which is what is expected.

 But the definition without shared will be the only one to link
 successfully.

 Is the mangling of shared types is consistent in C++ ? shared doesn't
 exists in C++, so I guess we should expect the same mangling in both
 cases. Unless it exists some magic on the C++ side that I'm not aware
 of ?
Have you tried with __gshared instead?
It doesn't compile at all with __gshared. I have the following error : basic type expected, not __gshared
extern (C++) { __gshared type function(blah) blah; alias foo bar;? } that doesn't work?
That does work. But isn't what is failing here.
Nov 27 2011
prev sibling next sibling parent reply "Martin Nowak" <dawg dawgfoto.de> writes:
On Sun, 27 Nov 2011 01:20:35 +0100, deadalnix <deadalnix gmail.com> wrote:

 alias extern(C++) void* function(void*) EntryPoint
Can you please file a reduced test case as bug stating exactly what in the mangling went wrong. Not sure about the current policy of passing shared data to C++ functions. It seems to work on a promise base, then stripping the qualifiers. martin
Nov 27 2011
parent deadalnix <deadalnix gmail.com> writes:
Le 27/11/2011 13:16, Martin Nowak a écrit :
 On Sun, 27 Nov 2011 01:20:35 +0100, deadalnix <deadalnix gmail.com> wrote:

 alias extern(C++) void* function(void*) EntryPoint
Can you please file a reduced test case as bug stating exactly what in the mangling went wrong. Not sure about the current policy of passing shared data to C++ functions. It seems to work on a promise base, then stripping the qualifiers. martin
module fail; extern(C++) void foo1(void*); extern(C++) void bar1(shared void*); pragma(msg, foo1.mangleof); pragma(msg, bar1.mangleof); // shared is ignored here, because C++ doesn't have shared, this make sense. extern(C++) void foo2(void function(void*)); extern(C++) void bar2(void function(shared void*)); pragma(msg, foo2.mangleof); pragma(msg, bar2.mangleof); // shared is ignored here, because C++ doesn't have shared, this make sense. extern(C++) void foo3(void function(void*), void*); extern(C++) void bar3(void function(shared void*), void*); pragma(msg, foo3.mangleof); pragma(msg, bar3.mangleof); // shared generate a different mangling here. extern(C++) void foo4(void function(void*), shared void*); extern(C++) void bar4(void function(shared void*), shared void*); pragma(msg, foo4.mangleof); // Same mangling as bar3. pragma(msg, bar4.mangleof); // back to correct mangling (the one expected by g++). extern(C++) void foo5(void* function(void*), void*); extern(C++) void bar5(void* function(shared void*), void*); pragma(msg, foo5.mangleof); pragma(msg, bar5.mangleof); // shared generate a different mangling here. extern(C++) void foo6(void* function(void*), shared void*); extern(C++) void bar6(void* function(shared void*), shared void*); pragma(msg, foo6.mangleof); // shared generate a different mangling here. pragma(msg, bar6.mangleof); // function pointer mangled as in bar5, but second parameter get a "0" in the mangling that none of the mangling above had. Give the following output : _Z4foo1Pv _Z4bar1Pv _Z4foo2PFvPvE _Z4bar2PFvPvE _Z4foo3PFvPvES_ _Z4bar3PFvPvEPv _Z4foo4PFvPvEPv _Z4bar4PFvPvES_ _Z4foo5PFPvS_ES_ _Z4bar5PFPvPvES_ _Z4foo6PFPvS_EPv _Z4bar6PFPvPvES0_ Comment describe what is inconsistent (or what require something on C++ side that I'm not aware of). None is generating any warning. GDC and G++ are used here, both in 4.6.2 version (and frontend v2.055, the last supported by GDC) on linux amd64.
Nov 27 2011
prev sibling parent reply deadalnix <deadalnix gmail.com> writes:
Le 27/11/2011 01:20, deadalnix a écrit :
 I have this function :
 extern(C++) void* __dsfml_start_thread(EntryPoint entryPoint, void*
 userData);

 If EntryPoint is defined as follow :
 alias extern(C++) void* function(void*) EntryPoint;

 The function mangle in _Z20__dsfml_start_threadPFPvS_ES_

 if alias extern(C++) void* function(shared void*) EntryPoint;
 _Z20__dsfml_start_threadPFPvPvES_

 Both demangle using c++filt in __dsfml_start_thread(void* (*)(void*),
 void*), which is what is expected.

 But the definition without shared will be the only one to link
 successfully.

 Is the mangling of shared types is consistent in C++ ? shared doesn't
 exists in C++, so I guess we should expect the same mangling in both
 cases. Unless it exists some magic on the C++ side that I'm not aware of ?
According to this document : http://www.scribd.com/doc/57293807/18/Gnu3-name-mangling S_ is used for template parameters, which is not correct here.
Nov 27 2011
parent "Martin Nowak" <dawg dawgfoto.de> writes:
On Sun, 27 Nov 2011 16:03:55 +0100, deadalnix <deadalnix gmail.com> wrot=
e:

 Le 27/11/2011 01:20, deadalnix a =C3=A9crit :
 I have this function :
 extern(C++) void* __dsfml_start_thread(EntryPoint entryPoint, void*
 userData);

 If EntryPoint is defined as follow :
 alias extern(C++) void* function(void*) EntryPoint;

 The function mangle in _Z20__dsfml_start_threadPFPvS_ES_

 if alias extern(C++) void* function(shared void*) EntryPoint;
 _Z20__dsfml_start_threadPFPvPvES_

 Both demangle using c++filt in __dsfml_start_thread(void* (*)(void*),=
 void*), which is what is expected.

 But the definition without shared will be the only one to link
 successfully.

 Is the mangling of shared types is consistent in C++ ? shared doesn't=
 exists in C++, so I guess we should expect the same mangling in both
 cases. Unless it exists some magic on the C++ side that I'm not aware=
=
 of ?
According to this document : =
 http://www.scribd.com/doc/57293807/18/Gnu3-name-mangling S_ is used fo=
r =
 template parameters, which is not correct here.
Thanks. http://d.puremagic.com/issues/show_bug.cgi?id=3D7024
Nov 28 2011