Zig: Syntax error in Zig code translated from C

Created on 2 Jan 2020  路  5Comments  路  Source: ziglang/zig

This seems to have been introduced in the last day or so.

cimport.zig:48417:34: error: invalid character: ';'
pub const _POSIX_VDISABLE = '\x00;
                                 ^

It's missing a ' before the ;, but I couldn't find where (in translate_c.zig?) it happens.

bug contributor friendly stage2 translate-c

All 5 comments

can you find _POSIX_VDISABLE in the c code that you are translating? it will help produce the test case for the fix.

never mind, @LemonBoy pointed out the repro:

#define FOO ((unsigned char)'\377')

I tried the fix and now there is a new syntax error:

error: expected token ')', found ';'
    io_read: ?extern fn (?*GIOChannel, [*c]gchar, gsize, [*c]gsize, [*c][*c]GError; GIOStatus,
                                                                                  ^

It's in a project using GTK/glib, and this is the code that's being translated:
```
struct _GIOFuncs
{
GIOStatus (io_read) (GIOChannel *channel,
gchar *buf,
gsize count,
gsize *bytes_read,
GError *
err);
GIOStatus (io_write) (GIOChannel *channel,
const gchar *buf,
gsize count,
gsize *bytes_written,
GError *
err);
// Omitted rest of struct
};

Looks like a separate regression. The next step will be to come up with C code that reproduces the problem. With this snippet, I cannot reproduce it:

typedef enum {a, b} GIOStatus;
typedef enum {c, d} GError;
typedef struct {int a;} GIOChannel;
typedef char gchar;
typedef long gsize;
struct _GIOFuncs
{
  GIOStatus (*io_read)           (GIOChannel   *channel, 
                      gchar        *buf, 
                  gsize         count,
                  gsize        *bytes_read,
                  GError      **err);
  GIOStatus (*io_write)          (GIOChannel   *channel, 
                  const gchar  *buf, 
                  gsize         count,
                  gsize        *bytes_written,
                  GError      **err);
  // Omitted rest of struct
};

Next step is to find a small test case.

@andrewrk Here's as small as I could get it:

typedef struct _S S;
typedef int A;
typedef int B;

struct _S {
    A (*f)(B b);
};
Was this page helpful?
0 / 5 - 0 ratings