<commit_before>// This copy of vdb.h has been doctored up to interoperate with Terra
// instead of giving errors.  In the process it lost access
// to callsite labeling/filtering.

#ifndef __VDB_H
#define __VDB_H

//#define VDB_CALL static inline
#define VDB_CALL

VDB_CALL int vdb_point(float x, float y, float z);
VDB_CALL int vdb_line(float x0, float y0, float z0, 
                      float x1, float y1, float z1);
VDB_CALL int vdb_normal(float x, float y, float z, 
                        float dx, float dy, float dz);
VDB_CALL int vdb_triangle(float x0, float y0, float z0, 
                          float x1, float y1, float z1,
                          float x2, float y2, float z2);

VDB_CALL int vdb_color(float r, float g, float b);

//By default, vdb will refresh the contents of the view at the end of every API call,
//you can surround multiple calls to vdb functions with vdb_begin/vdb_end
//to prevent the viewer from refreshing the contents until all the draw calls have been made

VDB_CALL int vdb_begin();
VDB_CALL int vdb_end();

VDB_CALL int vdb_flush();

//create a new blank frame. Currently just clears the screen, but eventually the viewer may keep
//around the contents of previous frames for inspection.
VDB_CALL int vdb_frame();


//versions that take direct pointers to floating point data
//this works well if you have a Point or Line struct
VDB_CALL int vdb_point_v(void * p);
VDB_CALL int vdb_line_v(void * p);
VDB_CALL int vdb_normal_v(void * p);
VDB_CALL int vdb_triangle_v(void * p);                 
VDB_CALL int vdb_color_v(void * c);



VDB_CALL int vdb_sample(float p);
//VDB_CALL int vdb_label(const char * lbl); 
//VDB_CALL int vdb_label(int i); 

//for simplicity all the implementation to interface with vdb is in this header, just include it in your project

#include <stdarg.h>
#ifndef _WIN32
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
VDB_CALL int vdb_close(int i) { return close(i); }
#else
#include <WinSock2.h>
#pragma comment(lib, "Ws2_32.lib")
typedef int socklen_t;
VDB_CALL int vdb_close(int i) { return closesocket(i); }
#endif

static void vdb_report_error();

#include <stdio.h>
#include <stdlib.h>

//#include <map>
//#include <string>

#define VDB_BUFFER_SIZE (64*1024)
//maximum characters in a vdb command
#define VDB_REDZONE_SIZE 512
static struct {
  int is_initialized;
  int init_error; 
  int in_group;
  int sample_enabled;
  int fd;
  size_t n_bytes;
  char buffer[VDB_BUFFER_SIZE];
  //TODO: remove c++ to make this header c compatible
//  std::map< std::string, int> string_table;
} __vdb;


VDB_CALL int vdb_sample(float p) {
  if(p >= 1.f)
    return __vdb.sample_enabled = 1;
  else {
#ifndef __APPLE__
    double r = rand() / (double) RAND_MAX;
#else
    double r = arc4random() / (double) 0xFFFFFFFF;
#endif
    return __vdb.sample_enabled = (r < p);
  }
}

static void vdb_os_init();

