How to use C++ std functions in Cython? - c++11

I would like to write a Cython function that involves strings, so of course I am inclined to use libcpp.string. But I could not figure out how to import std functions like std::to_string().
What is the cleanest way to make std functions available to my Cython file?

A wrapper needs to be written. A full tutorial can be found on docs.cython.org. Some of the standard library has already been ported, but given the monumental effort needed to complete a task (and then do C++11), I highly doubt you'll see std::to_string any time soon.
Anyways, just write it yourself. std::to_string is just a wrapper over std::sprintf anyway.

Related

Lua - Is there a different function in the Lua library that is identical or similar to debug.getupvalues / debug.getupvalue?

Is it possible or is there a function that works similar to debug.getupvalues / debug.getupvalue in the lua library that I could use, as I won't be able to use either soon and I depend on them slightly to keep parts of the code I have working.
Also if I could get the function code for debug.getupvalue it would be a great help as I could just use that as a function instead of using the debug library anymore, although I doubt it is code in Lua.
And before you say it, yes I know the debug library is the most undependable library in all of Lua but it made my code work and I would like to find a way to stop using it before it's too late.
The debug library is not meant to be used in production code (as opposed to tests and unusual debugging situations). There are 3 possible solutions. Two of them require changes to the code where the closures are defined. The other would require you to know C:
Add more closures in the same scope as the upvalues that will give you the access that you need.
Use tables instead of closures.
Write a C library that makes use of lua_getupvalue.
To see the source code of debug.getupvalue, download Lua 5.3.5 and look at src/ldblib.c, line 260. lua_getupvalue is in src/lapi.c, line 1222.

How do I use a cgo-based package on Windows?

The regexp in the Go's standard library is quite poor, so I need a more powerful engine, like regex in Python (pip install regex), supporting recursion, backref, look-ahead/behind, etc... .
I found:
https://godoc.org/github.com/dlclark/regexp2
.NET compatible, which was quite fine; however, recursion is not working properly.
and several bindings to PCRE, for example:
https://godoc.org/github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre
so, how can I use this binding on Win64?
You may consider using C++ standard library std::regex (no third-party library). Wrap the logic in try block, use catch(...){return ERROR;} to catch any error, and declare the C function extern "C" so you can call with cgo.
From https://github.com/golang/go/wiki/cgo (there is a part about Windows):
In order to use cgo on Windows, you'll also need to first install a
gcc compiler (for instance, mingw-w64) and have gcc.exe (etc.) in your
PATH environment variable before compiling with cgo will work.
That being said, I still think you should consider sticking with the regexp package and try to make regular expressions as simple as possible. Because complicated regular expressions are likely to hurt readability of code. Another problem is sometimes they introduce subtle bugs which are difficult to spot and fix. So writing more code in Go instead of regex may actually make the life easier.

How can I call a built-in compiler function in Ruby?

I'm working in Ruby, and realized that it would be incredibly beneficial to be able to use some of the built-in gcc functions (and x86 architecture built-ins for that matter as well). It seems like having to write an extension to use these is impractical, so I was wondering if there was a way I could call built-ins. For example, if I wanted to call int __builtin_popcount(unsigned int), on a number in Ruby, is there a way I could somehow do
a = rand(1..10000)
__builtin_popcount(a)
I know that I obviously can't do something that basic, but is there a way that I could include gcc and x86 architecture built-ins in Ruby?
It is not quite clear what you want to do.
If you want to call into GCC, you could wrap libgcc in a C extension and design a Ruby API for it.
If you want to generate native code using GCC dynamically, that is currently not possible AFAIK. There is a project for a JIT compiler library based on GCC, but I don't know what its status is. You could wrap that library into a C extension and design a Ruby API for it. At any rate, you will also have to modify the Ruby implementation you are using to be able to link dynamically generated native code with your Ruby code. (And on some implementations that is simply impossible, e.g. on Opal, which is a pure static compiler.)
And of course, not all Ruby implementations actually support C extensions; they are a non-standard feature of YARV and are not guaranteed to work or even exist on other implementations.

Ctags - Find where a function is used in a project

Is there any good way to find where is a function being called in our codebase ?
There is a gem called Starscope (disclaimer: I am the author) which can list function calls in ruby code, among other things. It isn't perfect, since it can't handle crazy meta-programming, but it will find all the normal calls to a given function.
gem: https://rubygems.org/gems/starscope
github: https://github.com/eapache/starscope
user guide: https://github.com/eapache/starscope/blob/master/doc/USER_GUIDE.md
edit: Luc's answer is entirely accurate as far as it goes; I wrote Starscope specifically to be "Cscope for Ruby".
With ctags, no. It references functions declarations and definitions, not their uses.
Then it depends on the language.
cscope can help with C, but not with C++. With C++, you should have a look at clang based solutions : there is clang_indexer (and its many forks) (see vim-clang to integrate it in vim), but I did found a few quirks ; it seems YouCompleteMe does a few things related to code indexation (as it provides GotoImplementation/Declaration commands).
For other languages, you may have dedicated plugins. But for sure, there is always grep (and many plugins that integrates it)

Scala dynamic class management

I would like to know if the following is possible in Scala (but I think the question can be applied also to Java):
Create a Scala file dynamically (ok, no problem here)
Compile it (I don't think this would be a real problem)
Load/Unload the new class dynamically
Aside from knowing if dynamic code loading/reloading is possible (it's possible in Java so I think it's feasible also in Scala) I would like also to know the implication of this in terms of performance degradation (I could have many many classes, with no name clash but really many of them!).
TIA!
P.S.: I know other questions about class loading in Scala exist, but I haven't been able to find an answer about performance!
Yes, everything you want to do is certainly possible. You might like to take a look at ScalaMock, which is an example of creating Scala source code dynamically. And at SBT which is an example of calling the compiler from code. And then there are many different systems that load classes dynamically - look at the documentation for loadLibrary as a starting point.
But, depending on what you want to achieve, you might like to look at Scala Macros instead. They provide the same kind of flexibility as you would get by generating source code and then compiling it, but without many of the downsides of that approach. The original version of ScalaMock used to work by generating source code, but I'm in the process of moving to using macros instead.
It's all possible in Scala, as is clearly demonstrated by the REPL. It's even going to be relatively easy with Scala 2.10.

Resources