GithubHelp home page GithubHelp logo

aslze / asl Goto Github PK

View Code? Open in Web Editor NEW
66.0 66.0 16.0 1.45 MB

A compact C++ cross-platform library including JSON, XML, HTTP, Sockets, WebSockets, threads, processes, logs, file system, CSV, INI files, etc.

License: Other

CMake 1.21% C++ 98.79%
filesystem http json sockets threads websocket xml

asl's People

Contributors

aslze avatar knavels avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

asl's Issues

HTTPS support is broken

GET to https://httpbin.org/get -> doesn't work
GET to http://devkitpro.org/misc/httpexample_rawimg.rgb -> works
GET to https://devkitpro.org/misc/httpexample_rawimg.rgb -> doesn't work
GET to https://avatars2.githubusercontent.com/u/22228082?s=88&v=4 -> works
POST to http://httpbin.org/post -> works
POST to https://httpbin.org/post -> doesn't work

Can't download GitHub release

Code:

#include <iostream>
#include <asl/Http.h>

int main()
{
    std::cout << asl::Http::get("https://github.com/aslze/asl/releases/download/1.9.3/asl-1.9.3.7z").code() << std::endl;
    return 0;
}

Output:

valentin@pop-os:~/Desktop/notworking$ ./build/notworking 
403

Body says The request signature we calculated does not match the signature you provided

Dynamic library load does not add ".dll" to the library name

I've been using the library in the project and I've noticed that despite mentioned in the documentation and as I've checked in the code the extension at least on windows is not added to the string.

here I've setup a completely fresh example for this:

  • CMakeLists.txt
cmake_minimum_required(VERSION 3.19)
project(dyn_load_test)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(LIB_NAME my_lib)

add_library(${LIB_NAME} SHARED my_lib.cpp)
target_link_libraries(${LIB_NAME} PUBLIC asls)

add_executable(${PROJECT_NAME} loader.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC asls)
  • loader.cpp
// loader.cpp
#include <asl/Library.h>

#include "my_lib.h"
#include <iostream>

int main()
{
        // asl::Library lib("my_lib.dll"); // this works as expected
	asl::Library lib("my_lib"); // this causes lib is not loaded error

	if (!lib.loaded())
	{
		std::cout << "lib is not loaded" << std::endl;
		return -1;
	}

	auto* l = (MyLib*)lib.create("MyLib");

	if (l == nullptr)
	{
		std::cout << "MyLib is not found" << std::endl;
		return -1;
	}

	std::cout << l->get_number() << std::endl;

	delete l;

	return 0;
}
  • my_lib.h
#pragma once

#include "asl/Library.h"

class MyLibBase
{
public:
	virtual int get_number() = 0;
};

class MyLib : public MyLibBase
{
public:
	int get_number() override;
};
  • my_lib.cpp
#include "my_lib.h"

int MyLib::get_number()
{
	return 36;
}

ASL_EXPORT_CLASS(MyLib)

UPDATE:
it seems in Library.h line 132, we need to do like file += "." ASL_LIB_EXT; because we don't have . for sure or change the macros to include . as well.

chars() problem

when String contains any utf8 characters like an emoji or a character from another language chars() works as expected, but when String contains only ascii characters, calling chars() causes the following error, and it seems it has something related to memory clean up or in the destructor.

the error: HEAP CORRUPTION DETECTED: after Normal block (....) at .........
CRT detected that the application wrote to memory after end of heap buffer.
	asl::String a("a__01");

	auto c = a.chars();
	std::cout << c.length() << std::endl;
	std::cout << a.count() << std::endl;
//	for (int i{0}; i < a.count(); ++i)
//		std::cout << c[i] << std::endl;
        std::getchar();

this code for example, this works until pressing a key, and what happens after is just destructing c and a.
I'm checking this line int n = utf8toUtf32(str(), c.ptr(), 1); that I think it might be this.

question: printing out single character

when iterating in an asl::String using a for (auto& character : my_text) loop a codepoint for each character is received, to print that individual character I came up with this code, is there any missing feature or shorter way or it's just fine?

asl::String code_point_to_utf8(int codePoint)
{
	std::string utf8;
	if (codePoint <= 0x7F)
	{
		utf8 += static_cast<char>(codePoint);
	}
	else if (codePoint <= 0x7FF)
	{
		utf8 += static_cast<char>((codePoint >> 6) | 0xC0);
		utf8 += static_cast<char>((codePoint & 0x3F) | 0x80);
	}
	else if (codePoint <= 0xFFFF)
	{
		utf8 += static_cast<char>((codePoint >> 12) | 0xE0);
		utf8 += static_cast<char>(((codePoint >> 6) & 0x3F) | 0x80);
		utf8 += static_cast<char>((codePoint & 0x3F) | 0x80);
	}
	else if (codePoint <= 0x10FFFF)
	{
		utf8 += static_cast<char>((codePoint >> 18) | 0xF0);
		utf8 += static_cast<char>(((codePoint >> 12) & 0x3F) | 0x80);
		utf8 += static_cast<char>(((codePoint >> 6) & 0x3F) | 0x80);
		utf8 += static_cast<char>((codePoint & 0x3F) | 0x80);
	}
	return utf8;
}

well this works fine with both asl::String and std::string.

A broken ini file causes segfaults when read with write parameter set

Hello, if I create an .ini file like this:

[phase1]
loglevel=1
inputfilename=common/myfile.txt
asasjdh
[phase2]
listno=7
dumbchoices=YES

