about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--main.c34
1 files changed, 7 insertions, 27 deletions
diff --git a/main.c b/main.c
index a51ba88..6f60c9b 100644
--- a/main.c
+++ b/main.c
@@ -62,25 +62,6 @@ scan()
 		XFree(wins);
 }
 
-static int
-winprop(Window w, Atom a, Atom t, long l, unsigned char **prop)
-{
-	int status, format;
-	unsigned long res, extra;
-	Atom real;
-
-	status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
-			&res, &extra, prop);
-
-	if(status != Success || *prop == 0) {
-		return 0;
-	}
-	if(res == 0) {
-		free((void *) *prop);
-	}
-	return res;
-}
-
 /*
  * Startup Error handler to check if another window manager
  * is already running.
@@ -111,21 +92,20 @@ Window root, barwin;
 int
 getproto(Window w)
 {
-	int protos = 0;
+	int status, format, protos = 0;
 	int i;
-	long res;
-	Atom *protocols;
+	unsigned long extra, res;
+	Atom *protocols, real;
 
-	res = winprop(w, wmatom[WMProtocols], XA_ATOM, 20L,
-			((unsigned char **)&protocols));
-	if(res <= 0) {
+	status = XGetWindowProperty(dpy, w, wmatom[WMProtocols], 0L, 20L,
+			False, XA_ATOM, &real, &format, &res, &extra, (unsigned char **)&protocols);
+	if(status != Success || protocols == 0)
 		return protos;
-	}
 	for(i = 0; i < res; i++) {
 		if(protocols[i] == wmatom[WMDelete])
 			protos |= PROTODELWIN;
 	}
-	free((char *) protocols);
+	free(protocols);
 	return protos;
 }
 
ht .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#
#
#           The Nimrod Compiler
#        (c) Copyright 2012 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## Thread var support for crappy architectures that lack native support for 
## thread local storage. (**Thank you Mac OS X!**)

# included from cgen.nim

proc emulatedThreadVars(): bool =
  result = {optThreads, optTlsEmulation} <= gGlobalOptions

proc accessThreadLocalVar(p: BProc, s: PSym) =
  if emulatedThreadVars() and not p.ThreadVarAccessed:
    p.threadVarAccessed = true
    p.module.usesThreadVars = true
    appf(p.procSec(cpsLocals), "\tNimThreadVars* NimTV;$n")
    app(p.procSec(cpsInit),
      ropecg(p.module, "\tNimTV = (NimThreadVars*) #GetThreadLocalVars();$n"))
    
var
  nimtv: PRope                 # nimrod thread vars; the struct body
  nimtvDeps: seq[PType] = @[]  # type deps: every module needs whole struct
  nimtvDeclared = initIntSet() # so that every var/field exists only once
                               # in the struct

# 'nimtv' is incredibly hard to modularize! Best effort is to store all thread
# vars in a ROD section and with their type deps and load them
# unconditionally...

# nimtvDeps is VERY hard to cache because it's not a list of IDs nor can it be
# made to be one.

proc declareThreadVar(m: BModule, s: PSym, isExtern: bool) =
  if emulatedThreadVars():
    # we gather all thread locals var into a struct; we need to allocate
    # storage for that somehow, can't use the thread local storage
    # allocator for it :-(
    if not containsOrIncl(nimtvDeclared, s.id):
      nimtvDeps.add(s.loc.t)
      appf(nimtv, "$1 $2;$n", [getTypeDesc(m, s.loc.t), s.loc.r])
  else:
    if isExtern: app(m.s[cfsVars], "extern ")
    if optThreads in gGlobalOptions: app(m.s[cfsVars], "NIM_THREADVAR ")
    app(m.s[cfsVars], getTypeDesc(m, s.loc.t))
    appf(m.s[cfsVars], " $1;$n", [s.loc.r])
  
proc generateThreadLocalStorage(m: BModule) =
  if nimtv != nil and (m.usesThreadVars or sfMainModule in m.module.flags):
    for t in items(nimtvDeps): discard getTypeDesc(m, t)
    appf(m.s[cfsSeqTypes], "typedef struct {$1} NimThreadVars;$n", [nimtv])

proc generateThreadVarsSize(m: BModule) =
  if nimtv != nil:
    app(m.s[cfsProcs], 
      "NI NimThreadVarsSize(){return (NI)sizeof(NimThreadVars);}" & tnl)