Create a ref to a C allocated object to manage its memory

2022-12-27 Thread sls1005
A Nim `seq` is not just a pointer and a length. It also has a capicity which might be stored on the heap before data. It also use a pointer interally, therefore a `ref seq` is a pointer-to-pointer which must be used carefully (and only when needed.) For your case, I recommend @Hlaaftana's soluti

Is setControlCHook still supported ?

2022-12-27 Thread archnim
Hello world. setControlCHook doesn't work for me, nether does it return an exception. I checked its definition in system.nim, and it's just a prototype ! Am I missing something ??

Javascript backend and implicit cstring conversions

2022-12-27 Thread tmsa04
There were several warnings I saw, including some related to cstrings, at various points compiling using Nim built from Nim devel git, but at more recent points in Nim development when I've tried this, the warnings had disappeared, so it might be worth checking how things go after that version i

Creating const in a macro fails in 1.9.1

2022-12-27 Thread yister
Not quite sure where to go with this, and whether it's something I'm doing wrong, or some behavior that changed in the new (rc) version, so figured I'd give the forum a shot. I'm trying to register some types and associated metadata during compile time, and that worked fine in 1.6.8. I also see

Mastering Nim: A complete guide to the programming language

2022-12-27 Thread jrfondren
> I'm troubleshooting Nim instead of using it on the first page of a Nim book. For the record this was due to a May 2019 file `~/.config/nimble/nimble.ini` containing those useless/legacy URLs. Fixed by blowing away ~/.config/nimble So it's at least not a problem a new user's likely to run into.

Is it possible to "mock" function calls? (For testing purposes)

2022-12-27 Thread Isofruit
I have arrived at a solution thanks to ElegantBeef and Vindaar! The core idea is that you can use the power of pragmas/macros to rewrite a function definition so that it is instead an anonymous proc assigned to a mutable variable! What this allows you is then to simply reassign the proc in the

Parazoa - Immutable, persistent data structures for Nim

2022-12-27 Thread sekao
Yep I saw [your project](https://github.com/PMunch/nim-persistent-vector) and I worked off of the same [blog posts by hypirion](https://hypirion.com/musings/understanding-persistent-vector-pt-1). I still haven't implemented the tail optimization he wrote about in part 3 though but maybe I'll fi

Strange error: single character string constants

2022-12-27 Thread SolitudeSF
`@[]` doesnt have definite type and there are too many indirection for compiler to infer it.

Default orc crash simple jester httpbeast

2022-12-27 Thread Araq
Fair enough. Can't blame anybody for avoiding Microsoft.

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
Glad you understand. I hope help nim take a step.

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
and I do apologize for using this forum to report this but it's been around since orc became default and I really wanted to get it to someone. This was my best effort. I'll take your personal email though. I'm at: wmcont...@protonmail.com

Parallel Fibonacci

2022-12-27 Thread Araq
You need to use a package that does this better than Nim's stdlib. For example: * * *

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
Thanks Araq. When Microsoft (owners of github) finally make me a job offer after all the rejections since 1992 I'll stop boycotting an account on github. :) I don't think I can file a bug therefore. I encourage you to do as I really want to see Nim surge.

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
BTW, I didn't do that font change I just cut and paste into the forum. It just blew up weirdly.

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
This the line I was referring to saying no check on incoming ptr p. It's the first line. let h = head(p) inc h.rc, rcIncrement

Default orc crash simple jester httpbeast

2022-12-27 Thread Araq
Report bugs on github please.

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
There is this triple X comment at the definition though. What is still not correct? const optimizedOrc = false # not defined(nimOldOrc) # XXX Still incorrect, see tests/arc/tdestroy_in_loopcond

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
to offer a bit more on my version of nim that I checked out on Dec 23 this is the code the error cites. The line is 47 which is the 'when' line. proc nimIncRefCyclic(p: pointer; cyclic: bool) {.compilerRtl, inl.} = let h = head(p) inc h.rc, rcIncrement when optimizedOrc: if cyclic:

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
And optimizedOrc is a constant that is false. Not a ptr. So it doesn't make much sense to me.

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
An older version of httpbeast that is as relates to prologue.

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
So, in short httpbeast seems to not play well with orc on my machine. :) Old as it is I think this shouldn't happen eh?

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
It orignates in httpbeast both in jester using it externally and from what I understand prologue is using an older version cloned from time past.

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
And here is the error: `/home/myhome/.nimble/pkgs2/httpbeast-0.4.1-b23e57a401057dcb9b7fae1fb8279a6a2ce1d0b8/httpbeast.nim(83) eventLoop` `/home/myhome/nim/lib/system/orc.nim(46) nimIncRefCyclic` SIGSEGV: Illegal storage access. (Attempt to read from nil?) Segmentation fault (core dumped)

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
I looked at orc impl and noticed that nimIncRefCyclic does not check the incoming pointer for nil which maybe be the spot but I don't know rather is should never get there with a non nil as I don't know the full impl.

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
This code causes the crash: import htmlgen import jester routes: > get "/": > resp h1("Hello world")

Default orc crash simple jester httpbeast

2022-12-27 Thread Cnerd
Also you can try using the not nil pragma to make sure that your procedures do not return a nil value

Default orc crash simple jester httpbeast

2022-12-27 Thread Cnerd
The crash is not because of orc. It's from trying to access a ref or pointer object that is nil. The problem is probably in your database code. You can tell the os to avoid the error by importing std / segfault in the file causing the segfault error

Create a ref to a C allocated object to manage its memory

