savely-krasovsky / go-tdjson Goto Github PK
View Code? Open in Web Editor NEWGolang bindings for TDLib (Telegram MTProto library)
License: MIT License
Golang bindings for TDLib (Telegram MTProto library)
License: MIT License
go get github.com/L11R/go-tdjson
# github.com/L11R/go-tdjson
In file included from ../../../.go/src/github.com/L11R/go-tdjson/tdjson.go:6:0:
./td/telegram/td_log.h:61:1: error: unknown type name 'using'; did you mean 'uint'?
using td_log_fatal_error_callback_ptr = void (*)(const char *error_message);
^~~~~
uint
./td/telegram/td_log.h:61:41: error: expected expression before 'void'
using td_log_fatal_error_callback_ptr = void (*)(const char *error_message);
^~~~
./td/telegram/td_log.h:72:52: error: expected declaration specifiers or '...' before 'td_log_fatal_error_callback_ptr'
TDJSON_EXPORT void td_set_log_fatal_error_callback(td_log_fatal_error_callback_ptr callback);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
With the latest version of tdlib, builded following the instraction from the README and installed with make install
According to tdlib documentation td_json_client_receive()
and td_json_client_execute()
share control on returned string buffer memory allocation and deallocation:
Returned pointer will be deallocated by TDLib during next call to td_json_client_receive or td_json_client_execute in the same thread, so it can't be used after that.
Returned by those methods string must be consumed (e.g. copied) before next call to td_json_client_receive
or td_json_client_execute
.
Currently Receive
and Execute
go-tdjson
's methods doesn't serialize calls to td_json_client_receive
and td_json_client_execute
methods, which may result in accessing already freed memory.
Here is an proof of concept that this may happen with cgo and go scheduler (I haven't found simple and clear doc stating that this behavior is possible/expected): https://gist.github.com/rutsky/69d7055e64a3080fbb6853b54dcf1cef#file-cgo-go
Output:
$ go version
go version go1.10.1 linux/amd64
$ go run cgo.go
panic: Iteration 39068207 - receive: "y" != "\x00"
goroutine 5 [running]:
main.main.func1()
/home/bob/stuff/go/playground/cgo.go:35 +0x156
created by main.main
/home/bob/stuff/go/playground/cgo.go:28 +0x47
exit status 2
$ go run cgo.go
panic: Iteration 44789915 - execute: "y" != "\xd0"
goroutine 1 [running]:
main.main()
/home/bob/stuff/go/playground/cgo.go:46 +0x16e
exit status 2
$ go run cgo.go
panic: Iteration 1963975 - receive: "y" != "\x00"
goroutine 5 [running]:
main.main.func1()
/home/bob/stuff/go/playground/cgo.go:35 +0x156
created by main.main
/home/bob/stuff/go/playground/cgo.go:28 +0x47
exit status 2
$ go run cgo.go
panic: Iteration 56646123 - execute: "y" != "\xd0"
goroutine 1 [running]:
main.main()
/home/bob/stuff/go/playground/cgo.go:46 +0x16e
exit status 2
$
Hi!
I try to build my simple example using your lib.
But I get this error:
/tmp/___client: error while loading shared libraries: libtdjson.so.1.4.0: cannot open shared object file: No such file or directory
I've installed tdLib into /usr/local by this instruction https://tdlib.github.io/td/build.html?language=Go
this is my /usr/local/lib/:
vs@vs-pc:~$ ls -l /usr/local/lib/
total 377700
drwxr-xr-x 10 root root 4096 авг 12 11:39 cmake
lrwxrwxrwx 1 root root 16 янв 25 2019 libbson-1.0.so -> libbson-1.0.so.0
lrwxrwxrwx 1 root root 20 янв 25 2019 libbson-1.0.so.0 -> libbson-1.0.so.0.0.0
-rw-r--r-- 1 root root 254176 янв 25 2019 libbson-1.0.so.0.0.0
-rw-r--r-- 1 root root 236384 янв 25 2019 libbsoncxx-static.a
-rw-r--r-- 1 root root 399366 янв 25 2019 libbson-static-1.0.a
lrwxrwxrwx 1 root root 18 янв 25 2019 libmongoc-1.0.so -> libmongoc-1.0.so.0
lrwxrwxrwx 1 root root 22 янв 25 2019 libmongoc-1.0.so.0 -> libmongoc-1.0.so.0.0.0
-rw-r--r-- 1 root root 646496 янв 25 2019 libmongoc-1.0.so.0.0.0
-rw-r--r-- 1 root root 1189848 янв 25 2019 libmongoc-static-1.0.a
-rw-r--r-- 1 root root 1387920 янв 25 2019 libmongocxx-static.a
-rw-r--r-- 1 root root 82941288 мая 6 12:51 libprotobuf.a
-rwxr-xr-x 1 root root 976 мая 6 12:51 libprotobuf.la
-rw-r--r-- 1 root root 13223020 мая 6 12:51 libprotobuf-lite.a
-rwxr-xr-x 1 root root 1011 мая 6 12:51 libprotobuf-lite.la
lrwxrwxrwx 1 root root 26 мая 6 12:51 libprotobuf-lite.so -> libprotobuf-lite.so.18.0.1
lrwxrwxrwx 1 root root 26 мая 6 12:51 libprotobuf-lite.so.18 -> libprotobuf-lite.so.18.0.1
-rwxr-xr-x 1 root root 5178240 мая 6 12:51 libprotobuf-lite.so.18.0.1
lrwxrwxrwx 1 root root 21 мая 6 12:51 libprotobuf.so -> libprotobuf.so.18.0.1
lrwxrwxrwx 1 root root 21 мая 6 12:51 libprotobuf.so.18 -> libprotobuf.so.18.0.1
-rwxr-xr-x 1 root root 32565952 мая 6 12:51 libprotobuf.so.18.0.1
-rw-r--r-- 1 root root 123348848 мая 6 12:51 libprotoc.a
-rwxr-xr-x 1 root root 992 мая 6 12:51 libprotoc.la
lrwxrwxrwx 1 root root 19 мая 6 12:51 libprotoc.so -> libprotoc.so.18.0.1
lrwxrwxrwx 1 root root 19 мая 6 12:51 libprotoc.so.18 -> libprotoc.so.18.0.1
-rwxr-xr-x 1 root root 42379352 мая 6 12:51 libprotoc.so.18.0.1
-rw-r--r-- 1 root root 320774 авг 12 11:17 libtdactor.a
-rw-r--r-- 1 root root 209306 авг 12 11:27 libtdclient.a
-rw-r--r-- 1 root root 51701210 авг 12 11:27 libtdcore.a
-rw-r--r-- 1 root root 702368 авг 12 11:17 libtddb.a
-rw-r--r-- 1 root root 4929100 авг 12 11:28 libtdjson_private.a
lrwxrwxrwx 1 root root 18 авг 12 11:39 libtdjson.so -> libtdjson.so.1.4.0
-rw-r--r-- 1 root root 19893432 авг 12 11:28 libtdjson.so.1.4.0
-rw-r--r-- 1 root root 8336 авг 12 11:28 libtdjson_static.a
-rw-r--r-- 1 root root 1420440 авг 12 11:18 libtdnet.a
-rw-r--r-- 1 root root 1788116 авг 12 11:16 libtdsqlite.a
-rw-r--r-- 1 root root 1957448 авг 12 11:17 libtdutils.a
drwxr-xr-x 3 root root 4096 окт 1 2018 node_modules
drwxr-xr-x 2 root root 4096 мая 6 12:51 pkgconfig
drwxrwsr-x 4 root staff 4096 июн 14 09:20 python2.7
drwxrwsr-x 3 root staff 4096 апр 27 2018 python3.6
I have no idea how to fix this problem
Hi @L11R
I'm building the td libraries using this docker file
FROM ubuntu as builder
LABEL Name=tgcli-builer Version=0.0.1
RUN apt-get update
RUN apt-get install build-essential -y
RUN apt-get install libssl-dev -y
RUN apt-get install cmake -y
RUN apt-get install gperf -y
RUN apt-get install zlib1g-dev -y
WORKDIR /
COPY ./td /td
RUN ls
WORKDIR /td
RUN mkdir build
WORKDIR build
RUN cmake ..
RUN cmake --build .
RUN cmake --build . --target install
FROM ubuntu
LABEL Name=tdcli Version=0.0.1
RUN apt-get update
RUN apt-get install libssl1.0.0 -y
RUN apt-get install gperf -y
RUN apt-get install zlib1g -y
COPY --from=builder /usr/local/lib/libtdjson.so /usr/local/lib/libtdjson.so
COPY --from=builder /usr/local/lib/libtdjson_static.a /usr/local/lib/libtdjson_static.a
COPY --from=builder /usr/local/lib/libtdjson_private.a /usr/local/lib/libtdjson_private.a
COPY --from=builder /usr/local/lib/libtdclient.a /usr/local/lib/libtdclient.a
COPY --from=builder /usr/local/lib/libtdcore.a /usr/local/lib/libtdcore.a
COPY --from=builder /usr/local/lib/cmake/Td/TdTargets.cmake /usr/local/lib/cmake/Td/TdTargets.cmake
COPY --from=builder /usr/local/lib/cmake/Td/TdTargets-noconfig.cmake /usr/local/lib/cmake/Td/TdTargets-noconfig.cmake
COPY --from=builder /usr/local/include/td/telegram/td_json_client.h /usr/local/include/td/telegram/td_json_client.h
COPY --from=builder /usr/local/include/td/telegram/td_log.h /usr/local/include/td/telegram/td_log.h
COPY --from=builder /usr/local/include/td/telegram/tdjson_export.h /usr/local/include/td/telegram/tdjson_export.h
COPY --from=builder /usr/local/include/td/telegram/Client.h /usr/local/include/td/telegram/Client.h
COPY --from=builder /usr/local/include/td/telegram/Log.h /usr/local/include/td/telegram/Log.h
COPY --from=builder /usr/local/include/td/tl/TlObject.h /usr/local/include/td/tl/TlObject.h
COPY --from=builder /usr/local/include/td/telegram/td_api.h /usr/local/include/td/telegram/td_api.h
COPY --from=builder /usr/local/include/td/telegram/td_api.hpp /usr/local/include/td/telegram/td_api.hpp
COPY --from=builder /usr/local/lib/cmake/Td/TdConfig.cmake /usr/local/lib/cmake/Td/TdConfig.cmake
COPY --from=builder /usr/local/lib/cmake/Td/TdConfigVersion.cmake /usr/local/lib/cmake/Td/TdConfigVersion.cmake
COPY --from=builder /usr/local/lib/libtdutils.a /usr/local/lib/libtdutils.a
COPY --from=builder /usr/local/lib/libtdactor.a /usr/local/lib/libtdactor.a
COPY --from=builder /usr/local/lib/libtdnet.a /usr/local/lib/libtdnet.a
COPY --from=builder /usr/local/lib/libtdsqlite.a /usr/local/lib/libtdsqlite.a
COPY --from=builder /usr/local/lib/libtddb.a /usr/local/lib/libtddb.a
#Clean
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
The next steps are:
If I compile "hello-world" it works properly in both places. so the architecture is the same.
it's hard to figure out the problem with the only output is "exit status 1"
any idea?
Thanks!
Please add LICENSE file, specifying license under which source code can (or can't) be used.
Hi, Possible to add some documentation along with example code on how to do basic operations like:
I am a beginner with Go and documentation of tdlib is also hard to decipher coming from just PHP/JS background. I understand JSON interface is the only option to interact with it but its hard to understand that without an HTTP context, given my background.
There is no documentation on how tdlib behaves, where authorized sessions are maintained etc either so I don't even know where to began to put both of the projects together to create something meaningful. Trying to read source code to understand alone but the situation feels hopeless. Any pointers to what I should be learning would be appreciated :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.