Skip to content

asyncio.nim compiles to invalid C-file (asyncio.c)  #1148

@ninjacato

Description

@ninjacato

Using the following import statement

import asyncio

Gives the following build error

c:\test\nimcache\asyncio.c:1183:4: error: 'else' without a previous 'if'
else {
^

The asyncio.c line the compiler complains about is the following

    popSafePoint();
}
F.len-=1; // 1182
else { // 1183
    popSafePoint();

As you can see, the compiler inputs "F.len-=1" between the end of an "if" clause and the beginning of "else", making the source code file invalid. The reason seem to be the try/catch on line 236-251 in asyncio.nim (https://github.com/Araq/Nimrod/blob/devel/lib/pure/asyncio.nim#L236)

I tried removing the try/catch in asyncio.nim leaving me with the following code on line 235-247

let sock = PAsyncSocket(h)
let bytesSent = sock.socket.sendAsync(sock.sendBuffer)
if bytesSent == 0:
    # Apparently the socket cannot be written to. Even though select
    # just told us that it can be... This used to be an assert. Just
    # do nothing instead.
elif bytesSent != sock.sendBuffer.len:
    sock.sendBuffer = sock.sendBuffer[bytesSent .. -1]
elif bytesSent == sock.sendBuffer.len:
    sock.sendBuffer = ""

if PAsyncSocket(h).handleWrite != nil:
    PAsyncSocket(h).handleWrite(PAsyncSocket(h))

... and it compiles.

Notes: Tried with Nimrod 0.9.4 (32bit) on Windows 8 x64.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions