Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread via Digitalmars-d-learn
On Saturday, 24 June 2017 at 18:46:06 UTC, ketmar wrote: Petar Kirov [ZombineDev] wrote: Oh, I should have mentioned that I don't expect anything but ugly platform-specific hacks possibly involving the object file format ;) Just enough of them to claim that the solution is somewhat cross-plat

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread ketmar via Digitalmars-d-learn
Petar Kirov [ZombineDev] wrote: Oh, I should have mentioned that I don't expect anything but ugly platform-specific hacks possibly involving the object file format ;) Just enough of them to claim that the solution is somewhat cross-platform :D i guess you can loot at how TSL scanning is done

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread via Digitalmars-d-learn
On Saturday, 24 June 2017 at 18:05:55 UTC, ketmar wrote: Petar Kirov [ZombineDev] wrote: *** But in any case, the null-terminated string was just an example application. I'm interested in a fast way to determine the "storage class" of the memory a slice or a pointer point to. I'm expecting so

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread ketmar via Digitalmars-d-learn
Petar Kirov [ZombineDev] wrote: *** But in any case, the null-terminated string was just an example application. I'm interested in a fast way to determine the "storage class" of the memory a slice or a pointer point to. I'm expecting some magic along the lines of checking the range of address

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread via Digitalmars-d-learn
On Saturday, 24 June 2017 at 14:18:33 UTC, ketmar wrote: with the edge case when something like the code i posted below managed to make `a` perfectly aligned with r/o area, and you got segfault by accising out-of-bounds byte. BTW, are you sure? AFAIU, it doesn't matter if the CTFE engine re

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread ketmar via Digitalmars-d-learn
ketmar wrote: p.s.: btw, druntime tries to avoid that edge case by not checking for trailing out-of-bounds zero if string ends exactly on dword boundary. it will miss some strings this way, but otherwise it is perfectly safe. oops. not druntime, phobos, in `std.string.toStringz()`.

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread ketmar via Digitalmars-d-learn
p.s.: btw, druntime tries to avoid that edge case by not checking for trailing out-of-bounds zero if string ends exactly on dword boundary. it will miss some strings this way, but otherwise it is perfectly safe.

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread ketmar via Digitalmars-d-learn
Petar Kirov [ZombineDev] wrote: Please note that not all static immutable strings have to be null terminated. It is possible to generate a string at ctfe which may appear the same as string literal, but does not have the \0 at the end. But in that case, the check `s.ptr[s.length] == 0` in fas

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread via Digitalmars-d-learn
On Saturday, 24 June 2017 at 13:11:02 UTC, Stefan Koch wrote: On Saturday, 24 June 2017 at 12:22:54 UTC, Petar Kirov [ZombineDev] wrote: [ ... ] /** * Returns: * A pointer to a null-terminated string in O(1) time, * (with regards to the length of the string and the required * memory, if any

Re: What's the fastest way to check if a slice points to static data

2017-06-24 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 24 June 2017 at 12:22:54 UTC, Petar Kirov [ZombineDev] wrote: [ ... ] /** * Returns: * A pointer to a null-terminated string in O(1) time, * (with regards to the length of the string and the required * memory, if any) or `null` if * the time constraint * can't be met. */ immu

What's the fastest way to check if a slice points to static data

2017-06-24 Thread via Digitalmars-d-learn
I need a fast and hopefully relatively cross-platform (ELF, OMF, COFF and MachO) way of checking if a slice points to data in the read-only section of the binary, i.e. it's pointing to a statically-allocated piece of memory. Of course a simple solution using meta programming would be: --- e