Re: Wow. It all 'just works'

2019-08-01 Thread Libman
Related to the above:

[GitHub starts blocking developers in countries facing US trade 
sanctions](https://www.zdnet.com/article/github-starts-blocking-developers-in-countries-facing-us-trade-sanctions/)

Of course people with unpopular political opinions have been facing informal 
sanctions (ex. shadow-censorship) for years now, but a lot more people will 
soon have reasons to avoid major platforms like GitHub. It could include rather 
large nations like Russia and China... 


Re: How to Maintain a Nim Chinese Community

2019-08-01 Thread Libman
Just curious, is IPFS taking off in Mainland China?

I was thinking of thinking of possibly contemplating an IPFS mirror of the Nim 
ecosystem (git source code, Web-site snapshots, videos, binaries, etc). 


Async socket to server connection error handling

2019-08-01 Thread adokitkat
Hello guys.

Is there any way to find out if async socket _proc connect()_ has established a 
connection or not - it just returns Future[void] either way - or a proper way 
to handle refused connections?

My program crashes when I call 


 await socket.recvLine() 

Run

for a socket where 


 asyncCheck socket.connect(serverAddress, port.Port) 

Run

did not established a connection i.e. random IP, but it **works** ok when I 
connect to my server which listens.

I've tried to catch an Exception and OSError (shown in traceback) but it didn't 
work. Shown errors: 


Error: unhandled exception: A request to send or receive data was 
disallowed because the socket is not connected and (when sending on a datagram 
socket using a sendto call) no address was supplied.

Exception message: A request to send or receive data was disallowed because 
the socket is not connected and (when sending on a datagram socket using a 
sendto call) no address was supplied.

Exception type: [OSError]


Run


Re: Tables - can't get the address of value

2019-08-01 Thread r3c
When im creating the faces, i know their exact number, but to speedup the 
rendering, I want to merge them by their common texture. I dont know the number 
of the merged faces, so I have to make one [loop trough all the 
faces](https://github.com/JDragan/CoreQ3BSP/blob/a9242fed0e603628b8c1e901a258a34edb899ad7/src/coreBSP.nim#L93)
 and find the number of unique texture/lightmap combinations.

Then from this number i have the size of the render data (number of merged 
faces) Then I do another loop to fill the data.

With tables I dont have to do that, I can do that in the first loop


Re: Tables - can't get the address of value

2019-08-01 Thread demotomohiro
From: 
[https://nim-lang.org/docs/manual.html#statements-and-expressions-the-addr-operator](https://nim-lang.org/docs/manual.html#statements-and-expressions-the-addr-operator)

> The addr operator returns the address of an l-value.

From: 
[https://nim-lang.org/docs/manual.html#procedures-var-return-type](https://nim-lang.org/docs/manual.html#procedures-var-return-type)

> A proc, converter or iterator may return a var type which means that the 
> returned value is an l-value and can be modified by the caller:

In other words, when a return type is not a var type, it is not an l-value.

From: 
[https://nim-lang.org/docs/tables.html#%5B%5D%2CTable%5BA%2CB%5D%2CA](https://nim-lang.org/docs/tables.html#%5B%5D%2CTable%5BA%2CB%5D%2CA)
 
[https://nim-lang.org/docs/tables.html#%5B%5D%2CTable%5BA%2CB%5D%2CA_2](https://nim-lang.org/docs/tables.html#%5B%5D%2CTable%5BA%2CB%5D%2CA_2)

> proc `[]`[A, B](t: Table[A, B]; key: A): B
> 
> proc `[]`[A, B](t: var Table[A, B]; key: A): var B

So in your `CreateBuffers` proc, `proc `[]`[A, B](t: Table[A, B]; key: A): B` 
is called and it doesn't return var type. You can get an address only from an 
l-value. That is why you cannt use `unsafeAddr` in your code.

You can not access `seq[0]` when the lenght of the sequence is 0.

I think your code shoulde be like: 


proc CreateBuffers*(obj: var RenderableObject) {.inline.} =
# # #
  glBufferData(GL_ARRAY_BUFFER, obj.vertices_tbl[f].len*sizeof(GLfloat), if 
obj.vertices_tbl[f].len == 0: nil else: obj.vertices_tbl[f][0].unsafeAddr, 
GL_STATIC_DRAW)


Run

> if I pass it with var like obj: var RenderableObject it works, but that kinda 
> defeats the purpose of using tables and its very slow

I don't understand neither why you are using tables in your code nor why `var` 
defeats the purpose of using tables only from your code.


Tables - can't get the address of value

2019-08-01 Thread r3c
I use table in type like: 


type
  RenderableObject* = object
vertices_tbl*: Table[int, seq[float32]]
indices_tbl*: Table[int, seq[uint32]]

# init
var FACE : RenderableObject
FACE.vertices_tbl = initTable[int, seq[float32]]()
FACE.indices_tbl  = initTable[int, seq[uint32]]()

#init the seq
proc CreateFace(f: int, pos: int) =
  if not hasKey(FACE.vertices_tbl, pos):
FACE.vertices_tbl[pos] = @[]
FACE.indices_tbl[pos] = @[]


Run

but in OpenGL function where i specify the container 


proc CreateBuffers*(obj: RenderableObject) {.inline.} =
# # #
  glBufferData(GL_ARRAY_BUFFER, obj.vertices_tbl[f].len*sizeof(GLfloat), 
obj.vertices_tbl[f][0].unsafeAddr, GL_STATIC_DRAW)
# # #


Run

It says it cant get the address.

Is it because its not yet initialized? if I pass it with var like _obj: var 
RenderableObject_ it works, but that kinda defeats the purpose and its very slow


Re: spawn/sync hangs -- any ideas?

2019-08-01 Thread mratsim
There might be a deadlock.

Can you compile with `--debugger:native` and attach gdb/lldb and do a backtrace 
if your programs hangs?

Also you can maybe compile with `-d:useMalloc` and use helGrind to try to find 
threading errors: 
[http://valgrind.org/docs/manual/hg-manual.html](http://valgrind.org/docs/manual/hg-manual.html)


Re: spawn/sync hangs -- any ideas?

2019-08-01 Thread cdunn2001
Even in my current program (runs in a second, but builds a lot of code), this 
hangs only 1 in 10 tries. It's a "Heisenbug", an intermittent multi-threading 
error. And it's almost certainly in Nim because my code spawns only 1 task.


Re: spawn/sync hangs -- any ideas?

2019-08-01 Thread cdunn2001
@araq, if I don't call `threadpool.setMaxPoolSize(1)`, this always works. I 
think there is a bug in threadpool resizing, which is a must-have for me.

Should I file a bug? I cannot provide a simple repro from my current codebase.


spawn/sync hangs -- any ideas?

2019-08-01 Thread cdunn2001
What could cause sync() to hang?


for x in stage1:
spawn startStage1(x)
sync()
log("First sync() done.")


Run


proc startStage1(args: Stage1) =
log("StartProcess in Stage1: '", args.icmd, "'")
var p = startProcess(command = args.icmd, options = {poEvalCommand,
poStdErrToStdOut})
var argsx = args
argsx.sin = p.outputStream
doStage1(argsx)
log(" startStage1: p.close() ...")
p.close()
log(" startStage1: p.close() done")


Run

I see everything except "First sync() done."

This is all after `threadpool.setMaxPoolSize(1)`, and the size of the array is 
`1`.

What could possibly prevent "sync()" from working. (Verified behavior with both 
0.20.0 and 0.20.2.)


Re: What do you think about the programming language NIM?

2019-08-01 Thread Kiloneie
Having curly braces {} and having to type semicolons every time; and more isn't 
less readable to me either, but it does add extra unnecessary stuff to type. 
Python style indentation(which to me is an upgrade from BASIC syntax which i 
have used) makes it faster to write what you are aiming to. But you know that's 
just an opinion D:.


Re: Roadmap Document?

2019-08-01 Thread bobd
Excellent - thanks - I'll take a look at it later this month.


Re: Roadmap Document?

2019-08-01 Thread mratsim
Hot-reloading works but is still rough as it's not even 6 months old.

You can probably already try building a REPL on top, but just make sure to not 
stay alone if you hit a bug, join the IRC/Gitter/Discord/Matrix.

Alternatively for REPL you have

  * `nim secret`, unsupported secret command line option to get a limited REPL 
(it doesn't support anything that requires a C library)
  * `INim` \- 
[https://github.com/AndreiRegiani/INim](https://github.com/AndreiRegiani/INim), 
which works with plain raw Nim.




Re: Roadmap Document?

2019-08-01 Thread bobd
@mratsim On my to-do list for August is to take an initial look at Nim REPL 
options - so is the hot-loading work that was done recently still needing work 
to get a REPL going?


Re: Erroneous values returned from Nim’s C foreign function interface.

2019-08-01 Thread napalu
Judging from the c example you posted, your sizes are wrong. On my system utmpx 
is defined something like 


utmpx* = object
ut_type*:ut_type   #  Type of record
ut_pid*:cint   #  PID of login process
ut_line*:array[UT_LINESIZE,char]   #  Device name of tty - "/dev/"
ut_id*:array[4,char]   #  Terminal name suffix   or 
inittab(5) ID
ut_user*:array[UT_NAMESIZE,char]   #  Username
ut_host*:array[UT_HOSTSIZE,char]   #  Hostname for remote login, or 
kernel version for run-level  messages
ut_exit*:cint  #  Exit status
ut_session*:cint   #  Session ID (getsid(2))
ut_tv*:tv  #  Time entry was made */
ut_addr_v6*:array[4,int32]   #  Internet address of remote host; 
IPv4 address uses just ut_addr_v6[0] */
reserved:array[20, char]


Run

And you're calling inet_ntop with the wrong size arguments. Something like


const
  UT_LINESIZE =  32
  UT_NAMESIZE =  32
  UT_HOSTSIZE =  256
  INET6_ADDRSTRLEN = 46

proc getfromIP(ut:ptr utmpx):cstring=
  var buff: array[INET6_ADDRSTRLEN, char]
  result = inet_ntop(AF_INET,ut.ut_addr_v6[0].addr, buff[0].addr, 
INET6_ADDRSTRLEN)


Run

should work.