Re: Issues creating a dynamic libary with dub

2020-03-24 Thread mitchell via Digitalmars-d-learn
On Wednesday, 25 March 2020 at 04:04:09 UTC, rikki cattermole 
wrote:
When I see -fPIC I think something is wrong with your 
compiler+runtime setup.


Use -v to see the commands dub is using. This should not be dub 
related.


It seems you're correct. I looked through some of the older 
projects I've made on this machine (ones where I used make 
instead of dub), I found that whenever I made a shared library, I 
always had to revert to using gcc, rather than gdc. I will need 
to examine my setup.


Thank you for the rapid response!


Re: Issues creating a dynamic libary with dub

2020-03-24 Thread rikki cattermole via Digitalmars-d-learn
When I see -fPIC I think something is wrong with your compiler+runtime 
setup.


Use -v to see the commands dub is using. This should not be dub related.


Issues creating a dynamic libary with dub

2020-03-24 Thread mitchell via Digitalmars-d-learn

Hello,

I'm having issues creating a dynamic library with dub.
The dub config file contains (with the exception of the names and 
such) only


targetType "dynamicLibrary"

When I attempt to buld the library, I get:

common ~master: building configuration "library"...
/usr/bin/ld: 
/usr/lib/gcc/x86_64-linux-gnu/5/libgphobos2.a(ascii.o): 
relocation R_X86_64_32S against `.data' can not be used when 
making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/5/libgphobos2.a: error adding 
symbols: Bad value

collect2: error: ld returned 1 exit status
gdc failed with exit code 1.

I've been working with D for quite a while, but I've never really 
used dub. It looks like dub is attempting to attach phobos to the 
dynamic link library I'm trying to create. Is there something 
simple which I'm missing entirely?


I would have asked on the dub forums, but they seem to be down 
right now.


Re: linking obj files compiled with LDC2 1.20.0 on Win64

2020-03-24 Thread realhet via Digitalmars-d-learn

On Tuesday, 24 March 2020 at 16:35:56 UTC, realhet wrote:
On Tuesday, 24 March 2020 at 15:22:19 UTC, Steven Schveighoffer 
wrote:

On 3/24/20 10:28 AM, realhet wrote:

On Sunday, 22 March 2020 at 20:20:17 UTC, Steven Schveighoffer


Now I have 2 of this:

megatexturing.obj : error LNK2019: unresolved external symbol

pure nothrow @nogc @safe void std.format.hasToString!(
  std.typecons.Tuple!(
ulong, "index", const(het.megatexturing.SubTexInfo), "value"
  ).Tuple, char
).__lambda1().S.put(char)

referenced in function

pure scope @safe bool 
std.format.FormatSpec!(char).FormatSpec.writeUpToNextSpec!(

  std.format.hasToString!(
std.typecons.Tuple!(
  ulong,
  "index",
  const(het.megatexturing.SubTexInfo),
  "value"
).Tuple,
char
  ).__lambda1().S
).writeUpToNextSpec(
  ref std.format.hasToString!(std.typecons.Tuple!(ulong, "index", 
const(het.megatexturing.SubTexInfo), "value").Tuple, 
char).__lambda1().S

)

And only with that format hasToString! template.
I hope I can locate something along this:
std.typecons.Tuple!(
  ulong, "index", const(het.megatexturing.SubTexInfo), "value"
)
Maybe it refers to a function parameter list in my program.

Something tells me that this should not be look like something 
recursive o.o


I'll search for that Linux tool on windows that you mentioned...


Re: linking obj files compiled with LDC2 1.20.0 on Win64

2020-03-24 Thread realhet via Digitalmars-d-learn
On Tuesday, 24 March 2020 at 15:22:19 UTC, Steven Schveighoffer 
wrote:

On 3/24/20 10:28 AM, realhet wrote:

On Sunday, 22 March 2020 at 20:20:17 UTC, Steven Schveighoffer


I managed to compile it with normal compilation.
The -allInst flag may be the problem.

I also had success by manual linking:

ldmd2 -vcolumns -Ic:\D\libs\ -m64 -mcpu=athlon64-sse3 
-mattr=+ssse3 -release -O -inline -boundscheck=off 
-of=c:\D\libs\het\hdmd\hdmd.obj c:\D\libs\het\hdmd\hdmd.d ... -c


link /LIBPATH:c:\D\ldc2\lib64 /OUT:c:\D\libs\het\hdmd\hdmd.exe 
/MACHINE:X64 kernel32.lib user32.lib legacy_stdio_definitions.lib 
c:\D\libs\het\hdmd\hdmd.obj druntime-ldc.lib phobos2-ldc.lib 
msvcrt.lib


So I will try to narrow the problem in Jsonizer.exceptions.d

For a 11k LOC project with 10 .d files when I only modify a few 
top level d files, and I already have the .obj files for the 
rest, the compilation time is only 5-10 seconds instead of the 40 
with the all in one compilation. I got used to this, so I will 
try anything to fix it :D


Re: linking obj files compiled with LDC2 1.20.0 on Win64

2020-03-24 Thread Steven Schveighoffer via Digitalmars-d-learn

On 3/24/20 10:28 AM, realhet wrote:

On Sunday, 22 March 2020 at 20:20:17 UTC, Steven Schveighoffer wrote:
Make sure you don't have any stale objects left over in your project 
from the older build. Build everything clean from scratch.




After narrowing the problem, I fixed all warnings, and deprecations, and 
I have only one linker error now:


Compiler command line (LDC 1.20.0 Win64):
ldmd2 -vcolumns -c -op -allinst -Ic:\D\libs\ -m64 -mcpu=athlon64-sse3 
-mattr=+ssse3 -release -O -inline -boundscheck=off 
c:\D\libs\jsonizer\exceptions.d


Linker command line:
link /LIBPATH:c:\D\ldc2\lib64 /OUT:c:\D\libs\het\hdmd\hdmd.exe 
/MACHINE:X64 kernel32.lib user32.lib legacy_stdio_definitions.lib ***All 
the required obj files*** druntime-ldc.lib phobos2-ldc.lib msvcrt.lib


Linker response (after demangling):
Microsoft (R) Incremental Linker Version 14.23.28105.4
Copyright (C) Microsoft Corporation.  All rights reserved.

-

exceptions.obj : error LNK2019: unresolved external symbol

pure nothrow @nogc @safe void 
std.format.hasToString!(std.json.JSONValue, char).__lambda2().S.put(char)


referenced in function

pure nothrow @nogc @safe void 
std.range.primitives.put!(std.format.hasToString!(std.json.JSONValue, 
char).__lambda2().S, char).put(ref 
std.format.hasToString!(std.json.JSONValue, char).__lambda2().S, char)


-

I've searched for the hasToString template, but this seems way too 
complicated for me.

This nested lambda template thing o.O


Ugh, this is a template constraint. There's no reason to see it in 
compiled code.




Here is the source code for the exceptions.obj file: 
https://github.com/rcorre/jsonizer/blob/master/src/jsonizer/exceptions.d


These are caused by some format() calls, I don't know why it is a 
problem now and it's totally OK with a 2017 version.


This nested std.range.primitives.put is weird for me. Maybe it's a bug 
because by the -CompileAllTemplateInstances flag? (That's not the normal 
use, I know: I comile all the objs, and while I work, I only compile the 
ones that changed (recursively ofc), and finally link. It's much faster 
this way on a 8 core machine.).


I think this might be part of the problem. It's still a bug in the 
compiler, but this unusual way of compiling might be bringing it out. 
Most likely either the mangling is changed when compiling the 
dependency, or the symbol is being incorrectly referenced or incorrectly 
excluded.


If this were Linux, I'd start using nm to search the object files for 
the symbol that is missing (like search for symbols defining 
hasToString), and see if it possibly might be mangled in a different 
way. I'm not sure what tools there are on Windows to do this.


-Steve


Re: Swedish letters fuck up parsing into SQL querry

2020-03-24 Thread Anders S via Digitalmars-d-learn

On Tuesday, 24 March 2020 at 14:10:19 UTC, WebFreak001 wrote:

On Tuesday, 24 March 2020 at 11:15:24 UTC, matheus wrote:

On Monday, 23 March 2020 at 15:41:50 UTC, Adam D. Ruppe wrote:

On Monday, 23 March 2020 at 15:15:12 UTC, Anders S wrote:

I'm creating a connection to the db and conn.exec(sql)


It depends on the library but it is almost always easier to 
do it right than to do it the way you are.


like with my lib it is

db.query("update celldata set name = ?", new_name);


I'm not the OP but I have a question, isn't this passive to 
SQL injection too, or your LIB will handle this somehow?


If is the later could you please point the code on GitHub?

Matheus.


https://github.com/mysql-d/mysql-native/blob/8f9cb4cd9904ade43af006f96e5e03eebe7a7c19/source/mysql/protocol/comms.d#L494

it's builtin into mysql


Ahhh, thanks need to dig into this and learn.

Thanks guys for all the responses. Got plenty of leads to dig 
into, also issues I have to consider to be a better coder ;)

Thks again


Re: linking obj files compiled with LDC2 1.20.0 on Win64

2020-03-24 Thread realhet via Digitalmars-d-learn
On Sunday, 22 March 2020 at 20:20:17 UTC, Steven Schveighoffer 
wrote:
Make sure you don't have any stale objects left over in your 
project from the older build. Build everything clean from 
scratch.


-Steve


After narrowing the problem, I fixed all warnings, and 
deprecations, and I have only one linker error now:


Compiler command line (LDC 1.20.0 Win64):
ldmd2 -vcolumns -c -op -allinst -Ic:\D\libs\ -m64 
-mcpu=athlon64-sse3 -mattr=+ssse3 -release -O -inline 
-boundscheck=off c:\D\libs\jsonizer\exceptions.d


Linker command line:
link /LIBPATH:c:\D\ldc2\lib64 /OUT:c:\D\libs\het\hdmd\hdmd.exe 
/MACHINE:X64 kernel32.lib user32.lib legacy_stdio_definitions.lib 
***All the required obj files*** druntime-ldc.lib phobos2-ldc.lib 
msvcrt.lib


Linker response (after demangling):
Microsoft (R) Incremental Linker Version 14.23.28105.4
Copyright (C) Microsoft Corporation.  All rights reserved.

-

exceptions.obj : error LNK2019: unresolved external symbol

pure nothrow @nogc @safe void 
std.format.hasToString!(std.json.JSONValue, 
char).__lambda2().S.put(char)


referenced in function

pure nothrow @nogc @safe void 
std.range.primitives.put!(std.format.hasToString!(std.json.JSONValue, char).__lambda2().S, char).put(ref std.format.hasToString!(std.json.JSONValue, char).__lambda2().S, char)


-

I've searched for the hasToString template, but this seems way 
too complicated for me.

This nested lambda template thing o.O

Here is the source code for the exceptions.obj file: 
https://github.com/rcorre/jsonizer/blob/master/src/jsonizer/exceptions.d


These are caused by some format() calls, I don't know why it is a 
problem now and it's totally OK with a 2017 version.


This nested std.range.primitives.put is weird for me. Maybe it's 
a bug because by the -CompileAllTemplateInstances flag? (That's 
not the normal use, I know: I comile all the objs, and while I 
work, I only compile the ones that changed (recursively ofc), and 
finally link. It's much faster this way on a 8 core machine.).






Re: Swedish letters fuck up parsing into SQL querry

2020-03-24 Thread WebFreak001 via Digitalmars-d-learn

On Tuesday, 24 March 2020 at 11:15:24 UTC, matheus wrote:

On Monday, 23 March 2020 at 15:41:50 UTC, Adam D. Ruppe wrote:

On Monday, 23 March 2020 at 15:15:12 UTC, Anders S wrote:

I'm creating a connection to the db and conn.exec(sql)


It depends on the library but it is almost always easier to do 
it right than to do it the way you are.


like with my lib it is

db.query("update celldata set name = ?", new_name);


I'm not the OP but I have a question, isn't this passive to SQL 
injection too, or your LIB will handle this somehow?


If is the later could you please point the code on GitHub?

Matheus.


https://github.com/mysql-d/mysql-native/blob/8f9cb4cd9904ade43af006f96e5e03eebe7a7c19/source/mysql/protocol/comms.d#L494

it's builtin into mysql


Re: Swedish letters fuck up parsing into SQL querry

2020-03-24 Thread Steven Schveighoffer via Digitalmars-d-learn

On 3/24/20 7:15 AM, matheus wrote:

On Monday, 23 March 2020 at 15:41:50 UTC, Adam D. Ruppe wrote:

On Monday, 23 March 2020 at 15:15:12 UTC, Anders S wrote:

I'm creating a connection to the db and conn.exec(sql)


It depends on the library but it is almost always easier to do it 
right than to do it the way you are.


like with my lib it is

db.query("update celldata set name = ?", new_name);


I'm not the OP but I have a question, isn't this passive to SQL 
injection too, or your LIB will handle this somehow?


I haven't seen the code, but I'm going to guess this is using prepared 
statements with the given string as a parameter. This is what 
mysql-native does.


-Steve


Re: Swedish letters fuck up parsing into SQL querry

2020-03-24 Thread matheus via Digitalmars-d-learn

On Monday, 23 March 2020 at 15:41:50 UTC, Adam D. Ruppe wrote:

On Monday, 23 March 2020 at 15:15:12 UTC, Anders S wrote:

I'm creating a connection to the db and conn.exec(sql)


It depends on the library but it is almost always easier to do 
it right than to do it the way you are.


like with my lib it is

db.query("update celldata set name = ?", new_name);


I'm not the OP but I have a question, isn't this passive to SQL 
injection too, or your LIB will handle this somehow?


If is the later could you please point the code on GitHub?

Matheus.


Re: Swedish letters fuck up parsing into SQL querry

2020-03-24 Thread WebFreak001 via Digitalmars-d-learn

On Monday, 23 March 2020 at 15:15:12 UTC, Anders S wrote:

On Monday, 23 March 2020 at 15:07:31 UTC, Adam D. Ruppe wrote:

On Monday, 23 March 2020 at 14:26:46 UTC, Anders S wrote:
do you mean I should loop through each pos till 
strlen(cellTab[CellIndex].name) to find "\0"?


strlen is ok, that gives the answer itself. Just slice to that.

cellTab[CellIndex].name[0 .. 
strlen(cellTab[CellIndex].name.ptr)]


could do it. or

size_t end = 0;
foreach(idx, ch; cellTab[CellIndex].name)
   if(ch == 0) {
end = idx;
break;
   }

auto name = cellTab[CellIndex].name[0 .. end];


anything like that


How do you suggest I do the querry build then?


how are you running it? using a lib or just generating a .sql 
file?


Hi,
I'm creating a connection to the db and conn.exec(sql)
I think I'll try the foreach to find out if it works  ( 
tomorrow )


if you use mysql-native, use

conn.exec("UPDATE celldata SET name=?, ...", name);

where you can make a function for name =

/// Takes the data part from a fixed length string until a null 
terminator.
/// Returns: a slice of text until a null terminator or whole 
string in case there is none.

const(char)[] str(size_t n)(const(char)[n] text)
{
// count until \0 (in bytes, so we can't cause utf decoding 
exception)

auto end = text[].representation.countUntil(0);
// return whole string if there is no \0, otherwise until \0
return end == -1 ? text[] : text[0 .. end];
}

I think making your own function here instead of using to!string 
is what you want here. If you put in a char[20] into to!string, 
it will still return a string with the remaining characters being 
\0 characters.