VDB_CALL void vdb_exit() {
  if(__vdb.init_error == 0) {
    vdb_close(__vdb.fd);
    __vdb.init_error = 1;
  }
}
VDB_CALL int vdb_init() {
  if(!__vdb.is_initialized) {
    __vdb.is_initialized = 1;
    __vdb.sample_enabled = 1;
    vdb_os_init();
    __vdb.fd = socket(AF_INET, SOCK_STREAM, 0);
    if(__vdb.fd == -1) {
      vdb_report_error();
      __vdb.init_error = 1;
    } else {
      struct sockaddr_in serv_name;
      serv_name.sin_family = AF_INET;
      serv_name.sin_addr.s_addr = htonl(0x7F000001L);
      serv_name.sin_port = htons(10000);
      if(-1 == connect(__vdb.fd, (struct sockaddr*) &serv_name, sizeof(serv_name))) {
        vdb_report_error();
        __vdb.init_error = 1;
      }
      atexit(vdb_exit);
    }
  }
  if(__vdb.is_initialized == 2) { 
    //this never runs, but it tricks compilers into including these functions as debug symbols 
    //even though they may never be used
    //useful if you want to call them from the debugger directly
    vdb_point_v(NULL);
    vdb_line_v(NULL);
    vdb_normal_v(NULL);
    vdb_triangle_v(NULL);
    vdb_point(0,0,0);
    vdb_line(0,0,0,0,0,0);
    vdb_normal(0,0,0,0,0,0);
    vdb_triangle(0,0,0,0,0,0,0,0,0);
    vdb_color_v(NULL);
    vdb_color(0,0,0);
    //vdb_label("");
    //vdb_label(0);
  }<commit_msg>fixing atexit bug with vdb<commit_after>// This copy of vdb.h has been doctored up to interoperate with Terra
// instead of giving errors.  In the process it lost access
// to callsite labeling/filtering.

#ifndef __VDB_H
#define __VDB_H

//#define VDB_CALL static inline
#define VDB_CALL

VDB_CALL int vdb_point(float x, float y, float z);
VDB_CALL int vdb_line(float x0, float y0, float z0, 
                      float x1, float y1, float z1);
VDB_CALL int vdb_normal(float x, float y, float z, 
                        float dx, float dy, float dz);
VDB_CALL int vdb_triangle(float x0, float y0, float z0, 
                          float x1, float y1, float z1,
                          float x2, float y2, float z2);

VDB_CALL int vdb_color(float r, float g, float b);

//By default, vdb will refresh the contents of the view at the end of every API call,
//you can surround multiple calls to vdb functions with vdb_begin/vdb_end
//to prevent the viewer from refreshing the contents until all the draw calls have been made

VDB_CALL int vdb_begin();
VDB_CALL int vdb_end();

VDB_CALL int vdb_flush();

//create a new blank frame. Currently just clears the screen, but eventually the viewer may keep
//around the contents of previous frames for inspection.
VDB_CALL int vdb_frame();


//versions that take direct pointers to floating point data
//this works well if you have a Point or Line struct
VDB_CALL int vdb_point_v(void * p);
VDB_CALL int vdb_line_v(void * p);
VDB_CALL int vdb_normal_v(void * p);
VDB_CALL int vdb_triangle_v(void * p);                 
VDB_CALL int vdb_color_v(void * c);



VDB_CALL int vdb_sample(float p);
//VDB_CALL int vdb_label(const char * lbl); 
//VDB_CALL int vdb_label(int i); 

//for simplicity all the implementation to interface with vdb is in this header, just include it in your project

#include <stdarg.h>
#ifndef _WIN32
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
VDB_CALL int vdb_close(int i) { return close(i); }
#else
#include <WinSock2.h>
#pragma comment(lib, "Ws2_32.lib")
typedef int socklen_t;
VDB_CALL int vdb_close(int i) { return closesocket(i); }
#endif

static void vdb_report_error();

#include <stdio.h>
#include <stdlib.h>

//#include <map>
//#include <string>

#define VDB_BUFFER_SIZE (64*1024)
//maximum characters in a vdb command
#define VDB_REDZONE_SIZE 512
static struct {
  int is_initialized;
  int init_error; 
  int in_group;
  int sample_enabled;
  int fd;
  size_t n_bytes;
  char buffer[VDB_BUFFER_SIZE];
  //TODO: remove c++ to make this header c compatible
//  std::map< std::string, int> string_table;
} __vdb;


VDB_CALL int vdb_sample(float p) {
  if(p >= 1.f)
    return __vdb.sample_enabled = 1;
  else {
#ifndef __APPLE__
    double r = rand() / (double) RAND_MAX;
#else
    double r = arc4random() / (double) 0xFFFFFFFF;
#endif
    return __vdb.sample_enabled = (r < p);
  }
}

static void vdb_os_init();

VDB_CALL int vdb_init() {
  if(!__vdb.is_initialized) {
    __vdb.is_initialized = 1;
    __vdb.sample_enabled = 1;
    vdb_os_init();
    __vdb.fd = socket(AF_INET, SOCK_STREAM, 0);
    if(__vdb.fd == -1) {
      vdb_report_error();
      __vdb.init_error = 1;
    } else {
      struct sockaddr_in serv_name;
      serv_name.sin_family = AF_INET;
      serv_name.sin_addr.s_addr = htonl(0x7F000001L);
      serv_name.sin_port = htons(10000);
      if(-1 == connect(__vdb.fd, (struct sockaddr*) &serv_name, sizeof(serv_name))) {
        vdb_report_error();
        __vdb.init_error = 1;
      }
    }
  }
  if(__vdb.is_initialized == 2) { 
    //this never runs, but it tricks compilers into including these functions as debug symbols 
    //even though they may never be used
    //useful if you want to call them from the debugger directly
    vdb_point_v(NULL);
    vdb_line_v(NULL);
    vdb_normal_v(NULL);
    vdb_triangle_v(NULL);
    vdb_point(0,0,0);
    vdb_line(0,0,0,0,0,0);
    vdb_normal(0,0,0,0,0,0);
    vdb_triangle(0,0,0,0,0,0,0,0,0);
    vdb_color_v(NULL);
    vdb_color(0,0,0);
    //vdb_label("");
    //vdb_label(0);
  }
{'fraction_non_alphanumeric': 0.10566541307776295, 'fraction_numerical': 0.020380929273322818, 'mean_word_length': 3.3412322274881516, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1106890', 'n_tokens_mistral': 3137, 'n_tokens_neox': 3021, 'n_words': 913}