From: Mikko Rasa Date: Tue, 22 Sep 2009 07:43:42 +0000 (+0000) Subject: Fix GLintptr/GLsizeiptr print formats X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=be68706254c62406d4924fffa7f43d2b1c17f52e;p=gldbg.git Fix GLintptr/GLsizeiptr print formats Unify getwrite and getread to keep the write and read sides in sync Some more special cases for array sizes Wrap glXGetProcAddress to catch dynamically acquired functions Transmit null terminator with strings --- diff --git a/genwrap.py b/genwrap.py index 7f87c7f..b940036 100755 --- a/genwrap.py +++ b/genwrap.py @@ -39,7 +39,7 @@ for line in open("gl.spec"): s = parts[5][1:-1] if s.isdigit(): p[3] = int(s) - elif s=="": + elif s=="" or (len(parts)>=7 and parts[6]=="retained"): p[3] = "~" else: p[3] = s @@ -72,10 +72,10 @@ fmtmap = {"GLenum":"%#x", "GLchar *":"%s", "GLcharARB *":"%s", "GLvoid*":"%p", - "GLsizeiptr":"%p", - "GLsizeiptrARB":"%p", - "GLintptr":"%p", - "GLintptrARB":"%p", + "GLsizeiptr":"%d", + "GLsizeiptrARB":"%d", + "GLintptr":"%d", + "GLintptrARB":"%d", "GLhandleARB":"%i", "GLhalfNV":"%#x", "GLuint64EXT":"%lld"} @@ -161,7 +161,7 @@ def getfmt(param): else: return (fmtmap[ptype], param[0]) -def getwrite(func, param): +def getrwinfo(func, param): ptype = basetype(param[1], param[3]!=0) if param[3]: if type(param[3])==int: @@ -170,28 +170,24 @@ def getwrite(func, param): size = compsize(func, param[3][9:-1], ptype) if not size: print "Compsize '%s' for function '%s' failed"%(param[3][9:-1], func[0]) - return ("pointer", None) - elif param[3]=="~" and (param[2]=="charARB" or param[2]=="Char"): - return ("string", None) + return ("pointer", None, "void **") + elif param[3]=="~": + if param[2]=="charARB" or param[2]=="Char": + return ("string", None, "const unsigned char **") + else: + return ("pointer", None, "void **") else: s = getparam(func, param[3].split('*')[0]) - if s and (s[2]=="SizeI" or s[2].endswith("Int32")) and s[3]==0: + if s and (s[2]=="SizeI" or s[2].endswith("Int32") or s[2].startswith("BufferSize")) and s[3]==0: size = "%s*sizeof(%s)"%(param[3], ptype) if func[0].startswith("Uniform") and func[0][8]!='u' and func[0][7].isdigit(): size += "*%s"%func[0][7] else: print "Could not determine size for array parameter '%s[%s]' of function '%s'"%(param[0], param[3], func[0]) - return ("pointer", None) - return ("data", size) - else: - return (iomap[ptype], None) - -def getread(func, param): - ptype = basetype(param[1], param[3]!=0) - if param[3]: - return ("data", "(const void **)") + return ("pointer", None, "void **") + return ("data", size, "const void **") else: - return (iomap[ptype], "") + return (iomap[ptype], None, None) # Write out function enums @@ -207,7 +203,7 @@ out.close() # Write out wrapper functions for transmitting side -out = open(os.path.join(outdir, "glwrap.funcs"), "w"); +out = open(os.path.join(outdir, "glwrap.funcs"), "w") for f in funcs: out.write("%s GLAPIENTRY gl%s(%s)\n{\n"%(f[1], f[0], ", ".join("%s %s"%(p[1], p[0]) for p in f[2]))) @@ -225,7 +221,7 @@ for f in funcs: if f[1]!="void": out.write("\twrite_%s(ret);\n"%iomap[f[1]]) for p in f[2]: - (t, s) = getwrite(f, p) + (t, s, c) = getrwinfo(f, p) out.write("\twrite_%s(%s"%(t, p[0])) if s: out.write(", %s"%s) @@ -263,7 +259,11 @@ for f in funcs: if f[1]!="void": out.write("\tpos += read_%s(&ret, data+pos);\n"%iomap[f[1]]) for p in f[2]: - (t, c) = getread(f, p) + (t, s, c) = getrwinfo(f, p) + if c: + c="(%s)"%c + else: + c="" out.write("\tpos += read_%s(%s&arg_%s, data+pos);\n"%(t, c, p[0])) out.write("\tif(dec->%s)\n"%f[0]) out.write("\t\tdec->%s(dec->user_data"%f[0]) diff --git a/source/glwrap.c b/source/glwrap.c index 38f5e27..59bf1fb 100644 --- a/source/glwrap.c +++ b/source/glwrap.c @@ -116,7 +116,7 @@ static inline void write_data(const void *data, unsigned size) static inline void write_string(const unsigned char *s) { - write_data(s, strlen(s)); + write_data(s, strlen(s)+1); } static inline void begin_packet(int func) @@ -237,4 +237,12 @@ static inline int mapsize(GLenum target) return 1; } +void (*glXGetProcAddress(const GLubyte *procname))(void) +{ + void *handle = dlopen(NULL, RTLD_LAZY); + return dlsym(handle, (const char *)procname); +} + +void (*glXGetProcAddressARB(const GLubyte *))(void) __attribute__((alias("glXGetProcAddress"))); + #include "glwrap.funcs"