On 15-Apr-2004, Sven Panne <[EMAIL PROTECTED]> wrote:
> Fergus Henderson wrote:
> >I'd rather fix GHC so that interfacing with C macros works with ghc -fasm.
> >The equivalent works fine with the Mercury implementation ("mmc --target
> >asm"
> >gene
x27;t work!
As the C standard says:
|It is unspecified whether errno
|is a macro or an identifier declared with external linkage.
|If a macro definition is suppressed in order to access an
|actual object ... the behavior is undefined.
-
st by default.
I'd rather fix GHC so that interfacing with C macros works with ghc -fasm.
The equivalent works fine with the Mercury implementation ("mmc --target asm"
generates assembler for the Mercury code and C stubs for the FFI glue),
so it's clearly possible.
--
Fergus Henders
Haskell implementations to do
the same, even if this goes above and beyond the requirements standardized
in the Haskell FFI report.
--
Fergus Henderson| "I have always known that the pursuit
| of excellence is a lethal habit"
WWW:
quot;curses.h WINDOW" WINDOW
Then ghc could generate C code which uses "WINDOW *" rather than "void *",
and there would be no need to use parentheses or #undef to stop the macro
being invoked.
--
Fergus Henderson| "I have always
nal.
Cheers,
Fergus.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
_
kell code (c/c++).
I haven't tried it myself, but I think the answer is yes:
use the StablePtr type, which in C is the HsStablePtr typedef in "HsFFI.h".
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of Melbourne
6__,
i.e. whose wchar_t values are represented using the encoding specified
by ISO/IEC 10646?
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh
t; Should there perhaps be something like ...
>
> newForeignPtrWithUserData :: Ptr a -> Ptr b -> FunPtr (Ptr a -> Ptr b -> IO
> ()) -> IO (ForeignPtr a)
>
> ... where the second argument is a "userData" pointer that gets passed on
> to the finalizer?
IMHO yes!
--
Fergus Hende
} else {
*(CT *)&boxed_y = y;
}
return boxed_y;
}
Note that if compiling to C, such wrappers can be inlined.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of Mel
ed using the FFI, of course.
>
> But the FFI lists the types that may be returned by a foreign function,
> and T is not one of them.
Ah, I see.
> Are you suggesting we ought to be able to define new primitive types?
I think it is at least worth considering. See my other message about
h
t; with a builtin type is a different thing from what we're doing when we write:
>
> data T
>
> for some foreign type.
Sure. In fact, the "data Int" declaration need not even be physically
present; the implementation could just insert it in the Prelude automatically.
(
On 02-Jun-2003, Simon Marlow <[EMAIL PROTECTED]> wrote:
>
> I can't see how to acquire a value of type T that isn't bottom.
By calling a function defined using the FFI, of course.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pu
ypes, of course.
ghc has some complicated extension to the type system to deal with it,
which makes examples like the one above type errors if T is an unboxed type.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of Melbourne | of
On 02-Mar-2003, Wolfgang Thaller <[EMAIL PROTECTED]> wrote:
> >I have a C function:
> >
> >f_setCallback( void (funptr*) () );
That is a very bad design.
You should change the interface of your C function to
f_setCallback( void (funptr*) (void *), void * );
--
ted.
Sometimes standards should serve to advance the state of the art,
rather than merely standardizing on the flaws of existing
implementations, and I think this is one of those time.s
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of M
On 22-Jan-2003, Manuel M T Chakravarty <[EMAIL PROTECTED]> wrote:
> Finally, I am not sure whether we really want to allow that
> `reallocBytes' may be used on `alloca'ed memory, which the
> spec currently explicitly admits.
I agree, allowing this is a bad idea.
--
ups (e.g. for the Pseudoknot
benchmark, about a factor of two) from using pool-like memory management
rather than the Boehm collector.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal h
inishing the spec.
...
> In particular, I don't want to add a largely untested
> library.
...
> So, I propose to add Pool to the portable libraries package,
> but leave it out of the spec.
I agree. I support the inclusion of this proposal in FFI v1.1
or v2.0, but let's ship v1
ontains at least one
bug: the lines
pooledMallocArray0 pool size =
pooledMallocArray0 pool (size + 1)
^
|
|
oops!
should be
pooledMallocArray0 pool size =
required to be 8-byte aligned.
(This is something the C standard got wrong, IMHO.)
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh
t file format, name mangling,
the usage of registers and stack, the sizes and representations of the
basic types such as `int', struct padding, alignment, and so on.
If two C compilers both support the same C ABI, then it is possible
to mix code between them.
--
Fergus Henderson <[EMAIL PROTECT
e of representing the values of all the members of the
|enumeration.
| Footnote 108:
|An implementation may delay the choice of which integer
|type until all enumeration constants have been seen.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I h
ow should enum values be declared in the FFI?
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh
non-thread-safe".
So you want to disallow non-thread-safe Haskell implementations from
supporting the FFI?
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of Melbourne | of excellence is a letha
#x27; options), yes, but the part of the name which goes in between
the quotes or angle brackets in a #include line, no. They are part of
the API.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of Melbourne | of excellence is
tive machine
representation, but pointers of type `char *', `signed char *',
`unsigned char *', and `void *' need a different (and probably larger)
representation, because they can point to bytes within a word.
--
Fergus Henderson <[EM
argument passing convention, but known-prototype functions can use a
more efficient callee-pops convention. Some C compilers have taken
advantage of this.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
The University of Melbourne | of excellenc
ace qualification;
it's similar in some ways, but not quite the same.
The closest .NET equivalent would be assembly qualification, which is
written as "[mylib]foo" in ILASM and "foo,mylib" in ASP+ web.config files.
So I suggest using the ILASM syntax, i.e.
&qu
the C calling convention specify a "package name" rather
> than a header file name. Thus
>
> foreign import ccall "wuggle::foo" foo :: Int -> Int
>
> rather than wuggle.h
The main problem with that is that in general there will not be
any relationshi
ted/,
s/the language/the source language/
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
On 01-Jun-2001, Manuel M. T. Chakravarty <[EMAIL PROTECTED]> wrote:
> Fergus Henderson <[EMAIL PROTECTED]> wrote,
>
> > I would be fine to say that some other name, e.g. `c', means that.
> > But `ccall' already has an existing meaning, and it would be
>
On 31-May-2001, Manuel M. T. Chakravarty <[EMAIL PROTECTED]> wrote:
> Fergus Henderson <[EMAIL PROTECTED]> wrote,
> > Making the semantics of a particular construct implementation-dependent is
> > a good thing if the semantics that you want are implementation-dependent
he identical contained sequence (including >
|characters, if any) from the original directive.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://ww
On 29-May-2001, Manuel M. T. Chakravarty <[EMAIL PROTECTED]> wrote:
> Sven Panne <[EMAIL PROTECTED]> wrote,
>
> > Fergus Henderson wrote:
> >
> > > The calling convention should not necessarily default to 'ccall'.
> > > That would no
fi?
This is useful for tools that parse Haskell source code but which
are not compilers -- e.g. documentation generators.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
| of excellence is a lethal habit
7;
The calling convention should not necessarily default to 'ccall'.
That would not be appropriate for all implementations.
Instead, I think the default calling convention should be
implementation-dependent.
Also, implementations should be allowed to provide calling conventions
not on
TECTED]).
PROGRAMME COMMITTEE
Nick Benton (chair) Microsoft Research
Fergus Henderson University of Melbourne
Andrew Kennedy (organiser) Microsoft Research
Greg Morrisett Cornell University
Martin Odersky Ecole Polytechnique Federale de La
a to document their semantics.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
___
will want to support it.
I also think that it would be nice to standardize on the syntax used
to tell the compiler which include files are needed.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
| of excellence i
d it either!
The Mercury compiler has an attribute `will_not_call_mercury',
which I believe is analagous to ghc's `unsafe' attribute.
So ghc is not entirely alone here. (Furthermore, AFAIK these
two instances evolved independently, rather than either being
influenced by the other,
foreign import ccall "gtk:foo" foo :: Int -> IO Int
[...]
> * The "gtk:foo" is a string in language-specific format
>that uniquely specifies the thing being called.
[...]
> * The "gtk:" part is a concession to (b). It specifies a C package
> from which
>
rt before the user's #includes.
Another (probably better) alternative is to pass the `-ffixed-'
option to gcc to reserve the registers.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
| of excellence is a lethal
** __KERNEL__ to get sigcontext_struct from .
*/
#define __KERNEL__
#include
#undef __KERNEL__
/*
** Some versions of Linux define it in , others define it in
** . We try both.
*/
#ifdef HAVE_ASM_SIGCONTEXT
#include
#endif
#else
#include
#endif
--
Fergus Henderson
out it being implemented in Haskell
>
> 2) Have any desire to spend half a day installing lots of Haskell-related tools
>(greencard, c2hs, happy, etc.) on their machine before they can try out my
> tool.
Why not just distribute binaries for the platforms of interest?
Or runhugs scr
ough I'm not sure which architectures
> > this applies to.
You don't need to know. It's clearly reasonable to have architectures
on which pointers to code and pointers to data have different sizes.
That's all you need to know.
> AFAIK IA64. And MS-DOS.
You're wron
ad for performance.
On some systems that I've used (some version of DEC Ultrix, if I recall
correctly), you had to be super-user to flush the instruction cache.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
|
On 03-Jan-2001, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> wrote:
> Wed, 3 Jan 2001 21:44:03 +1100, Fergus Henderson <[EMAIL PROTECTED]> pisze:
>
> > Personally I'd rather have a single well-designed convenient foreign
> > language interface as
mpile via C.
But I want inline C to be fast in the one that compiles via C,
and I want inline Java to be fast in the Java back-end.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
| of excellence is a lethal habit"
ement the other FFI constructs
that don't involve inline foreign code in such a way that
if you don't use inline foreign code, you don't need a foreign
language compiler.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pu
On 03-Jan-2001, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> wrote:
> Wed, 3 Jan 2001 21:12:54 +1100, Fergus Henderson <[EMAIL PROTECTED]> pisze:
>
> > Well, if they are left, then at very least they should be
> > very clearly documented as being non
On 02-Jan-2001, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> wrote:
> Tue, 2 Jan 2001 22:28:02 +1100, Fergus Henderson <[EMAIL PROTECTED]> pisze:
>
> > Doing it in a separate tool will lose efficiency in some important
> > cases. If the compile
inter
> or a real data pointer to a function, together with an enumeration
> value indicating which one is this. Ugly, but that's life.
>
> Another example is dlopen.
I think you mean dlsym().
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known t
version depending on which target
language you are compiling to.
For those who are not fans of polyglot-style obfuscated programs,
(a) generally only works in the case of languages which are
syntactically quite similar, such as C and C++, where you can easily
write code that is in the intersect
tee that a data pointer will
fit in a function pointer or vice versa.
If you want something that could be either a data pointer or
a function pointer, you need to use a union:
union {
void *data;
void (*func)(void);
}
--
Fergus Henderson <[EMAIL PROT
inline C code directly in the generated code, and thus get
inlining. But I think a separate tool would have to put the C code in
a separate C file, which would prevent inlining.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
function
pointers are the same size as data pointers, and so I'd be somewhat
surprised if they've really done that.)
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
| of excellence is a lethal habit&q
ead object, which gets copied
> in after every foreign call. Anyone have any bright ideas here?
Well, you could have a private errno in each Haskell thread object,
which gets copied in at every Haskell thread switch...
--
Fergus Henderson <[EMAIL PROTECTED]> |
the initial try, and if it
doesn't fit then switch to using malloc()/realloc().
At the end, you can check whether the final buffer pointer is equal to
the original fixed-size static or alloca()'ed buffer, and only free it
if it is not. Or you can keep a separ
possible to have the second kind from the level of the
>Haskell compiler at all (done in an sufficiently elegant way to
>think about it as a candidate proposal for the official FFI)?
I think so. I certainly consider the mechanism that Mercury
uses to be elegant enough to be the officia
e functions are called or where they live, as long as we have them!
>
> Admittedly the functions above are C-specific and should probably go
> into a C-specific library on top of Foreign. CForeign anyone?
These are not C-specific, they are POSIX-specific.
As evidence that they are not
e docs.
In GNU C:
extern int foo __attribute__((weak));
int main() {
printf("%p", &foo);
}
This is documented in the gcc info pages.
In GNU as:
.weak foo
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known tha
can call existentially typed Mercury procedures to obtain dictionaries,
and can then pass those dictionaries to polymorphic Mercury procedures.
On 31-Jul-2000, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> wrote:
> How would you use such function in C? C does not support polymorph
63 matches
Mail list logo