Where to find Glib object in vala? - glib

I just started with learning vala. I tried the following program from the vala tutorial.
class Demo.Hello : Glib.Object
{
public static int main( string[] args )
{
stdout.printf("Hello, Vala!\n");
return 0;
}
}
and got this when I compiled.
$ valac hello.vala
hello.vala:1.20-1.23: error: The symbol `Glib' could not be found
class Demo.Hello : Glib.Object
^^^^
Compilation failed: 1 error(s), 0 warning(s)
[1]+ Done gvim hello.vala
If I remove Glib. from Glib.Object i.e leave it with just class Demo.Hello : Object, then everything works fine. But all the programs in the tutorial use Glib.Object. What's wrong here? I searched for answers but could not find it. Here is the vala version info:
$ valac --version
Vala 0.5.2
And I am running the latest version of CentOS.

The namespace is called GLib (with big L) not Glib..

The correct name is GLib. But you can just as well leave the "GLib." out and just write "Object", the GLib namespace is implicitely used in all vala apps.
For other namespaces you can use "using", for example using Gtk;.

Related

CYTHON : Generating coverage for pyx file

I am trying to generate code coverage report for a cython module, an d facing issues.
I have a simple c++ code : apple.h and apple.cpp files.
The cpp file is simple as :
using namespace std;
namespace mango {
apple::apple(int key) {
_key = key;
};
int apple::execute()
{
return _key*_key;
};
}
I have written a basic cython code over this in "cyApple.pyx" :
# cython: linetrace=True
from libcpp.list cimport list as clist
from libcpp.string cimport string
from libc.stdlib cimport malloc
cdef extern from "apple.h" namespace "mango" :
cdef cppclass apple:
apple(int)
int execute()
cdef class pyApple:
cdef apple* aa
def __init__(self, number):
self.aa = new apple(number)
def getSquare(self):
return self.aa.execute()
My setup.py file :
from distutils.core import setup, Extension
from Cython.Build import cythonize
compiler_directives = {}
define_macros = []
compiler_directives['profile'] = True
compiler_directives['linetrace'] = True
define_macros.append(('CYTHON_TRACE', '1'))
setup(ext_modules = cythonize(Extension(
"cyApple",
sources=["cyApple.pyx", "apple.cpp"],
define_macros=define_macros,
language="c++",
), compiler_directives=compiler_directives))
This generates a proper library cyApple.so.
I have also written a simple appletest.py file to run test cases :
import cyApple, unittest
class APPLETests(unittest.TestCase):
def test1(self):
temp = 5
apple1 = cyApple.pyApple(temp)
self.assertEqual(25, apple1.getSquare())
suite = unittest.TestLoader().loadTestsFromTestCase(APPLETests)
unittest.TextTestRunner(verbosity=3).run(suite)
The test works fine.
The problem is I need to get code coverage for my cyApple.pyx file
When i run "coverage report -m"
I get the error and coverage for only my test file not pyx file.
cyApple.pyx NotPython: Couldn't parse '/home/final/cyApple.pyx' as Python source: 'invalid syntax' at line 2
Name Stmts Miss Cover Missing
--------------------------------------------
appletest.py 8 1 88% 9
I tried to look online and get some help , so i added
.coveragerc file with contents as :
[run]
plugins = Cython.Coverage
On running "coverage run appletest.py" i get errors :
...
...
...
ImportError: No module named Coverage
I want to generate simple code coverage report for my pyx file. How i can do it in a simple way ?
I reinstalled Cython-0.28.3.
Now on running "coverage run appletest.py"
I am getting error :
test1 (__main__.APPLETests) ... Segmentation fault (core dumped)
This is my apple.h file :
#include<iostream>
namespace mango {
class apple {
public:
apple(int key);
int execute();
private:
int _key;
};
}
You must update Cython. The documentation states:
Since Cython 0.23, line tracing (see above) also enables support for
coverage reporting with the coverage.py tool.
I created a simple helper script that:
Runs all cython files in the directory
Creates a linetrace version of cython code, but cleans up after execution, so this won't interfere with production versions.
Produces cython annotated report with line coverage, takes care of .coveragerc creation and all technical stuff
Works well with pyximport, no need to build setup.py and rebuild cython modules
Caveats
It works only for linux (but it's doable to adapt it for another OS)
Built for anaconda python
Project:
https://github.com/alexveden/cython_coverage_script
Source code:
https://github.com/alexveden/cython_coverage_script/blob/master/cy_test/tests/run_cython_coverage_annotations.py
Hopefully this helps anyone, because I spent an enormous amount of time to figure out how to deal with coverage under Cython. It's appeared not a trivial task because, Cython coverage plugin has issues with mapping .pyx paths and pyximport doesn't support coverage directives.

Error running ParseTree

In the Rascal shell, doing this:
import lang::c90::\syntax::C;
import ParseTree;
parse(#TranslationUnit, |file:///teste.c|);
I get in the stable standalone jar:
|prompt:///|(24,93,<1,24>,<1,117>): ParseError(|file:///home/rafael2k/files/UnB/static_analysis/eclipse-workspace/rascal-C/c-source/teste.c|(47,0,<4,0>,<4,0>))
at parse(|prompt:///|(24,93,<1,24>,<1,117>))
at *** somewhere ***(|prompt:///|(24,93,<1,24>,<1,117>))
at parse(|prompt:///|(24,93,<1,24>,<1,117>))
And in Eclipse I get a giant message error:
(...)
public AbstractStackNode<IConstructor>[] FloatingPointConstant() {
return FloatingPointConstant.EXPECTS;
}
public AbstractStackNode<IConstructor>[] StructDeclarator() {
return StructDeclarator.EXPECTS;
}
}
Advice: |http://tutor.rascal-mpl.org/Errors/Static/JavaCompilation/JavaCompilation.html|null
Any tip?
Btw, running Debian Jessie, Oracle Java 1.8.0_112,x86_64.
I think it can be fixed with this:
parse(#start[TranslationUnit], |file:///teste.c|);
By using a start non-terminal you can parse files which begin and/or end with whitespace or source code comments. See also the answer to this question: Layout in Rascal
By the way, this grammar will parse c programs after the processor has been applied.
The Eclipse error is a seemingly unrelated issue for which we would love to receive a stack trace on the github issue tracker.

Lua - "multiple vms detected" while trying to add extension for statically linked Lua

I have application that contain statically linked lua 5.2 inteperpreter (and haven't access to code).
When I trying to write extension with next code:
#define LUA_LIB
#define LUA_BUILD_AS_DLL
#include "lua.hpp"
extern "C"
{
static int test(lua_State* state)
{
return 1;
}
static const struct luaL_Reg functions[] = {
{"test", test},
{NULL, NULL},
};
int __declspec(dllexport) luaopen_test(lua_State* state)
{
luaL_newlibtable(state, functions);
luaL_setfuncs(state, functions, 0);
return 0;
}
}
And compile it with statically linked lua52.lib .
I get "multiple vms detected" error when I trying to require it fromn lua code.
What I can do in this situation?
You can't compile it with statically linked lua52.lib as the main application loads its own version of lua52.lib and when this module is "required", it loads its own copy, which leads to "multiple VMs detected" message.
With statically compiled VM you have two options (on Windows): (1) include all your modules statically, or (2) compile your modules against Lua52.dll, but instead of the actual DLL include a "proxy" DLL that will forward Lua API calls to the methods in the statically compiled executable (the API methods also need to be exported in the executable).
See this thread for the discussion on how the executable needs to be compiled and LuaProxyDllFour page for the proxy DLL.
On Linux you don't need to have a proxy library, but you still need to avoid linking Lua interpreter into the library and export symbols from the executable by using -Wl,-E linker option; see lhf's answer for details.

Error when Compiling Clang Tool RecursiveASTVisitor : error: conflicting return type CreateASTConsumer

I just learn clang tool about How to write RecursiveASTVisitor based ASTFrontendActions.
I followed the example in the documentation and compile the example code, and there was always one error. I don't know why it have this error and how to solve it. I didn't find the solution of related problem. I don't know whether who meet the same problem and solved it.
/home/sun/project/clang-llvm/llvm/tools/clang/tools/extra/find-class-decls/FindClassDecls.cpp:44:31: error: conflicting return type specified for ‘virtual clang::ASTConsumer* FindNamedClassAction::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef)’
In file included from /home/sun/project/clang-llvm/llvm/tools/clang/tools/extra/find-class-decls/FindClassDecls.cpp:4:0:
/home/sun/project/clang-llvm/llvm/tools/clang/include/clang/Frontend/FrontendAction.h:64:40: error: overriding ‘virtual std::unique_ptr clang::FrontendAction::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef)’
ninja: build stopped: subcommand failed.
Thanks!
Oops. I've updated the documentation the rest of the way. It should have read:
class FindNamedClassAction : public clang::ASTFrontendAction {
public:
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
clang::CompilerInstance &Compiler, llvm::StringRef InFile) {
return std::unique_ptr<clang::ASTConsumer>(
new FindNamedClassConsumer(&Compiler.getASTContext()));
}
};
As of r215323, FrontendAction::CreateASTConsumer was changed to return a std::unique_ptr<clang::ASTConsumer> instead. I've updated the documentation on http://clang.llvm.org/docs/RAVFrontendAction.html to reflect that.
when I change to std::unique_ptr. At the same time, I keep return new FindNamedClassConsumer(&Compiler.getASTContext()); not like you have updated the documentation "return new FindNamedClassConsumer;". Now When I compile FindClassDecls.cpp, there is still another error.
/home/sun/project/clang-llvm/llvm/tools/clang/tools/extra/find-class-decls/FindClassDecls.cpp:46:64: error: could not convert ‘((&(& Compiler)->clang::CompilerInstance::getASTContext()), (operator new(24ul), (((FindNamedClassConsumer*))->FindNamedClassConsumer::FindNamedClassConsumer(), ((FindNamedClassConsumer*)))))’ from ‘FindNamedClassConsumer*’ to ‘std::unique_ptr’.
Thank you very much!

javac will not compile enum, ( Windows Sun 1.6 --> OpenJDK 1.6)

package com.scheduler.process;
public class Process {
public enum state {
NOT_SUBMITTED, SUBMITTED, BLOCKED, READY, RUNNING, COMPLETED
}
private state currentState;
public state getCurrentState() {
return currentState;
}
public void setCurrentState(state currentState) {
this.currentState = currentState;
}
}
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.state;
public class Machine {
com.scheduler.process.Process p = new com.scheduler.process.Process();
state s = state.READY; //fails if I don't also explicitly import Process.state
p.setCurrentState(s); //says I need a declarator id after 's'... this is wrong.
p.setCurrentState(state.READY);
}
Modified the example to try and direct to the issue. I cannot change the state on this code. Eclipse suggests importing Process.state like I had on my previous example, but this doesn't work either. This allows state s = state.READY but the call to p.setCurrentState(s); fails as does p.setCurrentState(state.READY);
Problem continued.... Following Oleg's suggestions I tried more permutations:
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.*;
public class Machine {
com.scheduler.process.Process p = new com.scheduler.process.Process();
public state s = Process.state.READY;
p.setCurrentState(s);
p.setCurrentState(state.READY);
}
Okay. It's clear now that I'm a candidate for lobotomy.
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.state;
public class Machine {
public void doStuff(){
com.scheduler.process.Process p = new com.scheduler.process.Process();
state s = state.READY; //fails if I don't also explicitly import Process.state
p.setCurrentState(s); //says I need a declarator id after 's'... this is wrong.
p.setCurrentState(state.READY);
}
}
I needed to have a method in the class--but we're still missing something (probably obvious) here. When I go via the command line and run javac on the Machine class AFTER compiling Process, I still get the following error:
mseil#context:/media/MULTIMEDIA/Scratch/Scratch/src/com/scheduler/machine$ javac Machine.java
Machine.java:3: package com.scheduler.process does not exist
import com.scheduler.process.Process;
^
So I guess the question now becomes, what idiot thing am I missing that is preventing me from compiling this by hand that eclipse is doing for me behind the scene?
======
Problem solved here:
Java generics code compiles in eclipse but not in command line
This has just worked for me:
Download latest Eclipse
Create new project
Create two packages com.scheduler.process and com.scheduler.machine
Create class Process in package com.scheduler.process and class Machine in com.scheduler.machine and copy their contents from your post modifying them to conform to Java language syntax, like this:
Everything compiles right away.
------ to answer the previous version of the question ------
To answer the question as it is right now: you need to either
import com.scheduler.process.Process.status or import com.scheduler.process.Process.* and refer to status as just status
or
import com.scheduler.process.* or import com.scheduler.process.Process and refer to status as Process.status
------ to answer the original version of the question ------
You can't import classes that are not inside some package. You just can't. It is a compile time error to import a type from the unnamed package.
You don't need to import anything if your classes are in the same package, or if all of your classes are packageless.
If Process class was inside some package it would be possible to import just its status inner class: import a.b.c.Process.status would work just fine.
All your Windows/Linux migration issues don't have anything to do with Java and exceptions that you see. import Process.state; will produce exception on any OS because you can't import classes that don't belong to any package.
Eclipse doesn't use the Sun JDK by default. I would assume that you are using Eclipse's built in compiler as Sun's JDK and the OpenJDK are almost identical.
Java code compiles and runs exact the same on Windows and Linux most of the time (unless you use a few of the platform specific operations)
I suspect you are not building the code the same way and when you compile Machine, the Process class has not been compiled.
I suggest you use a standard build system like maven or ant and it will build the same everywhere. Failing that run Eclipse on Linux or just the same .class you use on windows as they don't need to be re-compiled in any case.
BTW: You don't need to import Process.state as it not used and its in the same package (so you wouldn't need to if you did)

Resources