From 776d34f5349488d5b3104fd16c304bdc12f317a2 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Tue, 15 Jun 2021 07:23:17 -0400 Subject: [PATCH] dmd deprecation handling --- cgi.d | 2 +- characterencodings.d | 2 +- dbus.d | 2 +- dom.d | 60 ++++++++++++++++++++++---------------------- eventloop.d | 2 +- htmlwidget.d | 2 +- http.d | 2 +- png.d | 2 +- terminal.d | 49 ++++++++++++++++++++++++++++++++++-- web.d | 2 +- 10 files changed, 85 insertions(+), 40 deletions(-) diff --git a/cgi.d b/cgi.d index 80745b9..83df269 100644 --- a/cgi.d +++ b/cgi.d @@ -546,7 +546,7 @@ private struct stdin { in { assert(size, "size must be larger than 0"); } - body { + do { chunk_ = new ubyte[](size); popFront(); } diff --git a/characterencodings.d b/characterencodings.d index 1a2aac4..7fc56d5 100644 --- a/characterencodings.d +++ b/characterencodings.d @@ -185,7 +185,7 @@ string decodeImpl(in ubyte[] data, in dchar[] chars160to255, in dchar[] chars128 import std.utf; validate(ret); } -body { +do { string utf8; /// I'm sure this could be a lot more efficient, but whatever, it diff --git a/dbus.d b/dbus.d index ed396c3..d04d177 100644 --- a/dbus.d +++ b/dbus.d @@ -300,7 +300,7 @@ struct ObjectPath { assert(ObjectPath.isValid(_value) && ObjectPath.isValid(rhs._value)); } out (v) { assert(ObjectPath.isValid(v._value)); - } body { + } do { ObjectPath ret; if (_value == "/") diff --git a/dom.d b/dom.d index a0a193f..e669dc6 100644 --- a/dom.d +++ b/dom.d @@ -1209,7 +1209,7 @@ class Document : FileResource { final SomeElementType requireElementById(SomeElementType = Element)(string id, string file = __FILE__, size_t line = __LINE__) if( is(SomeElementType : Element)) out(ret) { assert(ret !is null); } - body { + do { return root.requireElementById!(SomeElementType)(id, file, line); } @@ -1217,7 +1217,7 @@ class Document : FileResource { final SomeElementType requireSelector(SomeElementType = Element)(string selector, string file = __FILE__, size_t line = __LINE__) if( is(SomeElementType : Element)) out(ret) { assert(ret !is null); } - body { + do { auto e = cast(SomeElementType) querySelector(selector); if(e is null) throw new ElementNotFoundException(SomeElementType.stringof, selector, this.root, file, line); @@ -1332,7 +1332,7 @@ class Document : FileResource { out(ret) { assert(ret !is null); } - body { + do { return cast(Form) createElement("form"); } @@ -1494,7 +1494,7 @@ class Element { out(ret) { assert(ret !is null); } - body { + do { auto e = cast(SomeElementType) getElementById(id); if(e is null) throw new ElementNotFoundException(SomeElementType.stringof, "id=" ~ id, this, file, line); @@ -1509,7 +1509,7 @@ class Element { out(ret) { assert(ret !is null); } - body { + do { auto e = cast(SomeElementType) querySelector(selector); if(e is null) throw new ElementNotFoundException(SomeElementType.stringof, selector, this, file, line); @@ -1621,7 +1621,7 @@ class Element { //assert(e.parentNode is this); //assert(e.parentDocument is this.parentDocument); } - body { + do { auto e = Element.make(tagName, childInfo, childInfo2); // FIXME (maybe): if the thing is self closed, we might want to go ahead and // return the parent. That will break existing code though. @@ -1641,7 +1641,7 @@ class Element { assert(e.parentNode is this.parentNode); assert(e.parentDocument is this.parentDocument); } - body { + do { auto e = Element.make(tagName, childInfo, childInfo2); return parentNode.insertAfter(this, e); } @@ -1684,7 +1684,7 @@ class Element { assert(ret.parentDocument is this.parentDocument); //assert(firstChild.parentDocument is this.parentDocument); } - body { + do { auto e = Element.make(tagName, "", info2); e.appendChild(firstChild); this.appendChild(e); @@ -1700,7 +1700,7 @@ class Element { assert((cast(DocumentFragment) this !is null) || (ret.parentNode is this), ret.toString);// e.parentNode ? e.parentNode.toString : "null"); assert(ret.parentDocument is this.parentDocument); } - body { + do { auto e = Element.make(tagName, "", info2); this.appendChild(e); e.innerHTML = innerHtml.source; @@ -1724,7 +1724,7 @@ class Element { assert(this.parentNode is newParent); //assert(isInArray(this, newParent.children)); } - body { + do { parentNode.removeChild(this); newParent.appendChild(this); } @@ -1748,7 +1748,7 @@ class Element { assert(parentNode is null); assert(children.length == 0); } - body { + do { foreach(c; children) c.parentNode = null; // remove the parent if(children.length) @@ -1768,7 +1768,7 @@ class Element { assert(this.parentNode is null); assert(var is this); } - body { + do { if(this.parentNode is null) return this; @@ -1792,7 +1792,7 @@ class Element { assert(this.parentNode is what); assert(ret is what); } - body { + do { this.replaceWith(what); what.appendChild(this); @@ -1804,7 +1804,7 @@ class Element { in { assert(this.parentNode !is null); } - body { + do { e.removeFromTree(); this.parentNode.replaceChild(this, e); return e; @@ -2450,7 +2450,7 @@ class Element { out(ret) { assert(ret is this); } - body { + do { if(parentDocument && parentDocument.loose) name = name.toLower(); if(name in attributes) @@ -2662,7 +2662,7 @@ class Element { out { assert(this.children.length == 0); } - body { + do { children = null; } @@ -2696,7 +2696,7 @@ class Element { assert(e.parentDocument is this.parentDocument); assert(e is ret); } - body { + do { if(e.parentNode !is null) e.parentNode.removeChild(e); @@ -2728,7 +2728,7 @@ class Element { assert(what.parentDocument is this.parentDocument); assert(ret is what); } - body { + do { foreach(i, e; children) { if(e is where) { if(auto frag = cast(DocumentFragment) what) @@ -2762,7 +2762,7 @@ class Element { assert(what.parentDocument is this.parentDocument); assert(ret is what); } - body { + do { foreach(i, e; children) { if(e is where) { if(auto frag = cast(DocumentFragment) what) @@ -2793,7 +2793,7 @@ class Element { assert(replacement.parentNode is this); assert(replacement.parentDocument is this.parentDocument); } - body { + do { foreach(ref c; this.children) if(c is child) { c.parentNode = null; @@ -2868,7 +2868,7 @@ class Element { //assert(isInArray(where, children)); //assert(isInArray(child, children)); } - body { + do { foreach(ref i, c; children) { if(c is where) { i++; @@ -2906,7 +2906,7 @@ class Element { assert(child.parentDocument is this.parentDocument); } } - body { + do { foreach(c; e.children) { c.parentNode = this; c.parentDocument = this.parentDocument; @@ -2941,7 +2941,7 @@ class Element { assert(e.parentDocument is this.parentDocument); assert(children[0] is e); } - body { + do { e.parentNode = this; e.parentDocument = this.parentDocument; if(auto frag = cast(DocumentFragment) e) @@ -3073,7 +3073,7 @@ class Element { assert(replace.parentDocument is this.parentDocument); assert(find.parentNode is null); } - body { + do { // FIXME //if(auto frag = cast(DocumentFragment) replace) //return this.replaceChild(frag, replace.children); @@ -3109,7 +3109,7 @@ class Element { debug foreach(r; replace) assert(r.parentNode is this); } - body { + do { if(replace.length == 0) { removeChild(find); return; @@ -3149,7 +3149,7 @@ class Element { assert(child !is c); assert(c.parentNode is null); } - body { + do { foreach(i, e; children) { if(e is c) { children = children[0..i] ~ children [i+1..$]; @@ -3168,7 +3168,7 @@ class Element { debug foreach(r; ret) assert(r.parentNode is null); } - body { + do { Element[] oldChildren = children.dup; foreach(c; oldChildren) c.parentNode = null; @@ -3243,7 +3243,7 @@ class Element { assert(ret.children.length == this.children.length, format("%d %d", ret.children.length, this.children.length)); assert(ret.tagName == this.tagName); } - body { + do { +/ { return this.cloneNode(true); @@ -3992,7 +3992,7 @@ enum NodeType { Text = 3 } T require(T = Element, string file = __FILE__, int line = __LINE__)(Element e) if(is(T : Element)) in {} out(ret) { assert(ret !is null); } -body { +do { auto ret = cast(T) e; if(ret is null) throw new ElementNotFoundException(T.stringof, "passed value", e, file, line); @@ -6596,7 +6596,7 @@ class Table : Element { ); } } - body { + do { if(tablePortition is null) tablePortition = this; diff --git a/eventloop.d b/eventloop.d index f771fc6..0f75407 100644 --- a/eventloop.d +++ b/eventloop.d @@ -277,7 +277,7 @@ public struct FileEventDispatcher { private WrappedListener getHandler(OsFileHandle fd, int idx) in { assert(idx >= 0 && idx < 3); } - body { + do { auto handlersPtr = fd in listeners; if(handlersPtr is null) return null; // we don't handle this function diff --git a/htmlwidget.d b/htmlwidget.d index c2d7e07..e0d15e5 100644 --- a/htmlwidget.d +++ b/htmlwidget.d @@ -39,7 +39,7 @@ struct CssSize { int getPixels(int oneEm, int oneHundredPercent) // out (ret) { assert(ret >= 0, to!string(ret) ~ " " ~ definition); } - body { + do { if(definition.length == 0 || definition == "none") return 0; diff --git a/http.d b/http.d index 3b33c69..3ece079 100644 --- a/http.d +++ b/http.d @@ -190,7 +190,7 @@ HttpResponse doHttpRequestOnHelpers(void delegate(string) write, char[] delegate in { assert(method == "POST" || method == "GET"); } -body { +do { auto u = UriParts(uri); diff --git a/png.d b/png.d index b91ff23..4e84b05 100644 --- a/png.d +++ b/png.d @@ -1678,7 +1678,7 @@ struct Chunk { in { assert(type.length == 4); } - body { + do { Chunk* c = new Chunk; c.size = cast(int) payload.length; c.type[] = (cast(ubyte[]) type)[]; diff --git a/terminal.d b/terminal.d index 3e2e403..7c70c9e 100644 --- a/terminal.d +++ b/terminal.d @@ -1879,8 +1879,16 @@ struct Terminal { while(writeBuffer.length) { written = unix.write(this.fdOut, writeBuffer.ptr, writeBuffer.length); - if(written < 0) + if(written < 0) { + import core.stdc.errno; + auto err = errno(); + if(err == EAGAIN || err == EWOULDBLOCK) { + import core.thread; + Thread.sleep(1.msecs); + continue; + } throw new Exception("write failed for some reason"); + } writeBuffer = writeBuffer[written .. $]; } } @@ -2397,6 +2405,19 @@ struct RealTimeConsoleInput { n.c_lflag &= ~f; tcsetattr(fdIn, TCSANOW, &n); + + // ensure these are still blocking after the resumption + import core.sys.posix.fcntl; + if(fdIn != -1) { + auto ctl = fcntl(fdIn, F_GETFL); + ctl &= ~O_NONBLOCK; + fcntl(fdIn, F_SETFL, ctl); + } + if(fdOut != -1) { + auto ctl = fcntl(fdOut, F_GETFL); + ctl &= ~O_NONBLOCK; + fcntl(fdOut, F_SETFL, ctl); + } } // copy paste from constructor, but not setting the destructor teardown since that's already done @@ -2430,6 +2451,7 @@ struct RealTimeConsoleInput { terminal.flush(); + // returning true will send a resize event as well, which does the rest of the catch up and redraw as necessary return true; } @@ -2561,6 +2583,22 @@ struct RealTimeConsoleInput { this.fdIn = terminal.fdIn; this.fdOut = terminal.fdOut; + // if a naughty program changes the mode on these to nonblocking + // and doesn't change them back, it can cause trouble to us here. + // so i explicitly set the blocking flag since EAGAIN is not as nice + // for my purposes (it isn't consistently handled well in here) + import core.sys.posix.fcntl; + { + auto ctl = fcntl(fdIn, F_GETFL); + ctl &= ~O_NONBLOCK; + fcntl(fdIn, F_SETFL, ctl); + } + { + auto ctl = fcntl(fdOut, F_GETFL); + ctl &= ~O_NONBLOCK; + fcntl(fdOut, F_SETFL, ctl); + } + if(fdIn != -1) { tcgetattr(fdIn, &old); auto n = old; @@ -2885,8 +2923,15 @@ struct RealTimeConsoleInput { return -1; else goto try_again; + } else if(errno == EAGAIN || errno == EWOULDBLOCK) { + // I turn off O_NONBLOCK explicitly in setup, but + // still just in case, let's keep this working too + import core.thread; + Thread.sleep(1.msecs); + goto try_again; } else { - throw new Exception("read failed"); + import std.conv; + throw new Exception("read failed " ~ to!string(errno)); } } diff --git a/web.d b/web.d index 804d76e..b61910e 100644 --- a/web.d +++ b/web.d @@ -673,7 +673,7 @@ class ApiProvider : WebDotDBaseType { out(ret) { assert(ret !is null); } - body { + do { auto document = new TemplatedDocument( "