Windows to Linux Porting
Hi All, Request you help on the below code, the below code always state the file does not exist even if the file do exist. Code: import core.stdc.stdlib: exit; import std.stdio; import std.file; import std.path; auto osSwitch () { string ConfigFile; version (Windows) { ConfigFile = absolutePath(`.\nasconfig.txt`); } else version (Linux) { ConfigFile = absolutePath(`nasconfig.txt`); } return ConfigFile; } void main () { auto ConfigFile = osSwitch; if (!ConfigFile.exists) { writeln("The Configuration File ", buildNormalizedPath(ConfigFile), " do to exist, Terminating the execution.."); exit(-1);} else { writeln(ConfigFile); } } From, Vino.B
How do you connect Python with D via socket, I'm still getting connection refused error
Error - builtins.ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it Python Side --- from PyQt5.QtWidgets import QApplication, QMainWindow import sys import socket import settings if __name__ == "__main__": app = QApplication([]) window = QMainWindow() window.show() host = socket.gethostname() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind((host, 0))# have os choose random available port print(host) sock.connect((host, settings.debugPort)) try: # Send data message = 'This is the message. It will be repeated.' print(sys.stderr, 'sending "%s"' % message) sock.sendall(message.encode()) # Look for the response amount_received = 0 amount_expected = len(message) while amount_received < amount_expected: data = sock.recv(16) amount_received += len(data) print(sys.stderr, 'received "%s"' % data) finally: print(sys.stderr, 'closing socket') sock.close() sys.exit(app.exec_()) And the D Side -- module server; import core.thread; import std.socket; import std.experimental.logger; class Server : Thread { private: Socket listener; int backlog; string address; ushort port; SocketSet sockSet; Socket[] clients; bool running; public: this(ushort port, string address="") { super(& run); if (address == "") address = "127.0.0.1"; this.port = port; this.address = address; backlog = int.max; listener = null; running = false; } bool setupSocket() { try { listener = new Socket(AddressFamily.INET, SocketType.STREAM); auto address_list = getAddress(address, port); if (address_list.length) { listener.bind(address_list[0]); sockSet = new SocketSet(); } } catch (Exception e) { log(LogLevel.critical, e.toString()); return false; } return true; } void start() { if (listener is null) { if (! setupSocket()) return; } running = true; if (! isRunning) super.start(); } void stop() { running = false; } private: void run() { char[1024] buffer; while(running) { sockSet.reset(); sockSet.add(listener); foreach (client; clients) sockSet.add(client); if (Socket.select(sockSet, null, null)) { foreach (client; clients) { if (sockSet.isSet(client)) { auto got = client.receive(buffer); client.send(buffer[0 .. got]); } } if (sockSet.isSet(listener)) { auto newSocket = listener.accept(); newSocket.send("Hello!\n"); clients ~= newSocket; } } } } }
LDC phobos2-ldc.lib(json.obj) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'
trying to compile a simple program in x86. Compiles fine in dmd and ldcx64. Seems like ldc is using the wrong lib for some reason? phobos2-ldc.lib(json.obj) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86' Error: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\bin\HostX86\x86\link.exe failed with status: 1112 Tried replacing the x64 dir with the x86 and it didn't change so it isn't the library arch best I can tell. Maybe this is a cross compilation issue?
Re: Is HibernateD dead?
On Thursday, 3 May 2018 at 21:28:18 UTC, bauss wrote: On Thursday, 3 May 2018 at 18:01:07 UTC, Matthias Klumpp wrote: DiamondMVC looks nice, but I would need PostgreSQL support for sure. Therefore, I think there are three options: 1) Extend the DiamondMVC ORM to support missing features that Hibernated has (maybe make it use ddbc as backend?) 2) Revive Hibernated - contacting Vadim Lopatin would be key for that, and maybe the project could be maintained in the dlang-community organization (although there are competing projects for it...) 3) Find a different D ORM that does the job and expand it to include missing features. Yes, I completely agree with PostgreSQL support. It's really important to me getting that working, as well MSSQL. I was hoping I could find time this weekend to actually do that. Would it maybe be easier for you to base on ddbc[1] or another existing abstraction layer for database abstraction? Ddbc is pretty neat, and even has support for reading structs directly from the database. [1]: https://github.com/buggins/ddbc Perhaps I will end up having another "optional" dependency to it as a temporary until I can have a better implementation or something. The frontend part of postgresql is almost finished, it's just having the postgresql driver working properly, which is where it's frozen right now. Hmm... Does any public code for that exist already that I could play around with? Unfortunately, I have a few more unusual requirements for Postgres, like: * UUIDs as primary keys, instead of integers * Ability to register custom datatypes with the ORM (version numbers in this case, the ORM can view them as text, but the database has a special type for them) * Obviously the usual ORM stuff, one-to-many, many-to-many, etc. relations (Obviously not a must-have list, I added support for custom datatypes to my ddbc fork as well, because it's not really a feature many people need) Diamond is a neat project, I played around with it about half a year ago, but didn't test the ORM part at all back then.
Re: Is HibernateD dead?
On Thursday, 3 May 2018 at 18:01:07 UTC, Matthias Klumpp wrote: DiamondMVC looks nice, but I would need PostgreSQL support for sure. Therefore, I think there are three options: 1) Extend the DiamondMVC ORM to support missing features that Hibernated has (maybe make it use ddbc as backend?) 2) Revive Hibernated - contacting Vadim Lopatin would be key for that, and maybe the project could be maintained in the dlang-community organization (although there are competing projects for it...) 3) Find a different D ORM that does the job and expand it to include missing features. Yes, I completely agree with PostgreSQL support. It's really important to me getting that working, as well MSSQL. I was hoping I could find time this weekend to actually do that. Perhaps I will end up having another "optional" dependency to it as a temporary until I can have a better implementation or something. The frontend part of postgresql is almost finished, it's just having the postgresql driver working properly, which is where it's frozen right now. MSSQL should be fairly easy, just wrapping odbc, which perhaps I could make a general odbc orm wrapper which could then be used for pretty much all alternatives.
Re: Finding the last executed line by checking dmd core
On 03.05.2018 22:45, kerdemdemir wrote: After a big refactor my code crushes I have no idea where. I am only getting : Program exited with code -11 And a core file. I used to use gdb for c++ coredumps. With what program&option I can check dmd core file? Erdemdem The same programs and options like c++
Re: Finding the last executed line by checking dmd core
On Thursday, May 03, 2018 19:45:54 kerdemdemir via Digitalmars-d-learn wrote: > After a big refactor my code crushes I have no idea where. > > I am only getting : > > Program exited with code -11 > > And a core file. > > I used to use gdb for c++ coredumps. With what program&option I > can check dmd core file? gdb supports D, though due to some recent changes to D's name mangling, the name mangling in gdb doesn't work quite right currently. I'd suggest reading this thread: https://forum.dlang.org/thread/zgnqjzarzrtzbwqjo...@forum.dlang.org - Jonathan M Davis
Re: Is HibernateD dead?
On Thursday, 3 May 2018 at 18:52:34 UTC, singingbush wrote: On Thursday, 3 May 2018 at 10:27:47 UTC, Pasqui23 wrote: Last commit on https://github.com/buggins/hibernated was almost a year ago So what is the status of HibernateD?Should I use it if I need an ORM? Or would I risk unpatched security risks? Both hibernated and ddbc have had open pull requests for months. It's really frustrating. Oh hey :-) I applied your patches for ddbc and hibernated a to my copy while back, because they weren't merged and fix real issues. There are also other patches floating around, for example people will really want https://github.com/KrzaQ/hibernated/commit/efa38c50effdd77e973b174feea89016b8d1fa1f applied when using hibernated. If there is enough interest, we can maybe provide at least some basic level of maintenance for these projects together, maybe under the dlang-community umbrella or similar. Per adoption guidelines[1], I think the projects are popular enough, but Hibernated is of course not the only D ORM (although a pretty complete one), and the continued maintenance is also not sure, even when PRs finally get reviewed and accepted faster (but that really depends on the library users). In any case, we need to get in contact with buggins. I asked him ages ago about Hibernated on Gitter, but that was probably the worst way to contact him (as he is active on Github, but probably never read that message). [1]: https://github.com/dlang-community/discussions
Finding the last executed line by checking dmd core
After a big refactor my code crushes I have no idea where. I am only getting : Program exited with code -11 And a core file. I used to use gdb for c++ coredumps. With what program&option I can check dmd core file? Erdemdem
Re: Derelict on Ubuntu with CODE::BLOCKS
On Thursday, 3 May 2018 at 18:36:04 UTC, RegeleIONESCU wrote: And here is the error I get when I execute dub run: christian@Christians:~/D_Projects$ dub run Performing "debug" build using /usr/bin/dmd for x86_64. derelict-util 2.0.6: target for configuration "library" is up to date. derelict-sdl2 2.1.4: target for configuration "library" is up to date. project_01 ~master: building configuration "application"... Linking... To force a rebuild of up-to-date targets, run again with --force. Running ./project_01 derelict.util.exception.SymbolLoadException@../../.dub/packages/derelict-util-2.0.6/derelict-util/source/derelict/util/exception.d(35): Failed to load symbol SDL_DequeueAudio from shared library libSDL2-2.0.so.0 So your app is compiling and executing. This is a runtime error. The SymbolLoadException means the SDL library was loaded, but a function Derelict expected to find was not there. This usually means that your version of Derelict by default supports a different version of SDL than you have on your system. SDL_DequeueAudio was added to SDL in 2.0.5. The best strategy is just to request the minimum version of SDL that you need via a SharedLibVersion: import derelict.util.loader : SharedLibVersion; DerelictSDL2.load(SharedLibVersion(2, 0, 0)); If you need functions from a later version, use that instead (e.g. 2,0,2). Just make sure you have the version of SDL that you need installed. Also, if you're going to load all of the libraries as in the example, you'll need to make sure they're all installed (SDL_image, SDL_mixer, SDL_net, SDL_ttf). I suggest you delete all except what you actually need. That's not your current problem, but you'll get more exceptions if those libraries aren't installed. If you want to update to derelict-sdl2 3.0.x or 3.1.x, delete your dub.selections.json before running dub after you edit your package configuration.
Re: Is HibernateD dead?
On Thursday, 3 May 2018 at 10:27:47 UTC, Pasqui23 wrote: Last commit on https://github.com/buggins/hibernated was almost a year ago So what is the status of HibernateD?Should I use it if I need an ORM? Or would I risk unpatched security risks? Both hibernated and ddbc have had open pull requests for months. It's really frustrating.
Re: Derelict on Ubuntu with CODE::BLOCKS
On Thursday, 3 May 2018 at 06:33:53 UTC, Mike Parker wrote: On Thursday, 3 May 2018 at 03:18:02 UTC, RegeleIONESCU wrote: The only problem I have with DUB is that all added dependencies are "old". For example added dependency "derelict-sdl2" is version="~>2.1.4" while on DUB site the last version is 3.1.0-alpha.3. I tried the --upgrade plus --prerelease option but the dependencies remain the same. I tried to write myself the version in the dub.sdl but I get errors related to other packages. Is there anyway to make DUB automatically use the latest version of a dependency? You an control that with precision, specifying specific versions if you want. But with Derelict, if you're using mulitple Derelict package you have to make sure that all of them depend on the same major version of DerelictUtil. If you paste your full dependency list here, exactly as it's written in your package configuration, I might be able to help you. Hello! I tried to execute the example from Derelict-SDL2 but I get some troubles. Here is the program: import std.stdio; import derelict.sdl2.sdl; import derelict.sdl2.image; import derelict.sdl2.mixer; import derelict.sdl2.ttf; import derelict.sdl2.net; void main() { DerelictSDL2.load(); DerelictSDL2Image.load(); DerelictSDL2Mixer.load(); DerelictSDL2ttf.load(); DerelictSDL2Net.load(); writeln("What is wrong"); } Here is the dub.sdl file content: name "project_01" description "SDL2_image test app" authors "Christian" copyright "Copyright © 2018, Christian" license "proprietary" dependency "derelict-sdl2" version="~>2.1.4" Here is the dub.selections.json { "fileVersion": 1, "versions": { "derelict-sdl2": "2.1.4", "derelict-util": "2.0.6" } } And here is the error I get when I execute dub run: christian@Christians:~/D_Projects$ dub run Performing "debug" build using /usr/bin/dmd for x86_64. derelict-util 2.0.6: target for configuration "library" is up to date. derelict-sdl2 2.1.4: target for configuration "library" is up to date. project_01 ~master: building configuration "application"... Linking... To force a rebuild of up-to-date targets, run again with --force. Running ./project_01 derelict.util.exception.SymbolLoadException@../../.dub/packages/derelict-util-2.0.6/derelict-util/source/derelict/util/exception.d(35): Failed to load symbol SDL_DequeueAudio from shared library libSDL2-2.0.so.0 ../../.dub/packages/derelict-util-2.0.6/derelict-util/source/derelict/util/sharedlib.d:177 void* derelict.util.sharedlib.SharedLib.loadSymbol(immutable(char)[], bool) [0x450eef] ../../.dub/packages/derelict-util-2.0.6/derelict-util/source/derelict/util/loader.d:323 void* derelict.util.loader.SharedLibLoader.loadSymbol(immutable(char)[], bool) [0x44f42a] ../../.dub/packages/derelict-util-2.0.6/derelict-util/source/derelict/util/loader.d:346 void derelict.util.loader.SharedLibLoader.bindFunc(void**, immutable(char)[], bool) [0x44f480] ../../.dub/packages/derelict-sdl2-2.1.4/derelict-sdl2/source/derelict/sdl2/sdl.d:111 void derelict.sdl2.sdl.DerelictSDL2Loader.loadSymbols() [0x44ab1f] ../../.dub/packages/derelict-util-2.0.6/derelict-util/source/derelict/util/loader.d:198 void derelict.util.loader.SharedLibLoader.load(immutable(char)[][]) [0x44f2aa] ../../.dub/packages/derelict-util-2.0.6/derelict-util/source/derelict/util/loader.d:143 void derelict.util.loader.SharedLibLoader.load(immutable(char)[]) [0x44f224] ../../.dub/packages/derelict-util-2.0.6/derelict-util/source/derelict/util/loader.d:82 void derelict.util.loader.SharedLibLoader.load() [0x44f107] source/app.d:10 _Dmain [0x44899a] Program exited with code 1 christian@Christians:~/D_Projects$ Could you help me, please? Thank you very much for your kind support! p.s. I am using Ubuntu 16.04.
Re: Is HibernateD dead?
On Thursday, 3 May 2018 at 10:27:47 UTC, Pasqui23 wrote: Last commit on https://github.com/buggins/hibernated was almost a year ago So what is the status of HibernateD?Should I use it if I need an ORM? Or would I risk unpatched security risks? Hah! I was just browsing the forums thinking about the same issue and whether I should ask a question about it. I am using Hibernated in one bigger project, ripping it out at this point would be quite painful and I only ever want to do that if there is a sustainable and actively developed alternative that is comparable in features[1]. Truth is, so far I haven't found any D ORM that compares to Hibernated in terms of supported features and databases. Hibernated also has issues though, at the time I maintain a forked version with changes that I hope to upstream soon - unfortunately, the trivial open pull-request on the project doesn't look promising. DiamondMVC looks nice, but I would need PostgreSQL support for sure. Therefore, I think there are three options: 1) Extend the DiamondMVC ORM to support missing features that Hibernated has (maybe make it use ddbc as backend?) 2) Revive Hibernated - contacting Vadim Lopatin would be key for that, and maybe the project could be maintained in the dlang-community organization (although there are competing projects for it...) 3) Find a different D ORM that does the job and expand it to include missing features. I really don't want to write ORMs in D and I actually lack the skills to do it properly, but I rely pretty heavily on Hibernated and ddbc. So, if anyone has a solution for this, I would help with it for sure. Asking Vadim (buggins) on the state of Hibernated would be the first thing to do, I think. Cheers, Matthias [1]: In fact, when I switched the database backend once in the past from an attempt to not use an ORM to using Hibernated, I was very close to rewriting the whole thing in Python - in D, there are tons of ORMs and database abstraction layers written, but not a single one compares even remotely to the likes of SQLAlchemy. It would be awesome if instead of 5 70% completed projects, we had one 90% complete one.
Re: Ambiguous template parameter names
On Thursday, 3 May 2018 at 02:51:18 UTC, Meta wrote: If you want that, you might be able to do `int val = val` on the inner function, though I'm not sure that'll work. It does not work and will do nothing.
Re: C++ / Wrong function signature generated for reference parameter
On 2018-05-03 09:34:56 +, kinke said: That's why there's `extern(C++, class) struct Image`, see https://dlang.org/spec/cpp_interface.html#classes. Hi, thanks. I didn't understand the docs as without any code examples for all the different cases, it's hard to derive the syntax and how to use it if one just gets started with this interface. As const is transitive in D, mangling a const object reference as C++ `const T *const` is consistent, but also means that a `const T *` cannot be mapped directly to D via a class (but as `const(T)*` if T is a D struct). Not sure I understand this too. This is now what I get: DMD: public: unsigned int __cdecl b2d::Context2D::_begin(class b2d::Image & __ptr64,class b2d::Context2D::InitParams const * __ptr64 const) __ptr64 LIB: public: unsigned int __cdecl b2d::Context2D::_begin(class b2d::Image & __ptr64,class b2d::Context2D::InitParams const * __ptr64) __ptr64 So I somehow get some more const from D. This is the code I used: final uint _begin(ref Image image, const(InitParams) initParams); Any idea how to solve this? I really like that I'm able to use C++ stuff from D but interfacing the tow is a bit tedious... it would be great to be able to write the C++ signature in the extern(C++) scope and have it translated to the D equivalent internally. -- Robert M. Münch http://www.saphirion.com smarter | better | faster
Re: Is HibernateD dead?
On Thursday, 3 May 2018 at 11:00:36 UTC, bauss wrote: On Thursday, 3 May 2018 at 10:27:47 UTC, Pasqui23 wrote: That is if you want to use something that isn't "dead"
Re: Is HibernateD dead?
On Thursday, 3 May 2018 at 10:27:47 UTC, Pasqui23 wrote: Last commit on https://github.com/buggins/hibernated was almost a year ago So what is the status of HibernateD?Should I use it if I need an ORM? Or would I risk unpatched security risks? Although currently only mysql/mariadb support, then you can easily implement your own, but there is an orm in Diamond: Basically you can strip out whole "diamond.data" and "diamond.database", I'm pretty sure they don't really depend on anything except for maybe one or two modules in "diamond.core" http://diamondmvc.org/docs/data/#database I'm planning on making a more light-weight version of the ORM that makes it even easier to implement your own, as right now you'd need to understand the mechanics of it, "kinda" I'm currently working on having some more support for other database drivers, but my time is very limited at the moment, hence why even postgresql support has been frozen for a while (Also due to the fact that I can't use the vibe.d postgresql package as it doesn't work with Windows, so I need to make my own implementation and I simply haven't had time.) I'll be more than happy to assist you in implementing it for whatever target you have, either create an issue in the repository: https://github.com/DiamondMVC/Diamond/issues or write a mail to cont...@diamondmvc.org
Re: cannot find -lcurl in Linux
On Thursday, 3 May 2018 at 10:22:43 UTC, Vino wrote: On Thursday, 3 May 2018 at 10:19:55 UTC, Jonathan M Davis wrote: [...] Hi Jonathan, The below packages are already installed [...] Hi Jonathan, Installed the package libcurl-devel, that resolved the issue. Thank you very much. From, Vino.B
Is HibernateD dead?
Last commit on https://github.com/buggins/hibernated was almost a year ago So what is the status of HibernateD?Should I use it if I need an ORM? Or would I risk unpatched security risks?
Re: cannot find -lcurl in Linux
On Thursday, 3 May 2018 at 10:19:55 UTC, Jonathan M Davis wrote: On Thursday, May 03, 2018 10:10:05 Vino via Digitalmars-d-learn wrote: Hi All, Request your help , while compiling a d program in SUSE Linux i am getting the below error, the executable curl is present under the path /usr/bin/ ask:/DScript # dmd -m64 -O -release -inline test.d /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lcurl collect2: error: ld returned 1 exit status Error: linker exited with status 1 -lcurl means that it's linking against the curl library, not that it's trying to use the curl executable. It needs libcurl.a, and I believe that on OpenSuSE, that means that you need to install the development package for curl. - Jonathan M Davis Hi Jonathan, The below packages are already installed S | Name | Type| Version| Arch | Repository ---++-+++ i+ | curl | package | 7.37.0-37.8.1 | x86_64 | localSLES12-SP2-Updates i+ | curl | package | 7.37.0-37.8.1 | x86_64 | SLES12-SP2-Updates i+ | libcurl4 | package | 7.37.0-37.8.1 | x86_64 | localSLES12-SP2-Updates i+ | libcurl4 | package | 7.37.0-37.8.1 | x86_64 | SLES12-SP2-Updates i+ | libcurl4-32bit | package | 7.37.0-37.17.1 | x86_64 | SLES12-SP2-Updates i | python-pycurl | package | 7.19.0-16.5| x86_64 | localSLES12-SP2-Pool i | python-pycurl | package | 7.19.0-16.5| x86_64 | SLES12-SP2-Pool From, Vino.B
Re: cannot find -lcurl in Linux
On Thursday, May 03, 2018 10:10:05 Vino via Digitalmars-d-learn wrote: > Hi All, > > Request your help , while compiling a d program in SUSE Linux i > am getting the below error, the executable curl is present under > the path /usr/bin/ > > ask:/DScript # dmd -m64 -O -release -inline test.d > /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: > cannot find -lcurl collect2: error: ld returned 1 exit status > Error: linker exited with status 1 -lcurl means that it's linking against the curl library, not that it's trying to use the curl executable. It needs libcurl.a, and I believe that on OpenSuSE, that means that you need to install the development package for curl. - Jonathan M Davis
cannot find -lcurl in Linux
Hi All, Request your help , while compiling a d program in SUSE Linux i am getting the below error, the executable curl is present under the path /usr/bin/ ask:/DScript # dmd -m64 -O -release -inline test.d /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lcurl collect2: error: ld returned 1 exit status Error: linker exited with status 1 From, Vino.B
Re: Why does enumerate over range return dchar, when ranging without returns char?
On Thursday, May 03, 2018 22:00:04 rikki cattermole via Digitalmars-d-learn wrote: > On 03/05/2018 9:50 PM, ag0aep6g wrote: > > On 05/03/2018 07:56 AM, rikki cattermole wrote: > >>> ``` > >>> import std.stdio; > >>> import std.range : enumerate; > >>> > >>> void main() > >>> { > >>> char[] s = ['a','b','c']; > >>> > >>> char[3] x; > >>> auto i = 0; > >>> foreach(c; s) { > >>> x[i] = c; > >>> i++; > >>> } > >>> > >>> writeln(x); > >>> } > >>> ``` > >>> Above works without cast. > >>> > >>> ''' > >>> import std.stdio; > >>> import std.range : enumerate; > >>> > >>> void main() > >>> { > >>> char[] s = ['a','b','c']; > >>> > >>> char[3] x; > >>> foreach(i, c; enumerate(s)) { > >>> x[i] = c; > >>> i++; > >>> } > >>> > >>> writeln(x); > >>> } > >>> ``` > > > > [...] > > > >> The first example uses auto-decoding (UTF-8 codepoints into a single > >> UTF-32 one). This is considered a bad thing. But the compiler can > >> disable it and leave it as UTF-8 code point upon request. > > > > The first example (foreach over a char[]) doesn't do any decoding. UTF-8 > > stays UTF-8. > > > > Also, a `char` is a UTF-8 code *unit*, not a code *point*. > > > >> The second example returns a Voldemort type (means no-name) which > >> happens to be an input range. Where it can't disable anything and has > >> been told that it is returning a dchar. See[0] as to where this gets > >> decoded. > > > > This is auto decoding. > > > >> Writing two small functions to replace it (and popFront), will > >> override this behavior. > > > > This sounds like you can disable auto decoding by providing your own > > range primitives in your own module. That doesn't work, because Phobos > > would still use the ones from std.range.primitives. > > Hmm, I swear this use to work. > > Oh well, easy fix: > > import std.algorithm; > > struct Wrapper { > char[] input; > alias input this; > > @property char front() { return input[0]; } > @property bool empty() {return input.length == 0;} > void popFront() { input = input[1 .. $]; } > } > > void main() { > char[] text = ['1', '2', '3']; > > foreach(c; Wrapper(text).filter!(a => a != '\0')) { > pragma(msg, typeof(c)); > } > } The standard way to get around auto-decoding is std.utf.byCodeUnit. - Jonathan M Davis
Re: Why does enumerate over range return dchar, when ranging without returns char?
On 03/05/2018 9:50 PM, ag0aep6g wrote: On 05/03/2018 07:56 AM, rikki cattermole wrote: ``` import std.stdio; import std.range : enumerate; void main() { char[] s = ['a','b','c']; char[3] x; auto i = 0; foreach(c; s) { x[i] = c; i++; } writeln(x); } ``` Above works without cast. ''' import std.stdio; import std.range : enumerate; void main() { char[] s = ['a','b','c']; char[3] x; foreach(i, c; enumerate(s)) { x[i] = c; i++; } writeln(x); } ``` [...] The first example uses auto-decoding (UTF-8 codepoints into a single UTF-32 one). This is considered a bad thing. But the compiler can disable it and leave it as UTF-8 code point upon request. The first example (foreach over a char[]) doesn't do any decoding. UTF-8 stays UTF-8. Also, a `char` is a UTF-8 code *unit*, not a code *point*. The second example returns a Voldemort type (means no-name) which happens to be an input range. Where it can't disable anything and has been told that it is returning a dchar. See[0] as to where this gets decoded. This is auto decoding. Writing two small functions to replace it (and popFront), will override this behavior. This sounds like you can disable auto decoding by providing your own range primitives in your own module. That doesn't work, because Phobos would still use the ones from std.range.primitives. Hmm, I swear this use to work. Oh well, easy fix: import std.algorithm; struct Wrapper { char[] input; alias input this; @property char front() { return input[0]; } @property bool empty() {return input.length == 0;} void popFront() { input = input[1 .. $]; } } void main() { char[] text = ['1', '2', '3']; foreach(c; Wrapper(text).filter!(a => a != '\0')) { pragma(msg, typeof(c)); } }
Re: Why does enumerate over range return dchar, when ranging without returns char?
On 05/03/2018 07:56 AM, rikki cattermole wrote: ``` import std.stdio; import std.range : enumerate; void main() { char[] s = ['a','b','c']; char[3] x; auto i = 0; foreach(c; s) { x[i] = c; i++; } writeln(x); } ``` Above works without cast. ''' import std.stdio; import std.range : enumerate; void main() { char[] s = ['a','b','c']; char[3] x; foreach(i, c; enumerate(s)) { x[i] = c; i++; } writeln(x); } ``` [...] The first example uses auto-decoding (UTF-8 codepoints into a single UTF-32 one). This is considered a bad thing. But the compiler can disable it and leave it as UTF-8 code point upon request. The first example (foreach over a char[]) doesn't do any decoding. UTF-8 stays UTF-8. Also, a `char` is a UTF-8 code *unit*, not a code *point*. The second example returns a Voldemort type (means no-name) which happens to be an input range. Where it can't disable anything and has been told that it is returning a dchar. See[0] as to where this gets decoded. This is auto decoding. Writing two small functions to replace it (and popFront), will override this behavior. This sounds like you can disable auto decoding by providing your own range primitives in your own module. That doesn't work, because Phobos would still use the ones from std.range.primitives. [0] https://dlang.org/phobos/std_range_primitives.html#.front
Re: C++ / Wrong function signature generated for reference parameter
On Thursday, 3 May 2018 at 07:00:03 UTC, Robert M. Münch wrote: using struct won't give the correct signature That's why there's `extern(C++, class) struct Image`, see https://dlang.org/spec/cpp_interface.html#classes. Not sure about the const part too, if this is correct on the D side... As const is transitive in D, mangling a const object reference as C++ `const T *const` is consistent, but also means that a `const T *` cannot be mapped directly to D via a class (but as `const(T)*` if T is a D struct).
Re: C++ / Wrong function signature generated for reference parameter
On 2018-05-03 02:23:27 +, Rubn said: You want to use a struct which isn't passed by pointer, but by value. Which will then give you the signature you want. In addition to my other post, using struct won't give the correct signature. That's the signature I need: public: unsigned int __cdecl b2d::Context2D::_begin(class b2d::Image & __ptr64,class b2d::Context2D::InitParams const * __ptr64) __ptr64 And this is what D does when using a struct: public: unsigned int __cdecl b2d::Context2D::_begin(struct b2d::Image &,class b2d::InitParams const * const) Of course the linker can't resolve this. Not sure about the const part too, if this is correct on the D side... -- Robert M. Münch http://www.saphirion.com smarter | better | faster