v
v copied to clipboard
segmentation fault
avey@avey Vlang % v run main.v signal 11: segmentation fault 0 libsystem_platform.dylib 0x00007fff6a4a85fd _sigtramp + 29 1 ??? 0x0000000000000015 0x0 + 21 2 main 0x0000000106bfb12e GC_malloc_kind + 205 3 main 0x0000000106af5096 _v_malloc + 198 4 main 0x0000000106afc650 new_dense_array + 112 5 main 0x0000000106ae3859 new_map + 121 6 main 0x0000000106bbdf8d net__http__new_header + 77 7 main 0x0000000106bc1887 net__http__parse_headers + 135 8 main 0x0000000106bb8f05 net__http__parse_response + 501 9 main 0x0000000106bc6ae1 net__http__Request_http_do + 913 10 main 0x0000000106bc6537 net__http__Request_method_and_url_to_response + 1623 11 main 0x0000000106bc4d24 net__http__Request_do + 1060 12 main 0x0000000106bddf40 main__request + 912 13 main 0x0000000106bdbf9f main__main + 239 14 main 0x0000000106be351c main + 76 15 main 0x0000000106ada9a4 start + 52
import mysql
import net.http
import json
fn main() {
// a := qsqlqueryu('2','5') or {return}
// sqldata := sqlquery('1','10')?
sqldata := mysql_orm('1','2')
// println(sqldata)
// data := '{"id": "6204", "tsin": "SPU000280COEY"}'
mut jsonstr := json.encode(sqldata) //将[]map[string]string 数据类型 编码为 json 数据类型
reponse := request(jsonstr)?
// s := request(data)?
println(reponse)
}
fn request(data string) ?string {
mut req := http.Request{
method: http.Method.post
url: "http://192.168.3.2:7700/indexes/tospinomall/documents"
// data: "{'id': '6204', 'tsin': 'SPU000280COEY'}" // 此样式不可用
// data: '{"id": "6204", "tsin": "SPU000280COEY"}'
data: data
}
req.add_custom_header('Content-Type', 'application/json')?
req.add_custom_header('Authorization', 'Bearer aveyamie')?
reponse := req.do()?
// println("打印req:$reponse")
return reponse.body
}
pub fn sqlquery(startpoint string, numperpage string) ?[]map[string]string {
mut conn := mysql.Connection{
host: '192.168.3.2'
port: 3306
username: 'admin'
password: 'admin'
dbname: 'tospinomall_product'
}
conn.connect()?
// res := conn.query('show tables')?
// mut sqlstr := 'select id,tsin from tospinomall_product.pms_goods_info limit 5'
mut sqlstr := 'select id,id,tsin, good_title,main_picture_url,keyword,good_code,ifnull(seller_id,0),ifnull(shop_id,0),' +
'ifnull(brand_id,0),ifnull(category_id,0),goods_type,ifnull(is_cash_delivery,0),ifnull(delivery_type,0),'+
'transport_mode from tospinomall_product.pms_goods_info limit '+startpoint+','+numperpage
mut res := conn.query(sqlstr)?
// println(res)
mut mapstrlist := []map[string]string{} //创建空数组
for row in res.rows() {
// map的另一种写法
// direct := {
// 'id': row.vals[0]
// 'tsin': row.vals[1]
// }
mut direct := map[string]string{} // a map with `string` keys and `string` values
direct["id"] = row.vals[0]
direct["objectID"] = row.vals[1]
direct["tsin"] = row.vals[2]
direct["good_title"] = row.vals[3]
direct["poster"] = row.vals[4]+ "?.webp" //不增加后缀,meilisearch不显示图片
direct["keyword"] = row.vals[5]
direct["good_code"] = row.vals[6]
direct["seller_id"] = row.vals[7]
direct["shop_id"] = row.vals[8]
direct["brand_id"] = row.vals[9]
direct["category_id"] = row.vals[10]
direct["goods_type"] = row.vals[11]
direct["is_cash_delivery"] = row.vals[12]
direct["delivery_type"] = row.vals[13]
direct["transport_mode"] = row.vals[14]
// println(direct)
mapstrlist << direct //追加direct到mapstrlist 数组
}
conn.close()
return mapstrlist
}
[table: 'pms_goods_info']
struct Module {
id int [primary; sql: serial]
tsin string
good_title string
main_picture_url string
keyword string
good_code string
seller_id int
shop_id int
brand_id int
category_id int
goods_type int
is_cash_delivery int
delivery_type int
transport_mode int
}
fn mysql_orm(startpoint string, numperpage string) []map[string]string {
mut conn := mysql.Connection{
host: '10.243.0.2'
port: 3306
username: 'admin'
password: 'admin'
dbname: 'tospinomall_product'
}
conn.connect() or { panic(err) }
res := sql conn {
select from Module limit startpoint+','+numperpage
}
// eprintln('$row.id')
mut mapstrlist := []map[string]string{} //创建空数组
for row in res {
mut direct := map[string]string{} // a map with `string` keys and `string` values
direct["id"] = '$row.id'
direct["objectID"] = '$row.id'
direct["tsin"] = '$row.tsin'
direct["good_title"] = '$row.good_title'
direct["poster"] = '$row.main_picture_url'+ "?.webp" //不增加后缀,meilisearch不显示图片
direct["keyword"] = '$row.keyword'
direct["good_code"] = '$row.good_code'
direct["seller_id"] = '$row.seller_id'
direct["shop_id"] = '$row.shop_id'
direct["brand_id"] = '$row.brand_id'
direct["category_id"] = '$row.category_id'
direct["goods_type"] = '$row.goods_type'
direct["is_cash_delivery"] = '$row.is_cash_delivery'
direct["delivery_type"] = '$row.delivery_type'
direct["transport_mode"] = '$row.transport_mode'
// println(direct)
mapstrlist << direct //追加direct到mapstrlist 数组
}
// println(mapstrlist)
conn.close()
return mapstrlist
}
Which OS? Which version of V? Which compiler?
This is why the template suggests adding the output from v doctor
at the beginning of your issue...
Can you reproduce it again using a fresh V version? Could you create a shorter reproducible case?
Appears to be fixed - no more segfault:
bug.v:1:1: warning: module `mysql` has been deprecated since 2023-02-01, it will be an error after 2023-07-31; import db.mysql instead
1 | import mysql
| ~~~~~~~~~~~~
2 | import net.http
3 | import json
bug.v:29:59: warning: propagating a Result like an Option is deprecated, use `foo()!` instead of `foo()?`
27 | data: data
28 | }
29 | req.add_custom_header('Content-Type', 'application/json')?
| ^
30 | req.add_custom_header('Authorization', 'Bearer aveyamie')?
31 | reponse := req.do()?
bug.v:30:59: warning: propagating a Result like an Option is deprecated, use `foo()!` instead of `foo()?`
28 | }
29 | req.add_custom_header('Content-Type', 'application/json')?
30 | req.add_custom_header('Authorization', 'Bearer aveyamie')?
| ^
31 | reponse := req.do()?
32 | // println("打印req:$reponse")
bug.v:31:21: warning: propagating a Result like an Option is deprecated, use `foo()!` instead of `foo()?`
29 | req.add_custom_header('Content-Type', 'application/json')?
30 | req.add_custom_header('Authorization', 'Bearer aveyamie')?
31 | reponse := req.do()?
| ^
32 | // println("打印req:$reponse")
33 | return reponse.body
bug.v:44:16: warning: propagating a Result like an Option is deprecated, use `foo()!` instead of `foo()?`
42 | dbname: 'tospinomall_product'
43 | }
44 | conn.connect()?
| ^
45 | // res := conn.query('show tables')?
46 | // mut sqlstr := 'select id,tsin from tospinomall_product.pms_goods_info limit 5'
bug.v:51:31: warning: propagating a Result like an Option is deprecated, use `foo()!` instead of `foo()?`
49 | 'transport_mode from tospinomall_product.pms_goods_info limit '+startpoint+','+numperpage
50 |
51 | mut res := conn.query(sqlstr)?
| ^
52 | // println(res)
53 | mut mapstrlist := []map[string]string{} //创建空数组git/v/vlib/mysql/_cdefs_nix.c.v:9:1: error: Cannot find "mariadb" pkgconfig file
7 | #include <mysql.h> # Please install the libmysqlclient-dev development headers
8 | } $else {
9 | #pkgconfig mariadb
| ~~~~~~~~~~~~~~~~~~~
10 | #include <mysql.h> # Please install the libmariadb-dev development headers
11 | }
git/v/vlib/mysql/orm.v:155:13: error: cannot use `orm.Primitive` as type `int` in return argument
153 | id := db.query(query) or { return 0 }
154 |
155 | return orm.Primitive(id.rows()[0].vals[0].int())
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156 | }
157 |
git/v/vlib/mysql/stmt.c.v:66:24: error: cannot null cast a struct pointer, use &C.MYSQL_STMT(unsafe { nil })
64 |
65 | struct Stmt {
66 | stmt &C.MYSQL_STMT = &C.MYSQL_STMT(0)
| ~~~~~~~~~~~~~~~~
67 | query string
68 | mut:
bug.v:113:28: error: V ORM: the type of `limit` must be an integer type
111 |
112 | res := sql conn {
113 | select from Module limit startpoint+','+numperpage
| ~~~~~~~~~~~~~~~~~~~~~~~~~
114 | }
115 | // eprintln('$row.id')
bug.v:112:9: error: V ORM returns a result, so it should have either an `or {}` block, or `!` at the end
110 | conn.connect() or { panic(err) }
111 |
112 | res := sql conn {
| ~~~~~~~~~~
113 | select from Module limit startpoint+','+numperpage
114 | }