Skip to content

Commit

Permalink
Don't abuse double-underscore prefix.
Browse files Browse the repository at this point in the history
To avoid conflicts, as C++ standard reserved them for system libraries.
  • Loading branch information
jrfonseca committed Apr 19, 2012
1 parent e32a797 commit 632a78d
Show file tree
Hide file tree
Showing 30 changed files with 805 additions and 802 deletions.
9 changes: 6 additions & 3 deletions DEVELOPMENT.markdown
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Coding Style
============

XXX: These are mostly guidelines for new code, as some of existing hasn't been
updated to these conventions yet.
These are guidelines for new code. Some of existing hasn't been updated to
these conventions yet.

Whitespace (all languages):

Expand All @@ -24,6 +24,9 @@ Naming convention:

* `UPPER_CASE` for #defines

* single underscore prefix for variables/functions in automatically generated
code

C++:

* enclose single statement `if` clauses in { }, specially for automatically
Expand All @@ -35,7 +38,7 @@ C++:

CMake:

* `lower_case`
* `lower_case` commands

* space between ( and precedent name

Expand Down
26 changes: 13 additions & 13 deletions dispatch/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@


def function_pointer_type(function):
return '__PFN' + function.name.upper()
return 'PFN_' + function.name.upper()


def function_pointer_value(function):
return '__' + function.name + '_ptr'
return '_' + function.name + '_ptr'


class Dispatcher:
Expand All @@ -51,10 +51,10 @@ def header(self):
# Must be implemented by derived classes, which should define, declare,
# or implement something like:
#
# typedef void (*__PROC)(void);
# typedef void (*_PROC)(void);
#
# static __PROC __getPublicProcAddress(const char *name);
# static __PROC __getPrivateProcAddress(const char *name);
# static _PROC _getPublicProcAddress(const char *name);
# static _PROC _getPrivateProcAddress(const char *name);
#
raise NotImplementedError

Expand All @@ -67,7 +67,7 @@ def dispatch_api(self, api):
# functions
print '#ifdef RETRACE'
for function in api.functions:
print '#define %s __%s' % (function.name, function.name)
print '#define %s _%s' % (function.name, function.name)
print '#endif /* RETRACE */'
print

Expand All @@ -77,8 +77,8 @@ def invokeFunction(self, function):
print 'typedef ' + function.prototype('* %s' % ptype) + ';'
print 'static %s %s = NULL;' % (ptype, pvalue)
print
print 'static inline ' + function.prototype('__' + function.name) + ' {'
print ' const char *__name = "%s";' % function.name
print 'static inline ' + function.prototype('_' + function.name) + ' {'
print ' const char *_name = "%s";' % function.name
if function.type is stdapi.Void:
ret = ''
else:
Expand All @@ -95,27 +95,27 @@ def get_true_pointer(self, function):
ptype = function_pointer_type(function)
pvalue = function_pointer_value(function)
if self.isFunctionPublic(function):
get_proc_address = '__getPublicProcAddress'
get_proc_address = '_getPublicProcAddress'
else:
get_proc_address = '__getPrivateProcAddress'
get_proc_address = '_getPrivateProcAddress'
print ' if (!%s) {' % (pvalue,)
print ' %s = (%s)%s(__name);' % (pvalue, ptype, get_proc_address)
print ' %s = (%s)%s(_name);' % (pvalue, ptype, get_proc_address)
print ' if (!%s) {' % (pvalue,)
self.failFunction(function)
print ' }'
print ' }'

def failFunction(self, function):
if function.type is stdapi.Void or function.fail is not None:
print r' os::log("warning: ignoring call to unavailable function %s\n", __name);'
print r' os::log("warning: ignoring call to unavailable function %s\n", _name);'
if function.type is stdapi.Void:
assert function.fail is None
print ' return;'
else:
assert function.fail is not None
print ' return %s;' % function.fail
else:
print r' os::log("error: unavailable function %s\n", __name);'
print r' os::log("error: unavailable function %s\n", _name);'
print r' os::abort();'


2 changes: 1 addition & 1 deletion dispatch/eglimports.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ typedef int32_t GLclampx;
// avoid conflict with GL_EXT_framebuffer_multisample
#define GL_EXT_multisampled_render_to_texture

#undef __glext_h_
#undef _glext_h_
#include "GLES/glext.h"


Expand Down
8 changes: 4 additions & 4 deletions dispatch/glproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,13 @@ class GlDispatcher(Dispatcher):
def header(self):
print '''
#if defined(_WIN32)
extern HINSTANCE __libGlHandle;
extern HINSTANCE _libGlHandle;
#else
extern void * __libGlHandle;
extern void * _libGlHandle;
#endif
void * __getPublicProcAddress(const char *procName);
void * __getPrivateProcAddress(const char *procName);
void * _getPublicProcAddress(const char *procName);
void * _getPrivateProcAddress(const char *procName);
'''

def isFunctionPublic(self, function):
Expand Down
12 changes: 6 additions & 6 deletions dispatch/glproc_egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
* XXX: Not really used yet.
*/
#if defined(_WIN32)
HINSTANCE __libGlHandle = NULL;
HINSTANCE _libGlHandle = NULL;
#else
void *__libGlHandle = NULL;
void *_libGlHandle = NULL;
#endif


Expand Down Expand Up @@ -71,7 +71,7 @@ void *__libGlHandle = NULL;
* for quering via dlsym(RTLD_NEXT, ...).
*/
void *
__getPublicProcAddress(const char *procName)
_getPublicProcAddress(const char *procName)
{
#if defined(ANDROID)
/*
Expand Down Expand Up @@ -135,14 +135,14 @@ __getPublicProcAddress(const char *procName)
* eglGetProcAddress to mitigate that.
*/
void *
__getPrivateProcAddress(const char *procName)
_getPrivateProcAddress(const char *procName)
{
void *proc;
proc = __getPublicProcAddress(procName);
proc = _getPublicProcAddress(procName);
if (!proc &&
((procName[0] == 'e' && procName[1] == 'g' && procName[2] == 'l') ||
(procName[0] == 'g' && procName[1] == 'l'))) {
proc = (void *) __eglGetProcAddress(procName);
proc = (void *) _eglGetProcAddress(procName);
}

return proc;
Expand Down
58 changes: 29 additions & 29 deletions dispatch/glproc_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@
* Handle to the true OpenGL library.
*/
#if defined(_WIN32)
HINSTANCE __libGlHandle = NULL;
HINSTANCE _libGlHandle = NULL;
#else
void *__libGlHandle = NULL;
void *_libGlHandle = NULL;
#endif



#if defined(_WIN32)

void *
__getPublicProcAddress(const char *procName)
_getPublicProcAddress(const char *procName)
{
if (!__libGlHandle) {
if (!_libGlHandle) {
char szDll[MAX_PATH] = {0};

if (!GetSystemDirectoryA(szDll, MAX_PATH)) {
Expand All @@ -58,20 +58,20 @@ __getPublicProcAddress(const char *procName)

strcat(szDll, "\\\\opengl32.dll");

__libGlHandle = LoadLibraryA(szDll);
if (!__libGlHandle) {
_libGlHandle = LoadLibraryA(szDll);
if (!_libGlHandle) {
os::log("apitrace: error: couldn't load %s\n", szDll);
return NULL;
}
}

return (void *)GetProcAddress(__libGlHandle, procName);
return (void *)GetProcAddress(_libGlHandle, procName);
}


void *
__getPrivateProcAddress(const char *procName) {
return (void *)__wglGetProcAddress(procName);
_getPrivateProcAddress(const char *procName) {
return (void *)_wglGetProcAddress(procName);
}


Expand All @@ -87,11 +87,11 @@ static const char *libgl_filename = "/System/Library/Frameworks/OpenGL.framework
/*
* Lookup a libGL symbol
*/
void * __libgl_sym(const char *symbol)
void * _libgl_sym(const char *symbol)
{
void *result;

if (!__libGlHandle) {
if (!_libGlHandle) {
/*
* Unfortunately we can't just dlopen the true dynamic library because
* DYLD_LIBRARY_PATH/DYLD_FRAMEWORK_PATH take precedence, even for
Expand All @@ -103,19 +103,19 @@ void * __libgl_sym(const char *symbol)

if (mktemp(temp_filename) != NULL) {
if (symlink(libgl_filename, temp_filename) == 0) {
__libGlHandle = dlopen(temp_filename, RTLD_LOCAL | RTLD_NOW | RTLD_FIRST);
_libGlHandle = dlopen(temp_filename, RTLD_LOCAL | RTLD_NOW | RTLD_FIRST);
remove(temp_filename);
}
}

if (!__libGlHandle) {
if (!_libGlHandle) {
os::log("apitrace: error: couldn't load %s\n", libgl_filename);
os::abort();
return NULL;
}
}

result = dlsym(__libGlHandle, symbol);
result = dlsym(_libGlHandle, symbol);

#if 0
if (result && result == dlsym(RTLD_SELF, symbol)) {
Expand All @@ -130,15 +130,15 @@ void * __libgl_sym(const char *symbol)


void *
__getPublicProcAddress(const char *procName)
_getPublicProcAddress(const char *procName)
{
return __libgl_sym(procName);
return _libgl_sym(procName);
}

void *
__getPrivateProcAddress(const char *procName)
_getPrivateProcAddress(const char *procName)
{
return __libgl_sym(procName);
return _libgl_sym(procName);
}


Expand All @@ -149,7 +149,7 @@ __getPrivateProcAddress(const char *procName)
* Invoke the true dlopen() function.
*/
static void *
__dlopen(const char *filename, int flag)
_dlopen(const char *filename, int flag)
{
typedef void * (*PFNDLOPEN)(const char *, int);
static PFNDLOPEN dlopen_ptr = NULL;
Expand All @@ -169,11 +169,11 @@ __dlopen(const char *filename, int flag)
/*
* Lookup a libGL symbol
*/
void * __libgl_sym(const char *symbol)
void * _libgl_sym(const char *symbol)
{
void *result;

if (!__libGlHandle) {
if (!_libGlHandle) {
/*
* The app doesn't directly link against libGL.so, nor does it directly
* dlopen it. So we have to load it ourselves.
Expand All @@ -188,7 +188,7 @@ void * __libgl_sym(const char *symbol)

result = dlsym(RTLD_NEXT, symbol);
if (result) {
__libGlHandle = RTLD_NEXT;
_libGlHandle = RTLD_NEXT;
return result;
}

Expand All @@ -202,27 +202,27 @@ void * __libgl_sym(const char *symbol)
* exposes symbols to it.
*/

__libGlHandle = __dlopen(libgl_filename, RTLD_GLOBAL | RTLD_LAZY);
if (!__libGlHandle) {
_libGlHandle = _dlopen(libgl_filename, RTLD_GLOBAL | RTLD_LAZY);
if (!_libGlHandle) {
os::log("apitrace: error: couldn't find libGL.so\n");
return NULL;
}
}

return dlsym(__libGlHandle, symbol);
return dlsym(_libGlHandle, symbol);
}


void *
__getPublicProcAddress(const char *procName)
_getPublicProcAddress(const char *procName)
{
return __libgl_sym(procName);
return _libgl_sym(procName);
}

void *
__getPrivateProcAddress(const char *procName)
_getPrivateProcAddress(const char *procName)
{
return (void *)__glXGetProcAddressARB((const GLubyte *)procName);
return (void *)_glXGetProcAddressARB((const GLubyte *)procName);
}


Expand Down
Loading

0 comments on commit 632a78d

Please sign in to comment.