-
Notifications
You must be signed in to change notification settings - Fork 20
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
Filterx add object str method #516
base: main
Are you sure you want to change the base?
Conversation
2cee8b1
to
3ead54f
Compare
@@ -195,10 +195,15 @@ _filterx_ref_repr(FilterXObject *s, GString *repr) | |||
{ | |||
FilterXRef *self = (FilterXRef *) s; | |||
|
|||
if (self->value->type->repr) | |||
return self->value->type->repr(self->value, repr); | |||
return filterx_object_repr(self->value, repr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks append()
, because filterx_object_repr()
truncates the string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have called this function _filterx_ref_repr_append
to avoid future mistakes.
(The vtable pointer should also be called append
, but that would look ugly.)
{ | ||
FilterXRef *self = (FilterXRef *) s; | ||
|
||
return filterx_object_str(self->value, str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should call the virtual method directly to avoid the truncation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we fix my original mistake and call it _filterx_ref_str_append
?
if (!object) | ||
return NULL; | ||
|
||
GString *buf = scratch_buffers_alloc(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is this reclaimed? Shouldn't we do it here just to be sure?
@@ -195,10 +195,15 @@ _filterx_ref_repr(FilterXObject *s, GString *repr) | |||
{ | |||
FilterXRef *self = (FilterXRef *) s; | |||
|
|||
if (self->value->type->repr) | |||
return self->value->type->repr(self->value, repr); | |||
return filterx_object_repr(self->value, repr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have called this function _filterx_ref_repr_append
to avoid future mistakes.
(The vtable pointer should also be called append
, but that would look ugly.)
{ | ||
FilterXRef *self = (FilterXRef *) s; | ||
|
||
return filterx_object_str(self->value, str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we fix my original mistake and call it _filterx_ref_str_append
?
Just like Python, sometimes we want to turn an object into a string to add it to trace messages (repr) indended to the developer, in other cases we want a simpler string representation aimed at customers (str). This patch adds str() in addition to the existing repr(). If str() is not implemented it defaults to using repr, so defaults doing the same as today. Signed-off-by: Balazs Scheidler <[email protected]>
Signed-off-by: Balazs Scheidler <[email protected]>
Signed-off-by: Balazs Scheidler <[email protected]>
Signed-off-by: Balazs Scheidler <[email protected]>
Signed-off-by: Balazs Scheidler <[email protected]>
Signed-off-by: Balazs Scheidler <[email protected]>
str() is a UNIX timestamp since epoch, including fractions of a digits, but no timezone. repr() remains an ISO date so that logs are easier to read. Signed-off-by: Balazs Scheidler <[email protected]>
Signed-off-by: Balazs Scheidler <[email protected]>
Signed-off-by: Balazs Scheidler <[email protected]>
3ead54f
to
7d9a701
Compare
This branch separates repr() and str() methods for objects. This works similarly to Python.
The goal of this patch is to resolve an issue around datetime, which is formatted differently when embedded in a JSON (where map_to_json is used) and when formatted using format_json (where repr is used).
The branch also changes a number of call sites to use str() instead of repr(). Convention is:
By default, str == repr so the formats can be the same.