Giter Club home page Giter Club logo

xtypes's People

Contributors

franava avatar jamoralp avatar lauramg15 avatar lemunozm avatar miguelbarro avatar richiware avatar russkel avatar

Stargazers

 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  avatar  avatar  avatar

xtypes's Issues

xtypes not compiling due to `basic_string(nullptr_t) = delete;` in C++23

Hello,

I am using xtypes in a library where I have used a certain amount of C++23 features. When compiling I ran into a header issue (PR incoming) and this trickier issue:

In file included from /home/work/ws/install/xtypes/include/xtypes/StringType.hpp:22,
                 from /home/work/ws/install/xtypes/include/xtypes/xtypes.hpp:24,
                 from /home/work/ws/install/nmea0183reader/include/nmea0183reader/definition_plugin.hpp:5,
                 from /home/work/ws/src/nmea0183_lib/include/nmea0183_lib/converters.hpp:6,
                 from /home/work/ws/src/nmea0183_lib/src/xtypes_structs.cpp:4:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp: In instantiation of ‘void eprosima::xtypes::PrimitiveType<T>::construct_instance(uint8_t*) const [with T = std::__cxx11::basic_string<char16_t>; uint8_t = unsigned char]’:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:117:18:   required from here
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:120:43: error: use of deleted function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::nullptr_t) [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>; std::nullptr_t = std::nullptr_t]’
  120 |         *reinterpret_cast<T*>(instance) = T(0);
      |                                           ^~~~
In file included from /usr/include/c++/12/string:53,
                 from /usr/include/c++/12/bits/locale_classes.h:40,
                 from /usr/include/c++/12/bits/ios_base.h:41,
                 from /usr/include/c++/12/ios:42,
                 from /usr/include/c++/12/ostream:38,
                 from /usr/include/c++/12/iostream:39,
                 from /home/work/ws/install/xtypes/include/xtypes/Assert.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/DynamicType.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/CollectionType.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/ArrayType.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/xtypes.hpp:23:
/usr/include/c++/12/bits/basic_string.h:742:7: note: declared here
  742 |       basic_string(nullptr_t) = delete;
      |       ^~~~~~~~~~~~
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp: In instantiation of ‘void eprosima::xtypes::PrimitiveType<T>::construct_instance(uint8_t*) const [with T = std::__cxx11::basic_string<wchar_t>; uint8_t = unsigned char]’:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:117:18:   required from here
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:120:43: error: use of deleted function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::nullptr_t) [with _CharT = wchar_t; _Traits = std::char_traits<wchar_t>; _Alloc = std::allocator<wchar_t>; std::nullptr_t = std::nullptr_t]’
  120 |         *reinterpret_cast<T*>(instance) = T(0);
      |                                           ^~~~
/usr/include/c++/12/bits/basic_string.h:742:7: note: declared here
  742 |       basic_string(nullptr_t) = delete;
      |       ^~~~~~~~~~~~
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp: In instantiation of ‘void eprosima::xtypes::PrimitiveType<T>::construct_instance(uint8_t*) const [with T = std::__cxx11::basic_string<char>; uint8_t = unsigned char]’:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:117:18:   required from here
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:120:43: error: use of deleted function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::nullptr_t) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::nullptr_t = std::nullptr_t]’
  120 |         *reinterpret_cast<T*>(instance) = T(0);
      |                                           ^~~~
/usr/include/c++/12/bits/basic_string.h:742:7: note: declared here
  742 |       basic_string(nullptr_t) = delete;
      |       ^~~~~~~~~~~~
In file included from /home/work/ws/install/xtypes/include/xtypes/StringType.hpp:22,
                 from /home/work/ws/install/xtypes/include/xtypes/xtypes.hpp:24,
                 from /home/work/ws/install/nmea0183reader/include/nmea0183reader/definition_plugin.hpp:5,
                 from /home/work/ws/src/nmea0183_lib/include/nmea0183_lib/converters.hpp:6,
                 from /home/work/ws/src/nmea0183_lib/src/converters_ref.cpp:5:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp: In instantiation of ‘void eprosima::xtypes::PrimitiveType<T>::construct_instance(uint8_t*) const [with T = std::__cxx11::basic_string<char16_t>; uint8_t = unsigned char]’:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:117:18:   required from here
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:120:43: error: use of deleted function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::nullptr_t) [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>; std::nullptr_t = std::nullptr_t]’
  120 |         *reinterpret_cast<T*>(instance) = T(0);
      |                                           ^~~~
