dstep icon indicating copy to clipboard operation
dstep copied to clipboard

Some missing imports and missing ssize_t alias

Open Timoses opened this issue 7 years ago • 8 comments

Dstepping this file: https://github.com/Timoses/libneo4j-client/blob/master/C/neo4j-client.h created (minus first line): https://github.com/Timoses/libneo4j-client/commit/29e349d923c24a2249f46750c4cc7d91ab8b7b3b#diff-3e1f79279fabc7d6472b0156d406bcde

These imports and aliases are missing to be able to compile: https://github.com/Timoses/libneo4j-client/commit/e87c777967ebf69e59f2215408a3696b31be6513#diff-3e1f79279fabc7d6472b0156d406bcde

import core.stdc.stdarg;
import core.stdc.stdio;
import core.sys.posix.sys.uio : iovec;

alias ssize_t = ptrdiff_t;

Timoses avatar Apr 28 '18 16:04 Timoses

That's a pretty big file. Are you able to produce a reduced test case?

jacob-carlborg avatar Apr 29 '18 07:04 jacob-carlborg

Okay, I was able to extract the following piece from the C header file and modified it to only contain the entries that yield the errors, test.h

#include <stdio.h>

struct test
{
    void (*log)(va_list ap);
};

void *some_func(FILE *stream);

struct test2
{
    ssize_t (*read)(void* buf);

    ssize_t (*readv)(const struct iovec *iov);
};

dstepping it (dstep test.h -o test.d) results in:

extern (C):

struct test
{
    void function (va_list ap) log;
}

void* some_func (FILE* stream);

struct test2
{
    ssize_t function (void* buf) read;

    ssize_t function (const(iovec)* iov) readv;
}

and a call to dmd -c test.d yields:

mytest.d(5): Error: undefined identifier va_list
mytest.d(8): Error: undefined identifier FILE
mytest.d(12): Error: undefined identifier ssize_t, did you mean alias size_t?
mytest.d(14): Error: undefined identifier ssize_t, did you mean alias size_t?
mytest.d(14): Error: undefined identifier iovec

Adding the imports and alias of ssize_t in the first post will lead to a successful compilation:

FILE => import core.stdc.stdio; va_list => import core.stdc.stdarg; iovec => import core.sys.posix.sys.uio : iovec; ssize_t => alias ssize_t = ptrdiff_t;

Timoses avatar Apr 29 '18 12:04 Timoses

I attempted to fix this: https://github.com/jacob-carlborg/dstep/pull/196 Unfortunately all FILE, va_list and ssize_tare defined in /usr/include/stdio.h so that dstep maps them to core.stdc.stdio;. And at D-side they are not defined in core.stdc.stdio. We would need a mapping between the symbols from standard library and the D module to solve this...

ciechowoj avatar May 08 '18 11:05 ciechowoj

@ciechowoj did you work on something that allowed to identify if a symbol was included through another file? Or is that not related?

jacob-carlborg avatar May 08 '18 13:05 jacob-carlborg

Yes, I tried to use this mechanism in the PR. But it doesn't work as the symbols aren't defined in the headers they should be defined. E.g. va_list should be defined in stdarg.h, but look into stdio.h:

[...]
#if defined __USE_XOPEN || defined __USE_XOPEN2K8
# ifdef __GNUC__
#  ifndef _VA_LIST_DEFINED
typedef _G_va_list va_list;
#   define _VA_LIST_DEFINED
#  endif
# else
#  include <stdarg.h>
# endif
#endif
[...]

and

__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ These macros are defined by all GNU compilers that use the C preprocessor: C, C++, Objective-C and Fortran.

Bummer : (

ciechowoj avatar May 08 '18 14:05 ciechowoj

Hmm :(, ok.

jacob-carlborg avatar May 08 '18 14:05 jacob-carlborg

Also bitten by missing ssize_t today. Is truly a bug on the Dlang core library side, but affects dstep

jblachly avatar Aug 14 '20 12:08 jblachly

I can add some hard coded mappings for these types. DStep already contains a list with mapping of types to imports.

jacob-carlborg avatar Aug 14 '20 13:08 jacob-carlborg