mirror of
https://github.com/google/go-jsonnet.git
synced 2025-08-07 23:07:14 +02:00
issue-433 increase the number of constructed Jsonnet handles.
This commit is contained in:
parent
a1f3af26dc
commit
db2bf1e024
@ -106,12 +106,12 @@ func jsonnet_make() *C.struct_JsonnetVm {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return C.jsonnet_internal_make_vm_with_id(C.uint32_t(id))
|
||||
return C.jsonnet_internal_make_vm_with_id(C.uint64_t(id))
|
||||
}
|
||||
|
||||
//export jsonnet_destroy
|
||||
func jsonnet_destroy(vmRef *C.struct_JsonnetVm) {
|
||||
if err := handles.free(uint32(vmRef.id)); err != nil {
|
||||
if err := handles.free(uint64(vmRef.id)); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
@ -120,7 +120,7 @@ func jsonnet_destroy(vmRef *C.struct_JsonnetVm) {
|
||||
}
|
||||
|
||||
func getVM(vmRef *C.struct_JsonnetVm) *vm {
|
||||
ref, err := handles.get(uint32(vmRef.id))
|
||||
ref, err := handles.get(uint64(vmRef.id))
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
@ -411,7 +411,7 @@ func jsonnet_json_destroy(vmRef *C.struct_JsonnetVm, v *C.struct_JsonnetJsonValu
|
||||
jsonnet_json_destroy(vmRef, child)
|
||||
}
|
||||
|
||||
if err := handles.free(uint32(v.id)); err != nil {
|
||||
if err := handles.free(uint64(v.id)); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
@ -427,11 +427,11 @@ func createJSONValue(vmRef *C.struct_JsonnetVm, val interface{}) *C.struct_Jsonn
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return C.jsonnet_internal_make_json_with_id(C.uint32_t(id))
|
||||
return C.jsonnet_internal_make_json_with_id(C.uint64_t(id))
|
||||
}
|
||||
|
||||
func getJSONValue(jsonRef *C.struct_JsonnetJsonValue) *jsonValue {
|
||||
ref, err := handles.get(uint32(jsonRef.id))
|
||||
ref, err := handles.get(uint64(jsonRef.id))
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const maxID = 100000
|
||||
const maxID = (1 << 63) - 1
|
||||
|
||||
// Because of Go GC, there are restrictions on keeping Go pointers in C.
|
||||
// We cannot just pass *jsonnet.VM/JsonValue to C. So instead we use "handle" structs in C
|
||||
@ -18,7 +18,7 @@ const maxID = 100000
|
||||
// handlesTable is the set of active, valid Jsonnet allocated handles
|
||||
type handlesTable struct {
|
||||
objects []interface{}
|
||||
freedIDs []uint32
|
||||
freedIDs []uint64
|
||||
}
|
||||
|
||||
// errMaxNumberOfOpenHandles tells that there was an attempt to create more than maxID open handles
|
||||
@ -28,14 +28,14 @@ var errMaxNumberOfOpenHandles = fmt.Errorf("maximum number of constructed Jsonne
|
||||
var errInvalidHandle = errors.New("invalid handle ID was provided")
|
||||
|
||||
// make registers the new object as a handle and returns the corresponding ID
|
||||
func (h *handlesTable) make(obj interface{}) (uint32, error) {
|
||||
var id uint32
|
||||
func (h *handlesTable) make(obj interface{}) (uint64, error) {
|
||||
var id uint64
|
||||
|
||||
if len(h.freedIDs) > 0 {
|
||||
id, h.freedIDs = h.freedIDs[len(h.freedIDs)-1], h.freedIDs[:len(h.freedIDs)-1]
|
||||
h.objects[id-1] = obj
|
||||
} else {
|
||||
id = uint32(len(h.objects) + 1)
|
||||
id = uint64(len(h.objects) + 1)
|
||||
|
||||
if id > maxID {
|
||||
return 0, errMaxNumberOfOpenHandles
|
||||
@ -48,7 +48,7 @@ func (h *handlesTable) make(obj interface{}) (uint32, error) {
|
||||
}
|
||||
|
||||
// free marks the given handle ID as unused
|
||||
func (h *handlesTable) free(id uint32) error {
|
||||
func (h *handlesTable) free(id uint64) error {
|
||||
if err := h.ensureValidID(id); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -60,7 +60,7 @@ func (h *handlesTable) free(id uint32) error {
|
||||
}
|
||||
|
||||
// get returns the corresponding object for the provided ID
|
||||
func (h *handlesTable) get(id uint32) (interface{}, error) {
|
||||
func (h *handlesTable) get(id uint64) (interface{}, error) {
|
||||
if err := h.ensureValidID(id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -69,7 +69,7 @@ func (h *handlesTable) get(id uint32) (interface{}, error) {
|
||||
}
|
||||
|
||||
// ensureValidID returns an error if the given handle ID is invalid, otherwise returns nil
|
||||
func (h *handlesTable) ensureValidID(id uint32) error {
|
||||
func (h *handlesTable) ensureValidID(id uint64) error {
|
||||
if id == 0 || uint64(id) > uint64(len(h.objects)) {
|
||||
return errInvalidHandle
|
||||
}
|
||||
|
@ -3,17 +3,17 @@
|
||||
#include <stdint.h>
|
||||
|
||||
struct JsonnetVm {
|
||||
uint32_t id;
|
||||
uint64_t id;
|
||||
};
|
||||
|
||||
struct JsonnetVm *jsonnet_internal_make_vm_with_id(uint32_t id);
|
||||
struct JsonnetVm *jsonnet_internal_make_vm_with_id(uint64_t id);
|
||||
void jsonnet_internal_free_vm(struct JsonnetVm *x);
|
||||
|
||||
struct JsonnetJsonValue {
|
||||
uint32_t id;
|
||||
uint64_t id;
|
||||
};
|
||||
|
||||
struct JsonnetJsonValue *jsonnet_internal_make_json_with_id(uint32_t id);
|
||||
struct JsonnetJsonValue *jsonnet_internal_make_json_with_id(uint64_t id);
|
||||
void jsonnet_internal_free_json(struct JsonnetJsonValue *x);
|
||||
|
||||
typedef struct JsonnetJsonValue *JsonnetNativeCallback(void *ctx,
|
||||
|
@ -6,7 +6,7 @@ extern "C" {
|
||||
#include "internal.h"
|
||||
}
|
||||
|
||||
struct JsonnetVm *jsonnet_internal_make_vm_with_id(uint32_t id) {
|
||||
struct JsonnetVm *jsonnet_internal_make_vm_with_id(uint64_t id) {
|
||||
JsonnetVm *vm = new JsonnetVm();
|
||||
vm->id = id;
|
||||
return vm;
|
||||
@ -16,7 +16,7 @@ void jsonnet_internal_free_vm(struct JsonnetVm *x) {
|
||||
delete(x);
|
||||
}
|
||||
|
||||
struct JsonnetJsonValue *jsonnet_internal_make_json_with_id(uint32_t id) {
|
||||
struct JsonnetJsonValue *jsonnet_internal_make_json_with_id(uint64_t id) {
|
||||
JsonnetJsonValue *json = new JsonnetJsonValue();
|
||||
json->id = id;
|
||||
return json;
|
||||
|
Loading…
Reference in New Issue
Block a user