Skip to content

Commit

Permalink
fix(go/adbc/pkg): clean up potential sites where Go GC may be exposed (
Browse files Browse the repository at this point in the history
…#1942)

Related to #1931.
  • Loading branch information
lidavidm authored Jun 27, 2024
1 parent e58987e commit 576f716
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 16 deletions.
11 changes: 8 additions & 3 deletions go/adbc/drivermgr/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package drivermgr
// #endif
// #include "adbc.h"
// #include <stdlib.h>
// #include <string.h>
//
// void releaseErr(struct AdbcError* err) {
// if (err->release != NULL) {
Expand All @@ -34,11 +35,15 @@ package drivermgr
// }
// }
// struct ArrowArray* allocArr() {
// return (struct ArrowArray*)malloc(sizeof(struct ArrowArray));
// struct ArrowArray* array = (struct ArrowArray*)malloc(sizeof(struct ArrowArray));
// memset(array, 0, sizeof(struct ArrowArray));
// return array;
// }
//
// struct ArrowArrayStream* allocArrStream() {
// return (struct ArrowArrayStream*)malloc(sizeof(struct ArrowArrayStream));
// struct ArrowArrayStream* stream = (struct ArrowArrayStream*)malloc(sizeof(struct ArrowArrayStream));
// memset(stream, 0, sizeof(struct ArrowArrayStream));
// return stream;
// }
//
import "C"
Expand Down Expand Up @@ -84,7 +89,7 @@ func (d Driver) NewDatabase(opts map[string]string) (adbc.Database, error) {
}

var err C.struct_AdbcError
db.db = (*C.struct_AdbcDatabase)(unsafe.Pointer(C.malloc(C.sizeof_struct_AdbcDatabase)))
db.db = (*C.struct_AdbcDatabase)(unsafe.Pointer(C.calloc(C.sizeof_struct_AdbcDatabase, C.size_t(1))))
if code := adbc.Status(C.AdbcDatabaseNew(db.db, &err)); code != adbc.StatusOK {
return nil, toAdbcError(code, &err)
}
Expand Down
6 changes: 3 additions & 3 deletions go/adbc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module github.com/apache/arrow-adbc/go/adbc
go 1.21

require (
github.com/apache/arrow/go/v17 v17.0.0-20240520131450-cc3e2db30094
github.com/apache/arrow/go/v17 v17.0.0-20240626234237-6680dcfbef42
github.com/bluele/gcache v0.0.2
github.com/golang/protobuf v1.5.4
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -71,8 +71,8 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/asmfmt v1.3.2 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go/adbc/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/apache/arrow/go/v15 v15.0.2 h1:60IliRbiyTWCWjERBCkO1W4Qun9svcYoZrSLcyOsMLE=
github.com/apache/arrow/go/v15 v15.0.2/go.mod h1:DGXsR3ajT524njufqf95822i+KTh+yea1jass9YXgjA=
github.com/apache/arrow/go/v17 v17.0.0-20240520131450-cc3e2db30094 h1:DnkS2LPX69st/7BvQVwtGUcLR9RTkrVrdlYnMm89AxY=
github.com/apache/arrow/go/v17 v17.0.0-20240520131450-cc3e2db30094/go.mod h1:GLRwak999pJQN7WbKiL5F6OOOq046IOQ/HduXhjTaUo=
github.com/apache/arrow/go/v17 v17.0.0-20240626234237-6680dcfbef42 h1:aIUzo1mgqqb3LJPDQmTdoXEqcZww1E7ilfUmH44IbEI=
github.com/apache/arrow/go/v17 v17.0.0-20240626234237-6680dcfbef42/go.mod h1:jR7QHkODl15PfYyjM2nU+yTLScZ/qfj7OSUZmJ8putc=
github.com/apache/thrift v0.20.0 h1:631+KvYbsBZxmuJjYwhezVsrfc/TbqtZV4QcxOX1fOI=
github.com/apache/thrift v0.20.0/go.mod h1:hOk1BQqcp2OLzGsyVXdfMk7YFlMxK3aoEVhjD06QhB8=
github.com/aws/aws-sdk-go-v2 v1.27.0 h1:7bZWKoXhzI+mMR/HjdMx8ZCC5+6fY0lS5tr0bbgiLlo=
Expand Down Expand Up @@ -103,10 +103,10 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGw
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/klauspost/asmfmt v1.3.2 h1:4Ri7ox3EwapiOjCki+hw14RyKk201CN4rzyCJRFLpK4=
github.com/klauspost/asmfmt v1.3.2/go.mod h1:AG8TuvYojzulgDAMCnYn50l/5QV3Bs/tp6j0HLHbNSE=
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
2 changes: 1 addition & 1 deletion go/adbc/pkg/_tmpl/driver.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ func {{.Prefix}}StatementExecutePartitions(stmt *C.struct_AdbcStatement, schema
for _, p := range part.PartitionIDs {
totalLen += len(p)
}
partitions.private_data = C.malloc(C.size_t(totalLen))
partitions.private_data = C.calloc(C.size_t(totalLen), C.size_t(1))
dst := fromCArr[byte]((*byte)(partitions.private_data), totalLen)

partIDs := fromCArr[*C.cuint8_t](partitions.partitions, int(partitions.num_partitions))
Expand Down
10 changes: 10 additions & 0 deletions go/adbc/pkg/_tmpl/utils.c.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ AdbcStatusCode AdbcStatementExecutePartitions(struct AdbcStatement* statement,
struct AdbcPartitions* partitions,
int64_t* rows_affected,
struct AdbcError* error) {
return {{.Prefix}}StatementExecutePartitionsTrampoline(
statement, schema, partitions, rows_affected, error);
}

AdbcStatusCode {{.Prefix}}StatementExecutePartitionsTrampoline(
struct AdbcStatement* statement,
struct ArrowSchema* schema,
struct AdbcPartitions* partitions,
int64_t* rows_affected,
struct AdbcError* error) {
if (schema) memset(schema, 0, sizeof(*schema));
if (partitions) memset(partitions, 0, sizeof(*partitions));
return {{.Prefix}}StatementExecutePartitions(statement, schema, partitions,
Expand Down
1 change: 1 addition & 0 deletions go/adbc/pkg/_tmpl/utils.h.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ AdbcStatusCode {{.Prefix}}StatementBindStream(struct AdbcStatement* stmt, struct
AdbcStatusCode {{.Prefix}}StatementCancel(struct AdbcStatement*, struct AdbcError*);
AdbcStatusCode {{.Prefix}}StatementExecuteQuery(struct AdbcStatement* stmt, struct ArrowArrayStream* out, int64_t* affected, struct AdbcError* err);
AdbcStatusCode {{.Prefix}}StatementExecutePartitions(struct AdbcStatement* stmt, struct ArrowSchema* schema, struct AdbcPartitions* partitions, int64_t* affected, struct AdbcError* err);
AdbcStatusCode {{.Prefix}}StatementExecutePartitionsTrampoline(struct AdbcStatement* stmt, struct ArrowSchema* schema, struct AdbcPartitions* partitions, int64_t* affected, struct AdbcError* err);
AdbcStatusCode {{.Prefix}}StatementExecuteSchema(struct AdbcStatement*, struct ArrowSchema*, struct AdbcError*);
AdbcStatusCode {{.Prefix}}StatementGetOption(struct AdbcStatement*, const char*, char*, size_t*, struct AdbcError*);
AdbcStatusCode {{.Prefix}}StatementGetOptionBytes(struct AdbcStatement*, const char*, uint8_t*, size_t*, struct AdbcError*);
Expand Down
2 changes: 1 addition & 1 deletion go/adbc/pkg/flightsql/driver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions go/adbc/pkg/flightsql/utils.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions go/adbc/pkg/flightsql/utils.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go/adbc/pkg/panicdummy/driver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions go/adbc/pkg/panicdummy/utils.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions go/adbc/pkg/panicdummy/utils.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go/adbc/pkg/snowflake/driver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions go/adbc/pkg/snowflake/utils.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions go/adbc/pkg/snowflake/utils.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 576f716

Please sign in to comment.