www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - C compatibility module for phobos.

reply Gor Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
Hello, my dear, beloved D community.

I've been reading literally all discussions on D.puremagic.com for about a
month now and I'm deeply concerned with my favorite language and it's
reference compiler.

So, for starters, i decided to add a very useful (in my opinion) module to
phobos: etc.c.compat.

Here's the pull request:
https://github.com/D-Programming-Language/phobos/pull/265

This module is supposed to help people develop bindings for C libraries, by
providing information language-specific information, depending on certain
compiler, processor architecture, operating system, etc.

Currently there are only aliases for C built-in types, which are static
if-ed to have the correct size for the respective C compilers.

It's well-documented and waits to be enhanced with more accurate
compile-time branching and additional useful information to make binding C
code even easier.

If we get a good enough C compatibility module, we'll be able to rapidly
bind all major and frequently-used libraries and include them in phobos.

This will also do a great job of promoting D as a good language to adopt for
serious projects, because it's standard library will be very rich and common
usage won't require the programmer to resort to anything besides phobos.

Any comments would be much appreciated.
Sep 21 2011
next sibling parent reply =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
On 21-09-2011 10:01, Gor Gyolchanyan wrote:
 Hello, my dear, beloved D community.

 I've been reading literally all discussions on D.puremagic.com
 <http://D.puremagic.com> for about a month now and I'm deeply concerned
 with my favorite language and it's reference compiler.

 So, for starters, i decided to add a very useful (in my opinion) module
 to phobos: etc.c.compat.

 Here's the pull request:
 https://github.com/D-Programming-Language/phobos/pull/265

 This module is supposed to help people develop bindings for C libraries,
 by providing information language-specific information, depending on
 certain compiler, processor architecture, operating system, etc.

 Currently there are only aliases for C built-in types, which are static
 if-ed to have the correct size for the respective C compilers.

 It's well-documented and waits to be enhanced with more accurate
 compile-time branching and additional useful information to make binding
 C code even easier.

 If we get a good enough C compatibility module, we'll be able to rapidly
 bind all major and frequently-used libraries and include them in phobos.

 This will also do a great job of promoting D as a good language to adopt
 for serious projects, because it's standard library will be very rich
 and common usage won't require the programmer to resort to anything
 besides phobos.

 Any comments would be much appreciated.
Hi, You should probably fix the enum member names to use camelCase (though in the case of 'x86_64', I think the underscore is acceptable). - Alex
Sep 21 2011
parent Gor F. Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
Will do! :-)
Right after i take a look at the existing core.stdc.config module, that i never
knew about before :-)
Sep 21 2011
prev sibling parent reply Jesse Phillips <jessekphillips+D gmail.com> writes:
Gor Gyolchanyan Wrote:

 Hello, my dear, beloved D community.
 
 I've been reading literally all discussions on D.puremagic.com for about a
 month now and I'm deeply concerned with my favorite language and it's
 reference compiler.
 
 So, for starters, i decided to add a very useful (in my opinion) module to
 phobos: etc.c.compat.
 
 Here's the pull request:
 https://github.com/D-Programming-Language/phobos/pull/265
 
 This module is supposed to help people develop bindings for C libraries, by
 providing information language-specific information, depending on certain
 compiler, processor architecture, operating system, etc.
 
 Currently there are only aliases for C built-in types, which are static
 if-ed to have the correct size for the respective C compilers.
Isn't this almost exactly like stdint https://github.com/D-Programming-Language/druntime/blob/master/src/core/stdc/stdint.d except that it isn't based on target architecture and can specify specific compilers? Also how much do sizes differ between compilers?
Sep 21 2011
parent reply Gor F. Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
I didn't know about core.stdc package because it doesn't show u on dpl.org.

The difference is, that some compilers make long 64 bit for 64-bit systems, and
some leave the long 32-bit no matter what.
Sep 21 2011
next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 9/21/11, Gor Gyolchanyan <gor.f.gyolchanyan gmail.com> wrote:
 If we get a good enough C compatibility module, we'll be able to rapidly
 bind all major and frequently-used libraries and include them in phobos.
Type compatibility might be just the tip of the iceberg for wrapping a C library. For example you might also have to worry about memory management, and then there are libraries that use special introspection mechanisms to generate language bindings, e.g. GObject.
Sep 21 2011
parent Gor F. Gyolchanyan <gor.f.gyolchanyan gmail.com> writes:
For that, there are a number of GC-related bugs to be fixed. If GC gets fully
stable and predictable, C-managed memory could be integrated in concert with GC
(like, making the GC call C-AI's custom free function on collection cycle).
Sep 21 2011
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2011-09-21 21:02, Gor F. Gyolchanyan wrote:
 I didn't know about core.stdc package because it doesn't show u on dpl.org.

 The difference is, that some compilers make long 64 bit for 64-bit systems, and
 some leave the long 32-bit no matter what.
core.stdc.config handles that. -- /Jacob Carlborg
Sep 22 2011