How can I access the root namespace by name - instead of simply `::`? - c++

I am working on a c++ project (and I'm a complete c++ n00b) that uses the root namespace to access the ::tolower method in the following lines of code, but I have changed some build settings and am getting an error.
CCString * CCBReader::toLowerCase(CCString * pString) {
std::string copy(pString->getCString());
std::transform(copy.begin(), copy.end(), copy.begin(), ::tolower);
return CCString::create(copy.c_str());
}
The build changes are essential for most of the project, and changing these is not an option. So as a workaround, I would like to try prefixing this with the root namespace. For example:
std::transform(copy.begin(), copy.end(), copy.begin(), rootns::tolower);
Is this possible? If so, how?
Since many of you have already disregarded my ideal solution as impossible, and have asked what the error is to see if you can solve it your own way, here is the relevant portion of the error:
error: '::tolower' has not been declared

The root namespace does not have a name, so there is no other way to address it.
Instead, you're going to have to re-examine your build changes, and maybe consider what exactly the error you get says. The error might not really be about namespaces. It could have been triggered by some other problem earlier in your code.

Related

Why I am getting errors from TableGen-generated *.inc files (LLVM)?

I am trying to write an LLVM backend, when I am trying to build it, I get the following error message:
AbcGenRegisterInfo.inc: In static member function 'static const llvm::AbcFrameLowering* llvm::AbcGenRegisterInfo::getFrameLowering(const llvm::MachineFunction&)':
AbcGenRegisterInfo.inc:322:43: error: invalid static_cast from type 'const llvm::TargetFrameLowering*' to type 'const llvm::AbcFrameLowering*'
MF.getSubtarget().getFrameLowering());
^
Here is my AbcRegisterInfo.td (I copied it from here):
class AbcReg<string n> : Register<n> {
let namespace = "Abc";
}
def DUMMY_REG : AbcReg<"R0">;
def RegI64 : RegisterClass<"Abc", [i64], 64, (add DUMMY_REG)>;
I also overrided AbcSubtarget::getFrameLowering() method:
class AbcSubTarget : public AbcGenSubtargetInfo {
AbcFrameLowering *frameLowering;
// more fields and methods
const AbcFrameLowering *getFrameLowering() const override {
return frameLowering;
}
};
but the error message did not change.
I don't understand what to do - I can't just edit AbcGenRegisterInfo.inc, because it will be re-generated every time I will build LLVM, and I don't understand what's wrong in my TableGen files.
I also tried to remove AbcGenRegisterInfo.inc file from my build directory before compiling, but it had no effect.
Does AbcFrameLowering inherit from TargetFrameLowering? It looks like the static cast is complaining because the types are unrelated.
Also make sure the header with the definition of AbcFrameLowering is included before the .inc file is included otherwise the static cast will fail as well.
I have the same exact error, and while I cannot answer your question in full, I believe I can address one part of the issue. You said
I also tried to remove AbcGenRegisterInfo.inc file from my build directory before compiling, but it had no effect.
Unless you mean that AbcGenRegisterInfo.inc was regenerated (and therefore deleting it had no effect), the fact that its absence has no effect should be due to the fact that TableGen has the .inc.tmp file to rely on as a backup. I noticed that when I make with VERBOSE=1, there is a statement that suggests tablegen uses the .tmp files in this way.
Again, not a specific answer to your main question, but just to hopefully help address that issue when trying to debug.

Class redeclaration error on targetEntity="Y" within ZF2