In file included from /usr/include/c++/12/string:53,
                 from /usr/include/c++/12/bits/locale_classes.h:40,
                 from /usr/include/c++/12/bits/ios_base.h:41,
                 from /usr/include/c++/12/ios:42,
                 from /usr/include/c++/12/ostream:38,
                 from /usr/include/c++/12/iostream:39,
                 from /home/work/ws/install/xtypes/include/xtypes/Assert.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/DynamicType.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/CollectionType.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/ArrayType.hpp:21,
                 from /home/work/ws/install/xtypes/include/xtypes/xtypes.hpp:23:
/usr/include/c++/12/bits/basic_string.h:742:7: note: declared here
  742 |       basic_string(nullptr_t) = delete;
      |       ^~~~~~~~~~~~
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp: In instantiation of ‘void eprosima::xtypes::PrimitiveType<T>::construct_instance(uint8_t*) const [with T = std::__cxx11::basic_string<wchar_t>; uint8_t = unsigned char]’:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:117:18:   required from here
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:120:43: error: use of deleted function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::nullptr_t) [with _CharT = wchar_t; _Traits = std::char_traits<wchar_t>; _Alloc = std::allocator<wchar_t>; std::nullptr_t = std::nullptr_t]’
  120 |         *reinterpret_cast<T*>(instance) = T(0);
      |                                           ^~~~
/usr/include/c++/12/bits/basic_string.h:742:7: note: declared here
  742 |       basic_string(nullptr_t) = delete;
      |       ^~~~~~~~~~~~
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp: In instantiation of ‘void eprosima::xtypes::PrimitiveType<T>::construct_instance(uint8_t*) const [with T = std::__cxx11::basic_string<char>; uint8_t = unsigned char]’:
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:117:18:   required from here
/home/work/ws/install/xtypes/include/xtypes/PrimitiveType.hpp:120:43: error: use of deleted function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::nullptr_t) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::nullptr_t = std::nullptr_t]’
  120 |         *reinterpret_cast<T*>(instance) = T(0);
      |                                           ^~~~
/usr/include/c++/12/bits/basic_string.h:742:7: note: declared here
  742 |       basic_string(nullptr_t) = delete;
      |       ^~~~~~~~~~~~

I am hoping this isn't that difficult to fix, do I have to modify these particular types to construct empty strings instead? It looks like it wasn't valid to begin with, if I simply try to construct a string with nullptr in C++20:

Program returned: 139
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string: construction from null is not valid
Program terminated with signal: SIGSEGV

I am not sure where T is being set to a basic_string because that shouldn't be a valid type for a PrimitiveType? The compiler was being no help in finding it.

Seg Fault Copying xtypes::DynamicData

My first attempt to use this library failed. Here is a simple program that reproduces the failure.

#include <iostream>
#include <string>
#include "xtypes/xtypes.hpp"

using namespace eprosima;

xtypes::DynamicData getTestEnum()
{
    xtypes::EnumerationType<uint32_t> testEnum("TestEnum");
    testEnum.add_enumerator("item0");
    testEnum.add_enumerator("item1");
    testEnum.add_enumerator("item2");
    xtypes::DynamicData test(testEnum);
    std::cout << "Looks good here: " << test.to_string();

    xtypes::DynamicData test2(test);
    std::cout << "Here too: " << test2.to_string();
    return test;
}

int main()
{
    xtypes::DynamicData testData(getTestEnum());
    std::cout << "Seg Faults here: " << testData.to_string();
    return 0;
}

backtrace:

>&"bt\n"
>~"#0  0x000055555555c727 in eprosima::xtypes::ReadableDynamicDataRef::for_each(std::function<void (eprosima::xtypes::ReadableDynamicDataRef::ReadableNode const&)>) const (this=0x7fffffffe590, visitor=...) at /home/kyle/VGB/eprosima_xtypes/include/xtypes/DynamicData.hpp:407\n"
>~"#1  0x000055555555e141 in eprosima::xtypes::ReadableDynamicDataRef::to_string[abi:cxx11]() const (this=0x7fffffffe590) at /home/kyle/VGB/eprosima_xtypes/include/xtypes/DynamicDataImpl.hpp:124\n"
>~"#2  0x000055555555b237 in main () at /home/kyle/VGB/XtypesTest/main.cpp:24\n"
>2322^done

Segfault when setting an empty string

This is causing a segfault with GCC 13 and C++23

