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
Related to apache#1931.
  • Loading branch information
lidavidm committed Jun 26, 2024
1 parent 453a9c3 commit 03a385e
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 7 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
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 03a385e

Please sign in to comment.