I am facing a weird error within my codebase currently. You can see the full ZF2s project code on my github right here. <- there's a link
I'm having a Module set up with two Entities (X and Y). Entity_X contains a reference to Entity_Y via (targetEntity="Entity_Y"). The Error persist with the FQCN or just the CN itself.
Entity_X:
id int PK,
id_Y int FK,
text varchar
Entity_Y:
id int PK,
text varchar
When loading Entity_Y first and then Entity_X everything is working fine. This remains true for both StandardAutoloader and ClassMapAutoloader. However: when loading Entity_X first with ClassMapAutoloader present, i will be seeing the following error:
Fatal error: Cannot redeclare class Kennzahlen\Entity\Referenzwert (Entity_Y)
in \module\Kennzahlen\src\Kennzahlen\Entity\Referenzwert.php
on line 13
Loading Entity_X first with StandardAutoloader works without any problems, too.
Update
The Problem appears to be within ZF2s ClassMapAutoloader (or Autoloading-Mechanism in General). My Module used the ClassMapAutoloader and using this i've gotten the above mentioned error. When removing the ClassMapAutoloader and simply using the StandardAutoloader, the error vanished into thin air. Thanks to #ocramius and all others i've botheres with this :)
I'm writing a failing test case to try and solve this in doctrine/common. The problem seems to be that silent autoloaders (as explained by #Xerkus) are not compatible with doctrine/common itself. To solve that, use a StandardAutoloader from ZF2 (or from composer) instead of using the ClassMapAutoloader. This will solve the issue until a patch is ready.
Update: patch is being suggested at doctrine/common#216
i have no knowledge of doctrine, but i browsed through source and i think i found issue:
https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/ClassLoader.php#L224
here, this code expects that autoloader will return value evaluated to true, but that is not requirement of spl autoload mechanism, therefore autoloader can return NULL,
To check if i am correct, in in your project in doctrine replace line 224 in Doctrine/Common/ClassLoader.php
} else if ($loader[0]->{$loader[1]}($className)) {
with
} else if ($loader[0]->{$loader[1]}($className) && class_exists($className, false)) {
Ans see if issue is fixed, if i am correct - then report bug to doctrine project

Include Alien in portable app, C++

Ok, I've searched quite a bit, but seem unable to find an answer or example for how to achieve this.
Basically, I have an app that is designed to be portable (built using VC++ in VS2010, but no MFC or managed components, raw WinAPI). I have Lua 5.2 built into it and allow the user to write scripts inside the application. I have multiple glued functions which are exposed to the Lua scripts which handle various WinAPI calls.
However, what I'd like to be able to do is allow the user to write a script in which looks something like this:
require[[Alien/alien]]
local mb = alien.User32.MessageBoxA
mb:types{ 'long', 'long', 'string', 'string', 'long' }
print(mb(0, "Hello World!", "Test", 64))
I simply cannot seem to find a way to do this. I do not want to require the user to install Lua for Windows and, ideally, there be no core.dll and struct.dll from alien; when I tried to do something with those DLLs in ./alien/, it was crashing in Lua5.1.dll because I had LuaForWindows installed, I uninstalled LFW, and then it just states that Lua5.1.dll is missing. I have Lua 5.2 built into my app, so obviously the core/struct DLLs from the Alien rock are expecting Lua5.1.dll to be in the path.
I made a worthless attempt to try to including the Alien src into the project, but doesn't seem to work that way either.
Any ideas would be greatly appreciated. I'd prefer it all be contained in my app, but I'll settle for a solution which involves including the libraries in my project to build and bundle in the distribution if that's the only alternative.
Thanks!
UPDATE:
Ok, thank you Ben Voigt! I think I'm almost there. I've pulled in core.c and struct.c and made sure all the paths are there for libffi. Everything compiles without issue, until I try to call luaopen_alien_core in core.c (the alien.core src file), claiming the identifier is undeclared. I've tried to declare the function signature in my separate source file that's trying to make the call, the compile gets further, but fails complaining of an unresolved external.
Clearly this is likely now a general C++ issue (as I'm only a novice in this area). Here's the general idea of what I have:
//core.c (from Alien project)
(...)
int luaopen_alien_core(lua_State *L) {
alien_register_library_meta(L);
alien_register_callback_meta(L);
alien_register_function_meta(L);
alien_register_buffer_meta(L);
lua_getglobal(L, "alien");
if(lua_isnil(L, -1)) {
lua_newtable(L);
lua_pushvalue(L, -1);
lua_setglobal(L, "alien");
}
lua_newtable(L);
lua_pushvalue(L, -1);
lua_setfield(L, -3, "core");
alien_register_main(L);
return 1;
}
//mysource.c (the file attempting to call luaopen_alien_core(L))
void initLua()
{
L = luaL_newstate();
luaL_openlibs(L);
luaopen_alien_core(L);
(...)
}
This fails to start compiling, issuing the error:
error C3861: 'luaopen_alien_core': identifier not found
Which makes sense, so I add the following line to myheader.h:
int luaopen_alien_core(lua_State *L);
This compiles, but fails to link with:
error LNK2001: unresolved external symbol "int __cdecl luaopen_alien_core(struct lua_State *)" (?luaopen_alien_core##YAHPEAUlua_State###Z)
I've tried several things I can think of, with my limited experience, but nothing will satisfy this error. I even tried to move the contents of core.c into mysource.c, but that creates a whole different mess and seemed to be the wrong way to go as it is.
I'm hoping, and imagining, this is something really stupid, but I'm just not sure how to get it to call luaopen_alien_core, which seems to be the final piece I need.
Thanks again!
}
I imagine that the require directive both loads a dynamic library and adds its contents to the active Lua engine.
By linking alien directly into your code, you obviate the need for the dynamic library. But the content enumeration code won't have run, and you can't use require to run it, or else it'll go looking for a DLL file (along with all the DLL dependencies).
So, you should find out what functions that require directive calls after loading the DLL, and call those when creating a Lua engine. Then it will neither be necessary nor allowed for the script to start with require [[Alien/alien]], but Alien objects will be available.

Visual C++ - Throwing unhandled exception from setting forms icon?

I can compile the solution with no errors, but when I'll try to run it, I get a crash window:
An unhandled exception of type
'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "<myformname>.resources" was corerctly embedded or linked into assembly "<myprojectname>" at compile time, or that all the satellite assemblies required are loaded and fully signed.
And after I press Break it throws me to the line:
this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
If I comment this line out, everything works just fine, but my program doesn't have icon.
Anyone else had this problem? Found a solution? I couldn't find anything clear enough for me to understand, problem is really annoying me, only solution I found was to declare my form class before any other classes, but I don't even have any other classes in my solution?
I also have only one project in this solution, ms support said something about having multiple projects, which I don't have, so it was no use either.
Take a look here :
http://www.mztools.com/articles/2005/MZ2005007.aspx
The exception is thrown because your icon cannot be located. You will probably need to compiles your resources under one .dll and put this under en-US subfolder on your project output. It did the trick for me at least. There are probably other solutions to your problem too.
Do not panic like I did. The root cause of the problem is that the compiled resource file is different from the one that is asked to load at runtime. This happens because the underlying build-script cannot detect the filename or namespace changes made after the form is created.
For example, At first we started a project named x . And our $(RootNamespace) becomes x. And we created a form named y. So our XML resource file y.resx gets compiled into x.y.resource . At this point the icon change works.
Now somehow we changed the project name or the namespace to z. But our $(RootNamespace) remains the x. While at compile-time it wrongly generates old x.y.resource, but at links-time it links z.y.resource. And at this point the icon change does not work.
It can also happen if the form is under some nested namespace which is not known in the project file.
It can be fixed by changing the compilation output of the y.resx file . It can be done by right-clicking the resource and changing the Resource Logical Name to $(RootNamespace).%(Filename).resources .
I will also make sure that ProjectName,AssemblyName and RootNamespace are the same in the .vcxproj file. Somehow if the form is declared under a nested namespace like RootNamespace.gui , then the output file of the resource should be $(RootNamespace).gui.%(Filename).resources .

What has to be Glib::init()'ed in order to use Glib::wrap?

So I'm trying to make use of a GtkSourceView in C++ using GtkSourceViewmm, whose documentation and level of support give me the impression that it hasn't been very carefully looked at in a long time. But I'm always an optimist :)
I'm trying to add a SourceView using some code similar to the following:
Glib::RefPtr<gtksourceview::SourceLanguageManager> source_language_manager = gtksourceview::SourceLanguageManager::create();
Glib::RefPtr<gtksourceview::SourceLanguage> source_language = Glib::wrap(gtk_source_language_manager_guess_language(source_language_manager->gobj(), file, NULL));
Glib::RefPtr<gtksourceview::SourceBuffer> source_buffer = gtksourceview::SourceBuffer::create(source_language);
gtksourceview::SourceView* = m_source_view = new gtksourceview::SourceView(source_buffer);
m_vbox.pack_start(*m_source_view);
Unfortunately, it spits out the warning
(algoviz:4992): glibmm-WARNING **:
Failed to wrap object of type
'GtkSourceLanguage'. Hint: this error
is commonly caused by failing to call
a library init() function.
and when I look at it in a debugger, indeed the second line above (the one with the Glib::wrap()) is returning NULL. I have no idea why this is, but I tried to heed the warning by adding Glib::init() to the begining of the program, but that didn't seem to help at all either.
I've tried Google'ing around, but have been unsuccessful. Does anyone know what Glib wants me to init in order to be able to make that wrap call? Or, even better, does anyone know of any working sample code that uses GtkSourceViewmm (not just regular GtkSourceView)? I haven't been able to find any actual sample code, not even on Google Code Search.
Thanks!
It turns out, perhaps not surprisingly, that what I needed to init was:
gtksourceview::init();
After this, I ran into another problem with one of the parameter to gtksourceview::SourceLanguageManager, but this was caused by a genuine bug which I subsequently reported and was promptly fixed. So everything's working great now!
I use gtkmm. Typically you have to initialize things with something like :
_GTKMain = new Gtk::Main(0, 0, false);
Of course do not forget :
delete _GTKMain;
Check here for details :
http://library.gnome.org/devel/gtkmm/2.19/classGtk_1_1Main.html
(Sorry but the link option does not work ...)