2022-12-27 Thread Hlaaftana
I expected there to be a library that does it but couldn't find one, though it should be easy to do, something like: type Array[T] = object len: int data: ptr UncheckedArray[T] proc `=destroy`[T](x: var Array[T]) = if not x.data.isNil: for i in 0 ..

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
And BTW, the failures are happening with orc.

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
More info. I have developed a web crud web service with jester and prologue both of which work fine with getting data under stress with refc and markandsweep. Jester fails right away as above. Prologue runs for indeterminate time and then segv's. The stress is just running GETs on small datamode

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
The basic jester app produced second result: # example.nim import htmlgen import jester routes: get "/": resp h1("Hello world")

Parallel Fibonacci

2022-12-27 Thread DougT
As a learning exercise in parallel computing, I would like to parallel compute the classic definition of the Fibonacci sequence. I realize there are many fast ways to compute the Fibonacci sequence, but I would like to use the classical definition as an exercise. If I try import t

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
System is older debian linux. Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18

Default orc crash simple jester httpbeast

2022-12-27 Thread niminuse001
Hello: Built nim on linux amd64 and tried simple jester route cited on jester page. Got this: INFO Jester is making jokes at Starting 2 threads Listening on port 5000 No stack traceback available SIGSEGV: Illegal storage access. (Attempt to read from nil?) Segmentation fa

Create a ref to a C allocated object to manage its memory

2022-12-27 Thread samdze
That is not enough for me. I want to wrap the C returned array into an immutable seq and return it to the user to provide a safe API. Seems like openArrays cannot be used this way. Also, I'd like Nim to call the `=destroy` proc I defined when there are no references to this (ref) seq left.

Create a ref to a C allocated object to manage its memory

2022-12-27 Thread shirleyquirk
Kind of! you can convert it to an `openArray` and use it in most places

Strange error: single character string constants

2022-12-27 Thread freeflow
Indeed, I continue to explore how nim can be used better. I now have those single character string defined as chars and am experimenting with type direction = enum North = (0, $twHat) East = (1, $twRAngle South = (2, "v") West

Create a ref to a C allocated object to manage its memory

2022-12-27 Thread samdze
Thanks for your replies! Related to this thread, I have another question: This time I'd like to wrap (and manage) a C returned array (pointer to heap + length) into a Nim seq (or ref seq) without performing extra copies. Is it possible?

Is there a traditional rounding function?

2022-12-27 Thread shirleyquirk
> i don't see that any particular rounding style is inherently any more correct > than any other (and there are what, 6 different ways?*) but the way that `formatBiggestFloat` (and therefore strformat) works is to use `sprintf`, which, yes, uses round to even. [*] there's 8 specified for IEEE D

Strange error: single character string constants

2022-12-27 Thread PMunch
By the way, in Nim it would be good practice to define groups of constants like these as enums. Make it possible to write type safe procedures that accept a sub-set of your constants.

How to further speed up the build of your Nim's projects (using ccache)

2022-12-27 Thread arnetheduck
> This sounds interesting, is it possible to tell the Nim compiler to use a > copy of stdlib residing in /tmp for example? If so, how? Nim C file generation is not deterministic between projects: because of dead code elimination and the random order in which the compiler generates code, the `c`

Parazoa - Immutable, persistent data structures for Nim

2022-12-27 Thread PMunch
Oh cool, I've been thinking about implementing these ever since I did my Clojure-based persistent vectors!

Is there a traditional rounding function?

2022-12-27 Thread fzqdoo
alright, thank you very much

Is there a traditional rounding function?

2022-12-27 Thread HJarausch
By the way, 165.562 **is correct**. The general rule is to round x5 to the next **even** digit, i.e. 2.5 should be rounded to 2 whereas 3.5 should be rounded to 4. There is an IEEE norm for rounding which is used in banking software.

How to further speed up the build of your Nim's projects (using ccache)

2022-12-27 Thread CraneDancingShape
I have found a way to share the cache with the project, but since very few people will benefit from this, I will only report on it. > After some trial and error(ccache -o debug=true), I think the ccache manual > needs to turn off the inclusion of the current directory in the hash in > hash_dir(

Is there a traditional rounding function?

2022-12-27 Thread Vindaar
There is in `math`: (generally searching here is a good idea)

Is there a traditional rounding function?

2022-12-27 Thread fzqdoo
Hi all, now I am converting a string to float. var e = "165.5625".parseFloat echo fmt("{e:1.3f}") The result is 165.562, which is wrong. The result I want to get is 165.563. I searched the nim class library and found no related functions. Is there such a function? thanks

Strange error: single character string constants

2022-12-27 Thread Hlaaftana
If you remove the `$` from `myChar: char = $mydata[myRow][myCol]` and convert the constants to chars as well, it should work. Thanks for giving information about this issue, the confusing error message should be fixed with

Strange error: single character string constants

2022-12-27 Thread freeflow
I think I've located the cause of the issue. The constants const WALL : string = twHat const PATH : string = twPeriod const EAST : string = twLAngle const WEST

try-catch misbehavior

2022-12-27 Thread xigoi
The problem is that bounds checks can be disabled in Nim, so the behavior of the program could change depending on compile flags, which is not good. Use a manual bounds check instead.

try-catch misbehavior

2022-12-27 Thread slangmgh
I don't like the exception model of Nim, when I want to write an server program, which process data every cycle, there is possible sometime the program don't do good because of we don't know what will the input data be, so I need to catch all exception, regardless of Defect or Error or SystemErr

Strange error: single character string constants

2022-12-27 Thread Hlaaftana
Again, the error is likely happening in the context where you _use_ the constant `SOUTH`, Nim is just giving incorrect line information for the error. We could fix this issue but it would be nice to know the exact context

OpenGPT seems to sort-of work with Nim also.

2022-12-27 Thread mantielero
I also played a little bit with OpenGPT and Nim these days. I tried to see how good could it be on creating bindings: Which won't work (there are too many failures), but it doesn't look too alien either. I was wondering how good would it be this sort of approach for