Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Rename getcptr to getCstring
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Aug 23, 2017
1 parent 0fd3e69 commit ce04323
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 30 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: go
sudo: false
go:
- 1.6.x
- 1.7.x
- 1.8.x
- master

install:
- go get .

script:
- go test ./...
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ Go-client allows to easily comunicate with the Babelfish server to parse the any
It's also integrated with libuast so it is possible to run xpath queries agains the UAST in an idiomatic way.



## Installation

### Dependencies

- libuast
- libuast ( https://github.com/bblfsh/libuast )

### Go library

```
go get github.com/bblfsh/client-go
```



30 changes: 11 additions & 19 deletions bindings.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#ifndef _GO_CLIENT_BINDINGS_H_
#define _GO_CLIENT_BINDINGS_H_
#ifndef _CLIENT_GO_BINDINGS_H_
#define _CLIENT_GO_BINDINGS_H_

#include <libuast/uast.h>


extern char* goGetInternalType(uintptr_t);
extern int goGetPropertiesSize(uintptr_t);
extern char* goGetToken(uintptr_t);
Expand All @@ -12,41 +11,34 @@ extern uintptr_t goGetChild(uintptr_t, int);
extern int goGetRolesSize(uintptr_t);
extern uint16_t goGetRole(uintptr_t, int);

static const char *get_internal_type(const void *node)
{
static const char *get_internal_type(const void *node) {
return goGetInternalType((uintptr_t)node);
}

static const char *get_token(const void *node)
{
static const char *get_token(const void *node) {
return goGetToken((uintptr_t)node);
}

static int get_children_size(const void *node)
{
static int get_children_size(const void *node) {
return goGetChildrenSize((uintptr_t)node);
}

static void *get_child(const void *data, int index)
{
static void *get_child(const void *data, int index) {
return (void*)goGetChild((uintptr_t)data, index);
}

static int get_roles_size(const void *node)
{
static int get_roles_size(const void *node) {
return goGetRolesSize((uintptr_t)node);
}

static uint16_t get_role(const void *node, int index)
{
static uint16_t get_role(const void *node, int index) {
return goGetRole((uintptr_t)node, index);
}

static node_api *api;
static find_ctx *ctx;

static void create_go_node_api()
{
static void create_go_node_api() {
api = new_node_api((node_iface){
.internal_type = get_internal_type,
.token = get_token,
Expand All @@ -62,12 +54,12 @@ static int _api_find(uintptr_t node_ptr, const char *query) {
return node_api_find(api, ctx, (void*)node_ptr, query);
}

static int _api_get_nu_results() {
static int _api_get_len() {
return find_ctx_get_len(ctx);
}

static uintptr_t _api_get_result(unsigned int i) {
return (uintptr_t)find_ctx_get(ctx, i);
}

#endif
#endif // _CLIENT_GO_BINDINGS_H_
1 change: 0 additions & 1 deletion client_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion cstring-pool.go → cstring_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type cstringPool struct {
pointers []unsafe.Pointer
}

func (pool *cstringPool) getCPtr(str string) *C.char {
func (pool *cstringPool) getCstring(str string) *C.char {
ptr := C.CString(str)
pool.pointers = append(pool.pointers, unsafe.Pointer(ptr))
return ptr
Expand Down
8 changes: 4 additions & 4 deletions libuast.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Find(node *uast.Node, xpath string) ([]*uast.Node, error) {
defer findMutex.Unlock()

// convert xpath string to a NULL-terminated c string
cquery := pool.getCPtr(xpath)
cquery := pool.getCstring(xpath)

// Make sure we release the pool of strings
defer pool.release()
Expand All @@ -52,7 +52,7 @@ func Find(node *uast.Node, xpath string) ([]*uast.Node, error) {
return nil, errors.New("error: node_api_find() failed")
}

nu := int(C._api_get_nu_results())
nu := int(C._api_get_len())
results := make([]*uast.Node, nu)
for i := 0; i < nu; i++ {
results[i] = ptrToNode(C._api_get_result(C.uint(i)))
Expand All @@ -62,12 +62,12 @@ func Find(node *uast.Node, xpath string) ([]*uast.Node, error) {

//export goGetInternalType
func goGetInternalType(ptr C.uintptr_t) *C.char {
return pool.getCPtr(ptrToNode(ptr).InternalType)
return pool.getCstring(ptrToNode(ptr).InternalType)
}

//export goGetToken
func goGetToken(ptr C.uintptr_t) *C.char {
return pool.getCPtr(ptrToNode(ptr).Token)
return pool.getCstring(ptrToNode(ptr).Token)
}

//export goGetChildrenSize
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit ce04323

Please sign in to comment.