diff --git a/examples/C/src/mqtt/include/mosquitto-extension.cmake b/examples/C/src/mqtt/include/mosquitto-extension.cmake index 3f31ad91..5fc4473d 100644 --- a/examples/C/src/mqtt/include/mosquitto-extension.cmake +++ b/examples/C/src/mqtt/include/mosquitto-extension.cmake @@ -34,4 +34,4 @@ mark_as_advanced(MOSQUITTO_INCLUDE_DIR MOSQUITTO_LIBRARY) ######## include_directories(/usr/local/include) -target_link_libraries(${LF_MAIN_TARGET} ${MOSQUITTO_LIBRARY}) +target_link_libraries(${LF_MAIN_TARGET} PRIVATE ${MOSQUITTO_LIBRARY}) diff --git a/examples/C/src/mqtt/include/paho-extension.cmake b/examples/C/src/mqtt/include/paho-extension.cmake index 339cb995..bcaf3e75 100644 --- a/examples/C/src/mqtt/include/paho-extension.cmake +++ b/examples/C/src/mqtt/include/paho-extension.cmake @@ -46,4 +46,4 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(PahoMqttC ######## include_directories(${PAHO_MQTT_C_INCLUDE_DIRS}) -target_link_libraries(${LF_MAIN_TARGET} ${PAHO_MQTT_C_LIBRARIES}) +target_link_libraries(${LF_MAIN_TARGET} PRIVATE ${PAHO_MQTT_C_LIBRARIES}) diff --git a/examples/C/src/mqtt/lib/MQTTTestReactors.lf b/examples/C/src/mqtt/lib/MQTTTestReactors.lf index 7744e21d..9a62f804 100644 --- a/examples/C/src/mqtt/lib/MQTTTestReactors.lf +++ b/examples/C/src/mqtt/lib/MQTTTestReactors.lf @@ -28,11 +28,12 @@ reactor MessageGenerator(root: string = "", period: time = 1 sec) { reaction(t) -> message {= // With NULL, 0 arguments, snprintf tells us how many bytes are needed. // Add one for the null terminator. - int length = snprintf(NULL, 0, "%s %d", self->root, self->count) + 1; + size_t length = snprintf(NULL, 0, "%s %d", self->root, self->count) + 1; // Dynamically allocate memory for the output. - SET_NEW_ARRAY(message, length); + char* buffer = (char*)malloc(length); // Populate the output string and increment the count. - snprintf(message->value, length, "%s %d", self->root, self->count++); + snprintf(buffer, length, "%s %d", self->root, self->count++); + lf_set_array(message, buffer, length); tag_t tag = lf_tag(); lf_print("MessageGenerator: At (elapsed) tag " PRINTF_TAG ", publish message: %s", tag.time - lf_time_start(), tag.microstep, diff --git a/examples/CCpp/ROS/src/ROSSerialization.lf b/examples/CCpp/ROS/src/ROSSerialization.lf index c5324a82..168b0a76 100644 --- a/examples/CCpp/ROS/src/ROSSerialization.lf +++ b/examples/CCpp/ROS/src/ROSSerialization.lf @@ -45,13 +45,16 @@ reactor Clock(offset: time = 0, period: time = 1 sec) { auto message_header_length = 8u; auto message_payload_length = 10u; + // The following allocates memory for serialization. The memory will later be + // freed by the LF token management scheme. + // TODO: Should this also call release_rcl_serialized_message()?? + // Otherwise, there is risk of a double free? self->serialized_msg->reserve(message_header_length + message_payload_length); static rclcpp::Serialization serializer_obj; serializer_obj.serialize_message(msg.get(), self->serialized_msg); - SET_NEW_ARRAY(y, self->serialized_msg->size()); - y->value = self->serialized_msg->get_rcl_serialized_message().buffer; + lf_set_array(y, self->serialized_msg->get_rcl_serialized_message().buffer, self->serialized_msg->size()); =} } diff --git a/examples/CCpp/ROS/src/include/CMakeListsExtension.txt b/examples/CCpp/ROS/src/include/CMakeListsExtension.txt index 2caddb8b..2a826f52 100644 --- a/examples/CCpp/ROS/src/include/CMakeListsExtension.txt +++ b/examples/CCpp/ROS/src/include/CMakeListsExtension.txt @@ -6,4 +6,4 @@ find_package(rmw REQUIRED) find_package(sensor_msgs REQUIRED) find_package(std_msgs REQUIRED) -ament_target_dependencies( ${LF_MAIN_TARGET} rclcpp sensor_msgs std_msgs rmw) \ No newline at end of file +ament_target_dependencies( ${LF_MAIN_TARGET} PUBLIC rclcpp sensor_msgs std_msgs rmw)