FPC320 lib for SSL lazarus / 66-Unix ---------------------------------------------------------------------- mm7 · 2020-06-05 12:45 There are know issues with libssl v1.1 in FPC304. I've decided to work it around by building my little library in FPC320 and then use it from program in FPC304. Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i library freehttpslib;{$mode objfpc}{$H+} uses Classes, SysUtils, fphttpclient, fpopenssl, OpenSSL, ssockets, opensslsockets, strutils; function https_get(url:string):RawByteString; cdecl;var Client: TFPHttpClient;begin Result := ''; InitSSLInterface; Client := TFPHttpClient.Create(nil); try Client.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)'); Client.AllowRedirect := true; //URL:='https://google.com/'; Result := Client.Get(URL); finally Client.Free; end;end; const Prefix = {$if defined(unix)}'lib' {$elseif freebsd}'lib' {$else}'' {$endif};exports https_get name Prefix+'https_get';end. The library is built fine. Program Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1;{$mode objfpc}{$H+} {$IF FPC_FULLVERSION < 32000}function libhttps_get(url:string):RawByteString; cdecl; external 'libfreehttpslib.so';{$endif} var R: RawByteString;begin R := libhttps_get('https://google.com'); writeln(R);end. The program is built fine. But it fails when I run it Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i mark@ustudio:~/MyProjects/fpc/https32$ ldd project1 linux- vdso.so.1 (0x00007fff2a71e000) libfreehttpslib.so => /usr/local/lib/libfreehttpslib.so (0x00007f43b6fe6000) /lib64/ld-linux-x86-64.so.2 (0x00007f43b6f3f000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f43b6d3b000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f43b694a000)mark@ustudio:~/MyProjects/fpc/https32$ ./project1 Inconsistency detected by ld.so: dl-minimal.c: 126: realloc: Assertion `ptr == alloc_last_block' failed! why? ---------------------------------------------------------------------- Cyrax · 2020-06-05 12:59 Use PChar type instead of String type. ---------------------------------------------------------------------- mm7 · 2020-06-05 13:29 just tryed. Same error Inconsistency detected by ld.so: dl-minimal.c: 126: realloc: Assertion `ptr == alloc_last_block' failed! ---------------------------------------------------------------------- Cyrax · 2020-06-05 15:32 Run your program under strace utility and see what your program really doing when its running. ---------------------------------------------------------------------- Cyrax · 2020-06-05 15:37 See this stackoverflow post : https://stackoverflow.com/questions/59956996/problem-loading-a- library-with-ffi-in-php-7-4/59994038#59994038 ---------------------------------------------------------------------- mm7 · 2020-06-05 16:08 After the program found all required libs, and even has opened connection to google, it has failed. Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ......connect(3, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr("172.217.165.14")}, 16) = -1 EINPROGRESS (Operation now in progress)select(4, NULL, [3], NULL, {tv_sec=3, tv_usec=0}) = 1 (out [3], left {tv_sec=2, tv_usec=989744})getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0fcntl(3, F_GETFL) = 0x802 (flags O_RDWR|O_NONBLOCK)fcntl(3, F_SETFL, O_RDWR) = 0futex(0x7f2075956810, FUTEX_WAKE_PRIVATE, 2147483647) = 0futex(0x7f2075956804, FUTEX_WAKE_PRIVATE, 2147483647) = 0futex(0x7f20759568d8, FUTEX_WAKE_PRIVATE, 2147483647) = 0mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2075ff5000writev(2, [{iov_base="Inconsistency detected by ld.so:"..., iov_len=33}, {iov_base="dl-minimal.c", iov_len=12}, {iov_base=": ", iov_len=2}, {iov_base="126", iov_len=3}, {iov_base=": ", iov_len=2}, {iov_base="realloc", iov_len=7}, {iov_base=": ", iov_len=2}, {iov_base="Assertion `", iov_len=11}, {iov_base="ptr == alloc_last_block", iov_len=23}, {iov_base="' failed!\n", iov_len=10}], 10Inconsistency detected by ld.so: dl-minimal.c: 126: realloc: Assertion `ptr == alloc_last_block' failed!) = 105exit_group(127) = ?+++ exited with 127 +++ I suspect something is wrong with memory/stack etc... But I am not sure how to fix it. the library was compiled with 0 No optimization, Relocatable -WR, Heap size 0, Stack size 0, All checks and assertions, and debug info. ---------------------------------------------------------------------- Fred vS · 2020-06-05 16:57 Hello. Using cmem + cthreads is working here: The library: Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i library freehttpslib;{$mode objfpc}{$H+} uses cmem, {$ifdef unix} cthreads, {$endif} Classes, SysUtils, fphttpclient, fpopenssl, OpenSSL, ssockets, opensslsockets, strutils; function https_get(url:string):RawByteString; cdecl;var Client: TFPHttpClient;begin Result := ''; InitSSLInterface; Client := TFPHttpClient.Create(nil); try Client.AddHeader('User- Agent','Mozilla/5.0 (compatible; fpweb)'); Client.AllowRedirect := true; //URL:='https://google.com/'; Result := Client.Get(URL); finally Client.Free; end;end; const Prefix = {$if defined(unix)}'lib' {$else}'' {$endif};exports https_get name Prefix+'https_get';end. The program: Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1;{$mode objfpc}{$H+} uses cmem {$ifdef unix} ,cthreads {$endif} ; {$IF FPC_FULLVERSION < 32000}function libhttps_get(url:string):RawByteString; cdecl; external 'libfreehttpslib.so';{$endif} var R: RawByteString;begin R := libhttps_get('https://google.com'); writeln(R);end. Result: Code: Pascal [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fred@fiens ~/freehttps> ./project1 Quote