FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Restricted names

 
Post new topic   Reply to topic     Forum Index -> Ares
View previous topic :: View next topic  
Author Message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Fri Oct 21, 2005 12:14 pm    Post subject: Restricted names Reply with quote

With the ability to declare things private at the module level I was hoping this could be avoided, but it recently occurred to me that there still may be problems with extern (C) callback functions. For example, std.exception includes these functions for internal use:
Code:
extern (C) void onAssert( char[] file, uint line );
extern (C) void onOutOfMemory();
extern (C) void onArrayBoundsError( char[] file, size_t line );
extern (C) void onSwitchError( char[] file, size_t line );
extern (C) void onInvalidUtfError( char[] msg, size_t idx );

Making these functions private (which they will be in the next release) doesn't help because the functions are still callable so long as the user declares them. And while I think it's unlikely that a user would create a function with one of these signatures for his own use, it's still not a chance I'd like take. How about reserving symbol names with a leading underscore for library use? Thus, the above functions would become:
Code:
extern (C) void _onAssert( char[] file, uint line );
extern (C) void _onOutOfMemory();
extern (C) void _onArrayBoundsError( char[] file, size_t line );
extern (C) void _onSwitchError( char[] file, size_t line );
extern (C) void _onInvalidUtfError( char[] msg, size_t idx );

The garbage collector declares a ton of callback functions for various things as well, so this list will grow in the not too distant future.
Back to top
View user's profile Send private message
pragma



Joined: 28 May 2004
Posts: 607
Location: Washington, DC

PostPosted: Fri Oct 21, 2005 12:25 pm    Post subject: Reply with quote

As long as its the low-level extern(C) stuff, that's okay by me. Better avoid those namespace collisions now rather than later.
_________________
-- !Eric.t.Anderton at gmail
Back to top
View user's profile Send private message Yahoo Messenger
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Fri Oct 21, 2005 2:53 pm    Post subject: Reply with quote

I agree ~ reserving part of the namespace for the library is a good idea. You could use the prefix "ares" instead of an underscore, but the latter is traditional along with the __ variety (used in C libraries).

- Kris
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Fri Oct 21, 2005 4:04 pm    Post subject: Reply with quote

The only restriction is that external symbol names can't collide with anything that may be linked in from a C library, so leading double underscore and underscore followed by a capital letter are definately out. DMD uses "_d_" for callbacks in Phobos, so perhaps Ares should follow suit. This is a strict enough convention that it's not likely to conflict with anything even if someone tries linking a D library into a C program. Another alternative would be to use a UniversalAlpha character as the prefix, though this might be a bit difficult to read.
Back to top
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Sat Oct 22, 2005 3:06 pm    Post subject: Reply with quote

See the general forum. I've settled on "_D_" for now, pending any criticism from Walter. So all extern (C) functions in Ares that are not intended to be user callable will be private and have this prefix.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Ares All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group