TEST (StructType, copying_a_structure)
{
    StructType my_struct("MyStruct");
//    my_struct.add_member("str", StringType());
    my_struct.add_member("str", primitive_type<std::string>());

    DynamicData data(my_struct);
    data["str"] = "";
}
Program received signal SIGSEGV, Segmentation fault.
0x00005555555e6cd3 in std::char_traits<char>::assign (__c1=<error reading variable: Cannot access memory at address 0x0>, __c2=@0x7fffffffb947: 0x0) at /usr/include/c++/12/bits/char_traits.h:358

[#0] 0x5555555e6cd3 → std::char_traits<char>::assign(__c1=@0x0, __c2=@0x7fffffffb947)
[#1] 0x5555555e8db4 → std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_set_length(this=0x55555578d6e6, __n=0x0)
[#2] 0x5555556243ba → std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(this=0x55555578d6e6, __str="")
[#3] 0x55555560fa71 → std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign(this=0x55555578d6e6, __str="")
[#4] 0x5555555fbb91 → std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(this=0x55555578d6e6, __str="")
[#5] 0x55555568ba21 → eprosima::xtypes::PrimitiveType<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::copy_instance(this=0x55555578d430, target=0x55555578d6e6 "", source=0x7fffffffc170 "\200\301\377\377\377\177")
[#6] 0x7ffff7f721df → eprosima::xtypes::WritableDynamicDataRef::value<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void>(this=0x7fffffffc120, t="")
[#7] 0x7ffff7f6f677 → eprosima::xtypes::WritableDynamicDataRef::operator=(this=0x7fffffffc120, other="")

Annotations from idl parser

The eprosima::xtypes::Member has support for id, key and optional annotations, which can be set using the xtypes API.
Currently, it seems the IDL parser do not parse annotations. Is it possible to slightly extend the grammar or the IDL parser implementation, so that the three annotations above are recognized when parsing IDL files?

  std::string my_idl = R"~~~(
    struct Inner
    {
        @key uint32 my_uint32;
        @optional boolean yes;
    };
  )~~~";

  eprosima::xtypes::idl::Context context = eprosima::xtypes::idl::parse(my_idl);

  // Create struct same with xtypes API
  eprosima::xtypes::StructType inner2 =
   eprosima::xtypes::StructType("Inner")
   .add_member(eprosima::xtypes::Member("my_uint32", eprosima::xtypes::primitive_type<uint32_t>()).key())
   .add_member(eprosima::xtypes::Member("yes", eprosima::xtypes::primitive_type<bool>()).optional());

  auto inner = context.module().structure("Inner");

  EXPECT_EQ(inner.member(0).is_key(), inner2.member(0).is_key());           // false, true
  EXPECT_EQ(inner.member(1).is_optional(), inner2.member(1).is_optional()); // false, true

Errors when trying to compile with -std=gnu++20

I came across these when trying to compile xtypes components when using it in a project that is C++20 on gcc 11:

https://github.com/eProsima/xtypes/blob/main/include/xtypes/DynamicDataImpl.hpp#L145

xtypes/include/xtypes/DynamicDataImpl.hpp:145:49: error: overload resolution selected deleted operator '<<' [clang-diagnostic-error]
                ss << "<" << type_name << ">  " << node.data().value<char16_t>();

https://github.com/eProsima/xtypes/blob/main/include/xtypes/StringType.hpp#L112

xtypes/include/xtypes/StringType.hpp:112:70: error: use 'template' keyword to treat 'basic_string' as a dependent template name [clang-diagnostic-error]
        reinterpret_cast<std::basic_string<CHAR_T>*>(instance)->std::basic_string<CHAR_T>::~basic_string<CHAR_T>();

SIGABRT when directly accessing value of float from member

I am compiling using C++20 on GCC 11:

Simple Structure definition:

    StructType msg("Msg");
    msg.add_member("latitude", primitive_type<float>());
    msg.add_member("longitude", primitive_type<float>());

This is inside a Catch2 test case:

// Works
  REQUIRE(msg["latitude"].value<float>() == Approx(-11.11293));

// SIGABRT
  REQUIRE(msg["latitude"] == Approx(-11.11293));

I believe this should error at compile time if it doesn't know what the return type is going to be.

Is it supposed to work with any os and compilers?

hi, I downloaded this library and tried to compile in windows environment with LLVM Clang 11 compiler but I got some issue due to linux environment specific inclusions (e.g. execinfo.h). Is this library meant to work in every operating system or is it linux specific?

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.