Re: segfault using string from c?

2017-07-16 Thread segmentation_fault
ok fixed i had to call NimMain(); this fixed everything


PyMODINIT_FUNC
PyInit_fib(void)
{
NimMain();
return PyModule_Create(_module);
}



Re: segfault using string from c?

2017-07-16 Thread segmentation_fault
thx this got the $fpx working now getting a segfault when i do open(), ill 
investigate further i guess its something related it works perfectly fine when 
not calling it from c.


Re: segfault using string from c?

2017-07-16 Thread yglukhov
Ok, so the problem is likely that Nim runtime is not initialized. Try 
setupForeignThreadGc() at the beginning of your proc. TBH, i don't remember 
exactly how this is done...


Re: segfault using string from c?

2017-07-16 Thread segmentation_fault
yes i tried that but if i do $fpx i get a segfault on the $fpx valgrind segfult 
line the compiled code is at fp = cstrToNimstr(fpx);


Re: segfault using string from c?

2017-07-16 Thread yglukhov
What's your C code then? Are you calling this proc from C program or from Nim 
program? If C program, Nim's GC might not be initialized.


Re: segfault using string from c?

2017-07-16 Thread segmentation_fault
if it helps this is the valgrind output 


==9355== Process terminating with default action of signal 11 (SIGSEGV)
==9355==  Access not within mapped region at address 0x0
==9355==at 0x665CA1B: lowGauge_3mwQtFaBTgevFrybZdgUNw 
(stdlib_system.c:1380)
==9355==by 0x6664A53: 
prepareForInteriorPointerChecking_Zqr3EQAAcehIfp3uSECEuQsystem 
(stdlib_system.c:1418)
==9355==by 0x6664A53: collectCTBody_zoTIuavlrCHyw3B8MBaLJA_2 
(stdlib_system.c:4046)
==9355==by 0x6664BF7: collectCT_zoTIuavlrCHyw3B8MBaLJA 
(stdlib_system.c:4115)
==9355==by 0x6664ED8: rawNewObj_QBPo5VW2O56Eeh8hPbQ7Pg 
(stdlib_system.c:4210)
==9355==by 0x666512F: newObjNoInit (stdlib_system.c:4226)
==9355==by 0x66651B3: rawNewStringNoInit (stdlib_system.c:4243)
==9355==by 0x6665251: toNimStr (stdlib_system.c:4707)
==9355==by 0x665A7AB: read_csv (fib.c:335)
==9355==by 0x6658C39: first_func (fib.c:22)
==9355==by 0x4E9B9E: PyCFunction_Call (in /home/x/x/venv/bin/python3.5)
==9355==by 0x524413: PyEval_EvalFrameEx (in 
/home/x/x/venv/bin/python3.5)
==9355==by 0x52D2E2: ??? (in /home/x/x/venv/bin/python3.5)


and this is my c code 


#include "nimcache/fib.h"
#include 
#include 
static PyObject* first_func(PyObject* self, PyObject* args)
{
char * value;

if (!PyArg_ParseTuple(args, "s", ))
return NULL;

read_csv("/home/x/Downloads/x.csv");

return Py_BuildValue("f", 1.1);
}



Re: Defining procs with a template

2017-07-16 Thread Nycto
Yup, that works.

For anyone looking to spot the difference, here is original signature:


template defineIndex*(name, source: typedesc, extractIt, cmpAB: untyped) 
{.immediate.} = ...


When you just remove the immediate, it breaks. Here is the working signature:


template defineIndex*(name, source, extractIt, cmpAB: untyped) = ...


The difference is that _[all](https://forum.nim-lang.org/postActivity.xml#all) 
of the arguments are untyped, versus using typedesc for the first two arguments.

@Araq, if you've got a moment (or anyone else that can offer details): why does 
this work?


Re: segfault using string from c?

2017-07-16 Thread yglukhov
First way is correct, except conversion from cstring to string should be made 
with $. 


proc read_csv(fpx: cstring): void {.exportc.} =
let fp = $fpx
var s = newFileStream(fp, fmRead)
if s == nil:
echo "file not found"
return



segfault using string from c?

2017-07-16 Thread segmentation_fault
How can you pass a char * to nim, ive been trying for a while but i keep 
getting segfault.

if i use:


proc read_csv(fpx: cstring): void {.exportc.} =
let fp: string = cast[string](fpx)
var s = newFileStream(fp, fmRead)
if s == nil:
echo "file not found"
return


then there's a segfault at newFileStream

if i use


proc read_csv(fp: string): void {.exportc.} =
var s = newFileStream(fp, fmRead)
if s == nil:
echo "file not found"
return


then the first 15 chars get truncated, but i still also get a segfault at 
newFileStream

i tried calling the function from c with read_csv("/path/to/csv");

if i run the nim file instead of compiling to c it works.

Also i found out that if i hardcode the value i get a segfault here 
STRING_LITERAL(TM_xgSOGG8fvQlwPH9bPyp9bbTg_6, "path_here", 36);

thx 


Re: Defining procs with a template

2017-07-16 Thread Araq
Try this prototype:


template defineIndex*(name, source, extractIt, cmpAB: untyped) = ...



Re: Nim Dynamic Libraries: exporting functions that return pointer-based types

2017-07-16 Thread RedFred
I have now written a [blog post about 
this](http://www.bootstrap.me.uk/bootstrapped-blog/nim-for-the-discerning-rubyist)

Feel free to ignore the first, introductory, part 


Defining procs with a template

2017-07-16 Thread Nycto
Hey folks!

As the immediate pragma is deprecated, I'm updating my packages to remove 
references to it. I've got one situation where I'm curious about the best 
alternative. It's [this 
template](https://github.com/Nycto/RBTreeNim/blob/a64b6a8ad230a8a8f34e7ce1f6564ebf423a5b17/rbtree.nim#L34-L72).
 Basically, I'm using a template to define a type with a few procs. When I 
remove {. immediate .}, my [test 
fails](https://github.com/Nycto/RBTreeNim/blob/a64b6a8ad230a8a8f34e7ce1f6564ebf423a5b17/test/customize_test.nim).

I know I could achieve this using a macro instead, but since all I'm doing is 
some basic substitutions, a template feeks a bit more clear. What's the best 
way to achieve this?


Re: Arraymancer - A n-dimensional array / tensor library

2017-07-16 Thread mratsim
The only static parts of the Tensor types are the Backend (Cpu, CUDA, ...) and 
the internal type (int32, float32, object ...).

The network topology will be dynamic and using dynamic graphs more akin to 
PyTorch/Chainer/DyNet than Theano/Tensorflow/Keras.

My next step is to build an autograd so people only need to implement the 
forward pass, backpropagation will be automatic. For this part I'm waiting for 
VTable.

PS: I think NimData is great too, Pandas seems like a much harder beast!


Re: In-Memory Database

2017-07-16 Thread alfrednewman
Thank you all !

@Stevo, can you pls provide some examples of how to use it ?


Re: Advance Nimble configs?

2017-07-16 Thread Nycto
For anyone facing a similar problem, I centralized my build configuration here:

[https://github.com/Nycto/ExtraNimble](https://github.com/Nycto/ExtraNimble)

It does (basically) everything I asked for in this thread above, though I had 
to do a few hacky things to get it working.