Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TupleHelper and SelectHelper to improve SWIG Go wrapper. #862

Conversation

liuh-80
Copy link
Contributor

@liuh-80 liuh-80 commented Mar 12, 2024

Why I did it

SWIG not support std::tuple, also not support C++ inheritance well, this make go wrapper method of select and pops method does not work.

How I did it

Add TupleHelper and SelectHelper to improve SWIG Go wrapper.

Work item tracking
  • Microsoft ADO: 26731929

How to verify it

Pass all test cases.
Add new test case.

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111

Description for the changelog

Add TupleHelper and SelectHelper to improve SWIG Go wrapper.

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@liuh-80 liuh-80 marked this pull request as ready for review March 12, 2024 09:04
@liuh-80 liuh-80 requested a review from qiluo-msft March 12, 2024 09:04
@liuh-80 liuh-80 changed the title Add GO wrapper for ConfigDBConnector Add Go wrapper for ConfigDBConnector Mar 12, 2024
@liuh-80 liuh-80 changed the title Add Go wrapper for ConfigDBConnector Add SWIG Go wrapper for ConfigDBConnector Mar 12, 2024
@liuh-80 liuh-80 changed the title Add SWIG Go wrapper for ConfigDBConnector Add TupleHelper and SelectHelper to improve SWIG Go wrapper. Mar 19, 2024
@@ -0,0 +1,28 @@
#ifndef __TUPLE_HELPER__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra blank

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

return kfvOp(tuple);
}

std::vector<FieldValueTuple> TupleHelper::getFieldsValues(const KeyOpFieldsValuesTuple& tuple)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vector

Constructing this return object is heavy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, return reference

return fvValue(tuple);
}

std::string TupleHelper::getKey(const KeyOpFieldsValuesTuple& tuple)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getKey

I guess the original kfvKey macro could not easily transformed by SWIG. If yes, recommend to change kfvKey to an inline function, instead of defining new class/functions.

Copy link
Contributor Author

@liuh-80 liuh-80 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SWIG does not generate wrapper for C++ macro.

We can't change macros to method, because there are code like this:
https://github.com/sonic-net/sonic-swss-common/blob/master/common/json.cpp

                kfvKey(cur_db_item) = cur_obj_key;
                kfvOp(cur_db_item) = op;

Similer code are in some other projects:

https://github.com/sonic-net/sonic-wpa-supplicant/blob/13e6f11007d3e6d33a514a702fea5d40daaad055/src/drivers/sonic_operators.cpp#L97

@@ -73,6 +73,27 @@ class Select
std::set<Selectable *, Select::cmp> m_ready;
};

class SelectHelper
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SelectHelper

Why we need a new class? Can SWIG just transform old class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this new class because SWIG can't handle pointer to pointer parameter:

int Select::select(**Selectable **c,** int timeout = -1, bool interrupt_on_signal = false);

We need this helper class handle the pointer to pointer parameter in C++ code.

@liuh-80
Copy link
Contributor Author

liuh-80 commented Mar 21, 2024

Close because Go wrapper still need improve. the change for GNMI support will create new PR.

@liuh-80 liuh-80 closed this Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants