-
Notifications
You must be signed in to change notification settings - Fork 2.5k
hscan adds support for i386 platform #1652
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
Conversation
Signed-off-by: monkey <[email protected]>
Signed-off-by: monkey <[email protected]>
This looks good. I did not event know Leaving open until tomorrow so @knadh have a chance to look at this. |
Looks good @monkey92t. Suggestion: Instead of separate |
i found other problems: for example: type Temp struct {
ID int8 `redis:"id"`
}
var t Temp
redis 127.0.0.1:6379>>set id 100
err := client.MGet(ctx, "id").Scan(&t)
//success, err = nil、t.ID = 100
//but:
redis 127.0.0.1:6379>>set id 999
err := client.MGet(ctx, "id").Scan(&t)
//err = nil
//error result: t.ID = -25 ??? the user may have unexpected results, |
i plan to convert int8/16/32/64 to int64... |
we should consider using |
Signed-off-by: monkey <[email protected]>
I don't think the errors should be silenced with bools indicating success or failure. You could still incorporate overflow checks and return a new error on that, right? Example: func decodeFloat(f reflect.Value, s string) error {
v, err := strconv.ParseFloat(s, 64)
if err != nil {
return err
}
if f.OverflowFloat(v) {
return errors.New("float overflows")
}
f.SetFloat(v)
return true
} |
I agree that a302f11 does not look right and should be reverted. I think all we need is a separate function for int8, int16 etc that passes the correct bigSize, e.g. func decodeInt8(v reflect.Value, s string) error {
return decodeInt(v, s, 8)
}
func decodeInt16(v reflect.Value, s string) error {
return decodeInt(v, s, 16)
}
func decodeInt(v reflect.Value, s string, bitSize int) error {
n, err := strconv.ParseInt(s, 10, bitSize)
if err != nil {
return err
}
v.SetInt(n)
return nil
} That should handle overflows. |
i did not delete the error, is to concentrate the error on func (s StructValue) Scan(key string, value string) (err error) {
field, ok := s.spec.m[key]
if ok && !field.fn(s.value.Field(field.index), value) {
t := s.value.Type()
err = fmt.Errorf("cannot scan redis.result %s into struct field %s.%s of type %s",
value, t.Name(), t.Field(field.index).Name, t.Field(field.index).Type)
}
return
} |
@monkey92t true, but it is also true that the original error is dropped (which is not nice). |
@vmihailenco yes, i also hesitated, but i think the error message returned by Error Example: redis 127.0.0.1:6379>> set id "abc"
type Temp struct {
ID int `redis:"id"`
}
var t Temp
// before modification, err == `strconv.ParseInt: parsing "abc": invalid syntax`, is a vague reminder to the user
err := client.Mget(ctx, "id").Scan(&t)
// after modification, err == `cannot scan redis.result abc into struct field Temp.ID of type int`, this is good tip
err := client.Mget(ctx, "id").Scan(&t)
|
If you do not change the return value type of exp (field.fn(..) != nil): func (s StructValue) Scan(key string, value string) (err error) {
field, ok := s.spec.m[key]
if ok && field.fn(s.value.Field(field.index), value) != nil {
t := s.value.Type()
err = fmt.Errorf("cannot scan redis.result %s into struct field %s.%s of type %s",
value, t.Name(), t.Field(field.index).Name, t.Field(field.index).Type)
}
return
} if you agree with this approach, i will send a PR to modify the return value type of |
Signed-off-by: monkey <[email protected]>
1efd52d
to
471409c
Compare
i restored the return value of
|
Signed-off-by: monkey <[email protected]>
i adjusted the function according to your opinion, i am used to returning in the end in short functions |
why do i encounter data race test errors many times? |
Signed-off-by: monkey <[email protected]>
We should and I've tried, but without any luck. It looks like there is a race in the conn pool reaper, but I don't understand how that is possible... |
Thanks - looks good 👍 |
@vmihailenco Could you please point to where one could start investigating this? |
set: GOARCH=386
it should run normally on the i386 platform, and there should not be such an error:
strconv.ParseInt: parsing "123456789123456789": value out of range