The string "asasjdh" generates a memory corruption with an unrecoverable segfault out of the .cpp unit which reads it...
Reading the file like this:

IniFile config(finalConfigFile, false);

gives no problems whatsoever, but if read with writing option set:

IniFile config(finalConfigFile, true);

the segfault breaks the unit when it returns to the caller.
HTH

add method for Dic<Var>, adds to other Dic...

Hi, I saw something that I think is an undefined behavior.
imagine this:

struct info {
    Dic<Var> prop{};
    int number{0};
};

std::map<int, info> information = {
    /* it has a bunch of information */
};

information[2].prop.add({"some_key", "value"});

I saw this caused problem in Array.h that is from add function in Map. what I observed is one of these adds has added the given Dic to another member of the std::map if that make sense. which causes other calling add for the other member to fail with undefined behavior and memory problem.

other information is that the keys in the information are built from code points of a String characters.
I tested the count and number are correct.

I've no clue for more debugging, but am open to contribute and/or any task or help that you may need.

Map join doesn't getting applied to the levels

consider an Object is Dic<Var> that naturally can have other Objects or Array<Object> as well inside
when I use join on the top level and let's say I want ", " and " : " it won't make any difference to the nested objects and it will use the default "," and "=" instead.

P.S. to print out the Object I can use Json::encode which is fine, in some cases join characters might be completely different based on usecases.

Build errors

macOS:

/Users/travis/build/valentinvanelslande/citra/externals/asl/src/Directory.cpp:266:35: error: use of undeclared identifier 'PATH_MAX'
        char* d = getcwd(SafeString(dir, PATH_MAX), PATH_MAX);
                                         ^
/Users/travis/build/valentinvanelslande/citra/externals/asl/src/Directory.cpp:266:46: error: use of undeclared identifier 'PATH_MAX'
        char* d = getcwd(SafeString(dir, PATH_MAX), PATH_MAX);

Compiling for Windows on Linux:

/citra/externals/asl/src/Socket.cpp:6:10: fatal error: WinSock2.h: No such file or directory
 #include <WinSock2.h>
          ^~~~~~~~~~~~
compilation terminated.

Converting String to std::string

Hello, first of all thanks for this very useful library...
I hava a cmd line input param which I need to feed to another library. This library takes std::string type for the parameter. How can I convert asl::String to std::string?
I've checked the String.h code but cannot find a method.
Thank you

Duplicating parameters with CmdArgs results in segfault

Not sure if can be considered an error. Anyway...
Insert a cmdline param two times crashes the app:

> test/at3d -cf config/readmesh.ini -cf data/checkmesh/cubeandisolatedvertex.obj
> Error reading test/at3d.ini
> Error reading /Users/max/Developer/Stage/Workspace/AutoTools3D/config/at3d.ini
> Reading data/checkmesh/cubeandisolatedvertex.obj
> =================================================================
> ==15094==ERROR: AddressSanitizer: negative-size-param: (size=-1)
>     #0 0x10f642f00 in wrap_memcpy (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x1df00)
>     #1 0x114e5da07 in asl::String::substring(int, int) const String.cpp:444
>     #2 0x10f49a281 in asl::IniFile::write(asl::String const&) IniFile.cpp:121
>     #3 0x10f49b252 in asl::IniFile::~IniFile() IniFile.cpp:201
>     #4 0x10f44a054 in Client::execute(asl::CmdArgs&) Client.hpp:89
>     #5 0x10f449712 in main Test.cpp:22
>     #6 0x7fff5ae0eed8 in start (libdyld.dylib:x86_64+0x16ed8)
> 
> 0x6030000004c0 is located 0 bytes inside of 29-byte region [0x6030000004c0,0x6030000004dd)
> allocated by thread T0 here:
>     #0 0x10f681053 in wrap_malloc (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x5c053)
>     #1 0x114e5c2ce in asl::String::alloc(int) String.cpp:290
>     #2 0x10f49f26b in asl::Array<asl::String>::insert(int, asl::String const&) String.h:121
>     #3 0x10f498eb7 in asl::IniFile::IniFile(asl::String const&, bool) Array.h:279
>     #4 0x10f449ede in Client::execute(asl::CmdArgs&) Client.hpp:79
>     #5 0x10f449712 in main Test.cpp:22
>     #6 0x7fff5ae0eed8 in start (libdyld.dylib:x86_64+0x16ed8)
> 
> SUMMARY: AddressSanitizer: negative-size-param (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x1df00) in wrap_memcpy
> ==15094==ABORTING
> Abort trap: 6

here's the culprit code:

    bool execute(CmdArgs &args)
    {
     .
     .
     .
        // cmdline overwrite for config
        if (args.has("cf"))
        {
            String configFile = args["cf"];
            IniFile checkconfig(configFile); -> line 79
            if (checkconfig.ok())
            {
                finalConfigFile = configFile;
                printf("Reading %s\n", *checkconfig.fileName());
            }
            else
            {
                printf("Error reading %s\n", *checkconfig.fileName());
            }
        } -> line 89

HTH

SocketServer can be destroyed before SockClientThread workers ends

There is no way to check if any SockClientThread is still working before destroying a SocketServer. The running() method only checks that the main loop of the server thread has been stoped after calling stop(), but a SockClientThread may be still working. If the server is destroyed with a SockClientThread it will SEGFAULT. A method to check that every SockClientThread has finished will be valuable in order to shutdown a server safely.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.