~kyrofa/unity-scope-snappy/integration-tests_previews

« back to all changes in this revision

Viewing changes to internal/launchpad.net/go-unityscopes/v2/helpers.cpp

  • Committer: Alejandro J. Cura
  • Date: 2015-06-03 19:46:54 UTC
  • mfrom: (8.1.3 ci_integration)
  • Revision ID: alecu@canonical.com-20150603194654-h4rnrkmefnmgsj49
MergingĀ lp:~kyrofa/unity-scope-snappy/ci_integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "helpers.h"
 
2
 
 
3
#include <cstdlib>
 
4
#include <cstring>
 
5
 
 
6
extern "C" {
 
7
#include "_cgo_export.h"
 
8
}
 
9
 
 
10
namespace gounityscopes {
 
11
namespace internal {
 
12
 
 
13
std::string from_gostring(void *str) {
 
14
    GoString *s = static_cast<GoString*>(str);
 
15
    return std::string(s->p, s->n);
 
16
}
 
17
 
 
18
void *as_bytes(const std::string &str, int *length) {
 
19
    *length = str.size();
 
20
    void *data = malloc(str.size());
 
21
    if (data == nullptr) {
 
22
        return nullptr;
 
23
    }
 
24
    memcpy(data, str.data(), str.size());
 
25
    return data;
 
26
}
 
27
 
 
28
}
 
29
}