Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Mar 03 2017 15:52
    @dom96 banned @Octopoda7
  • Feb 12 2017 23:57
    @dom96 banned @zzz125
  • Dec 23 2016 19:43
    @dom96 banned @Izrab
From IRC (bridge bot)
@FromIRC
<rayman22201> Nim maps exceptions to C++ exceptions when using the C++ backend, and those have proven to have acceptable overhead (They are actually very performant in modern compiler implementations). Using the C backend, they are mapped to crudely to long jumps IIRC... but I don't remember exactly. They do have worse performance in the C backend though.
<rayman22201> unwrapping is not as big of an issue because nim datatypes don't have most of the OOP garbage attached to a C++ class
<I_Right_I> rayman22201: Okay thanks for the insight!
<rayman22201> sorry I can't be more specific. It's not my area of expertise.
From IRC (bridge bot)
@FromIRC
<I_Right_I> I just don't know the does and don't of exceptions in nim and I have to use them in the library I am working on. But I abstract them out of the interface.
From IRC (bridge bot)
@FromIRC
<rayman22201> hrmm. Well, there aren't any big usability gotchas that I know of. Though, if you can, I do recommend using nim cpp to get the c++ backend for performance.
From IRC (bridge bot)
@FromIRC
<I_Right_I> Okay, I doubt I even need to o that. I am not using it in any performance critical area's as of right now.
<rayman22201> fair enough. At least you know you have the option. another tool in the toolbox as they say :⁠-)
Kaushal Modi
@kaushalmodi
hello all
I'm coming back to Nim/C binding exercise after a while, and I have never handled mapping a C array pointer type to Nim
How would I map int *data; from C to Nim?
I looked in Nim forum but the solution there to use a 0..0 array with {.unchecked.} doesn't work on the latest devel. Ref: https://forum.nim-lang.org/t/567
Kaushal Modi
@kaushalmodi
So the question is how do I map a pointer to a dynamic array in C (whose length I don't know at compile time) to Nim?
The bigger picture is that I am exporting a Matlab code to C using Matlab and then trying to map that to Nim
a snippet of Matlab exported C header:
struct emxArray_int32_T
{
  int *data;
  int *size;
  int allocatedSize;
  int numDimensions;
  boolean_T canFreeData;
};

typedef struct emxArray_int32_T emxArray_int32_T;

typedef struct {
  emxArray_int32_T *data;
  int len;
} struct0_T;
From IRC (bridge bot)
@FromIRC
<shashlick> hey @kaushalmodi ltns
Kaushal Modi
@kaushalmodi
shashlick: hello! Yeah, work, life
From IRC (bridge bot)
@FromIRC
Kaushal Modi
@kaushalmodi
hmm, it says unchecked is an invalid pragma
also I get warning for using pragma before generics
latest devel
i.e. how do I use it in my code?
genotrance
@genotrance
working on a example
Kaushal Modi
@kaushalmodi
from my Matlab exported example above: struct0_T type has pointer to an array of struct emxArray_int32_T type
and in struct emxArray_int32_T, I have pointers to two int arrays along with other "normal" types
genotrance
@genotrance
Kaushal Modi
@kaushalmodi
Thanks! that's a nice and simple example
btw echo test2 doesn't work as $ isn't implemented for UncheckedArray
I don't know if that's intentional or an oversight
I'd have thought that that $ printed all values in the allocated space
From IRC (bridge bot)
@FromIRC
<shashlick> well its an array of integers
<shashlick> well its an array of integers
Kaushal Modi
@kaushalmodi
actually test2 is the ptr right?
but even echo test2[] doesn't work
From IRC (bridge bot)
@FromIRC
<shashlick> yep, []
Kaushal Modi
@kaushalmodi
yeah, that doesn't work
but this works, so good enough to proceed with my debug for now:
for i in 0 .. 3:
  echo test2[i]
Kaushal Modi
@kaushalmodi
shashlick: are you still here?
I got the Nim code to compile, but ending up with SIGSEGV .. Nim code: http://ix.io/1FlB
the code calls mean_func_1 from compiled .so of Matlab exported .c
here's the mean_func_1 implementation in C: http://ix.io/1FlC
Jacek Sieka
@arnetheduck
@rayman22201 - immutable is not quite it - I want to mutate state at other places - I just don't want that to be allowed while a non-owning reference to state exists
or maybe I'm reading it wrong. it doesn't quite say if the existence of a non-owning ref has that effect.
Kaushal Modi
@kaushalmodi
shashlick: I cannot believe; I understood the C code myself and fixed the Nim code! :P
fixed Nim code: http://ix.io/1FlE
thanks for your help with UncheckedArray; that motivated me to try to solve this
From IRC (bridge bot)
@FromIRC
<shashlick> Sorry was away
From IRC (bridge bot)
@FromIRC
<PMunch> Hmm, I think there's something wrong with my computer case/sound card