Firebreath MethodConverter.h invalid initialization - objective-c

Hi I created a firebreath project. I added this methods to the default generated code:
In the application API header file (MYAppAPI.h):
FB_JSAPI_EVENT(bgp, 3, (const FB::variant&, bool, int));
std::string bgp(std::string& val);
In the application API source file (MAppAPI.mm I am using objective-c):
registerMethod("bgp", make_method(this, &MyAppAPI::bgp));
std::string MyAppAPI::bgp(std::string& val){...}
But when I build the code, I am getting this error:
...firebreath/src/ScriptingCore/MethodConverter.h:115: error: invalid initialization of non-const reference of type 'std::string&' from a temporary of type 'std::basic_string, std::allocator >'
Any ideas?

that should read:
std::string MyAppAPI::bgp(const std::string& val){...}
note the const. You can't pass things by reference into a JS function, so it won't let you pass a non-const reference.

Related

SystemC ERROR: type name requires a specifier or qualifier

I am trying to write synthesizable SystemC code.
My code:
struct test:sc_module{
sc_in<sc_lv<4>> inp;
sc_out<sc_lv<4>> outp;
void run(){
sc_lv<4> temp = inp.read();
outp.write(temp);
}
SC_CTOR(test){
SC_METHOD(run);
sensitive << inp;
}
};
I am able to simulate the code, but when I run synthesis, Vivado HLS v.2019 throws the following errors. Can someone please help me understand how to fix this error?
ERROR: [HLS 200-70] Compilation errors found: In file included from test2/test.cpp:1:
test2/test.cpp:4:18: error: use of undeclared identifier 'inp'
sc_in<sc_lv<4>> inp;
^
test2/test.cpp:4:21: error: type name requires a specifier or qualifier
sc_in<sc_lv<4>> inp;
^
test2/test.cpp:4:21: warning: declaration does not declare anything [-Wmissing-declarations]
sc_in<sc_lv<4>> inp;
When I add spaces between the angular brackets (as below), it does not throw an error, and synthesis runs successfully.
sc_in< sc_lv<4> > inp;
sc_out< sc_lv<4> > outp;

How can Poplar codelets include code from other header files?

Is it possible for codelets to reference code in other files, like header files?
If I have a codelet file
//FileA.cpp
#include "FileB.h"
class SomeCustomVertex : public Vertex {
public:
bool compute() {
int a = SomeConstantDefinedInFileB;
}
...
}
and some other "codelet" file
//FileB.h
const int SomeConstantDefineInFileB = 42;
and in the host graph program:
graph.addCodelets({"codelets/FileA.cpp", "codelets/FileB.h"});
I get a compile error from popc:
fatal error: 'FileB.h' file not found
#include "FileB.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
terminate called after throwing an instance of 'poplar::graph_program_compilation_error'
what(): Codelet compilation failed (see compiler output for details)
I figured this out.
Graph::addCodelets has a parameter StringRef compileFlags = "", which you can use to inject compiler options.
popc --help shows an option
-I arg Add directory to include search path
So when I use graph.addCodelets({"codelets/FileA.cpp"}, "-I codelets"); in the host program, and have my codelets in 'codelets' subdirectory, this works. No need to explicitly list the ".h" files in the arguments.
Incidentally, also a good way to ensure compiler optimisation (-O3) for the custom codelets.

How to use `git_note` from libgit2?

I've got code (where commit_id is already set) like:
git_note* note;
git_note_read(&note, repo, "refs/notes/label", &commit_oid);
printf("%s\n", note->message);
git_note_free(note);
It doesn't compile, complaining:
.../importer_test.cc:103:22: error: member access into incomplete type 'git_note'
printf("%s\n", note->message);
^
.../include/git2/types.h:160:16: note: forward declaration of 'git_note'
typedef struct git_note git_note;
If I just copy/paste from src/notes.h into this file:
struct git_note {
git_oid id;
git_signature *author;
git_signature *committer;
char *message;
};
It compiles and runs correctly. But surely that's not the right solution?
git_note is an opaque type. You're not meant to access members of the data directly. You should be using the accessor functions to read from it. In your case, you would want to use git_note_message() to get the message.

Error and warnings in Xcode when declaring Array of NSString* as a global extern

I am declaring an array of NSString* in a header file of a class.
PolygonShape.h
NSString* POLYGON_NAMES[] = {#"Invalid Polygon", #"Monogon", ...};
Now I am using this in PolyginShape.m as follows:
- (NSString*) name {
return (POLYGON_NAMES [self.numberOfSides]);
}
numberOfSides is an iVar which will indicate the index at which the polygon name is stored
So far so good ... it was compiling without any errors
Then I added PolygonShape.h in my file that implements main method (note: these does not have any class definition and call functions C-Style rather than obj-c Style)
#import "PolygonShape.h"
Now when I compile, I am getting a build (linking) error
ld: duplicate symbol _POLYGON_NAMES in /Users/../Projects/CS193P/1B/What_A_Tool/build/What_A_Tool.build/Debug/What_A_Tool.build/Objects-normal/i386/PolygonShape.o and /Users/../Projects/CS193P/1B/What_A_Tool/build/What_A_Tool.build/Debug/What_A_Tool.build/Objects-normal/i386/What_A_Tool.o
collect2: ld returned 1 exit status
So I went thru stack overflow and other forums and mostly the advice was to make the global variable extern and so I did ...
extern NSString* POLYGON_NAMES[] = {#"Invalid Polygon", #"Monogon" .. };
However I am still getting the linking error and also getting 2 warnings now that says
warning: 'POLYGON_NAMES' initialized and declared 'extern'
at both the places where i am importing PolygonShape.h
What am I missing here?
Thanks.
In your header file declare the array as:
extern const NSString* POLYGON_NAMES[];
In your source file, define the array and initialize the contents:
const NSString* POLYGON_NAMES[] = {#"Invalid Polygon", #"Monogon" };

How do I convert a System::String^ to const char*?

I'm developing an app in C++/CLI and have a csv file writing library in unmanaged code that I want to use from the managed portion. So my function looks something like this:
bool CSVWriter::Write(const char* stringToWrite);
...but I'm really struggling to convert my shiny System::String^ into something compatible. Basically I was hoping to call by doing something like:
if( m_myWriter->Write(String::Format("{0}",someValueIWantToSave)) )
{
// report success
}
using namespace System::Runtime::InteropServices;
const char* str = (const char*) (Marshal::StringToHGlobalAnsi(managedString)).ToPointer();
From Dev Shed.
As mcandre mentions, Marshal::StringToHGlobalAnsi() is correct. But don't forget to free the newly allocated resource with Marshal::FreeHGlobal(), when the string is no longer in use.
Alternatively, you can use the msclr::interop::marshal_as template to create the string resource and automatically release it when the call exits the resource's scope.
There's a list of what types need which conversion in the overview of marshalling in C++.