Exemple #1
0
/**
   process_stdout_read : 'process -> buf:string -> pos:int -> len:int -> int
   <doc>
   Read up to [len] bytes in [buf] starting at [pos] from the process stdout.
   Returns the number of bytes readed this way. Raise an exception if this
   process stdout is closed and no more data is available for reading.

        For hxcpp, the input buffer is in bytes, not characters
   </doc>
**/
static value process_stdout_read( value vp, value str, value pos, value len ) {
   CHECK_ARGS();
   gc_enter_blocking();
#   ifdef NEKO_WINDOWS
   {
      DWORD nbytes;
      if( !ReadFile(p->oread,buffer_data(buf)+val_int(pos),val_int(len),&nbytes,NULL) )
      {
         gc_exit_blocking();
         return alloc_null();
      }
      gc_exit_blocking();
      return alloc_int(nbytes);
   }
#   else
   int nbytes = read(p->oread,buffer_data(buf) + val_int(pos),val_int(len));
   if( nbytes <= 0 )
   {
      gc_exit_blocking();
      alloc_null();
   }
   gc_exit_blocking();
   return alloc_int(nbytes);
#   endif
}
Exemple #2
0
/**
 * @brief Create an indirect block.
 *
 * @details Creates a indirect block and saves in @param dest.
 *
 * @param dest Destination buffer, It is the corresponding disk block to be changed.
 * @param ip File to use.
 * @param offset Offset to be calculated the block.
 * @param creat If 1, creates an block, otherwise, just return this value.
 *
 * @returns If successful, the block number created / obtained, otherwise BLOCK_NULL is 
 *          returned.
 *
 * @note @p ip must be locked.
 */
PUBLIC block_t create_indirect_block
(struct buffer *dest, struct inode *ip, off_t offset, int create)
{
	block_t phys; /* Physical block number. */

	if (((block_t *)buffer_data(dest))[offset] == BLOCK_NULL && create)
	{
		/* Allocate an block. */
		superblock_lock(ip->sb);
		phys = block_alloc(ip->sb);
		superblock_unlock(ip->sb);

		if (phys != BLOCK_NULL)
		{
			((block_t *)buffer_data(dest))[offset] = phys;
			buffer_dirty(dest, 1);
			inode_touch(ip);
			brelse(dest);
			return (phys);
		}
		else
		{
			brelse(dest);
			return (phys);
		}
	}
	else
	{
		brelse(dest);
		return ((block_t *)buffer_data(dest))[offset];
	}
}
Exemple #3
0
Buffer *rope_flatten(const Rope *r) {
    Buffer *buf = buffer_empty(r->length);
    size_t counter = 0;
    void visitor(List *l, void *ctx, void *item, bool *keep_going) {
        Buffer *buf_item = (Buffer *)item;
        memcpy(buffer_data(buf) + counter, buffer_data(buf_item), buffer_length(buf_item));
        counter += buffer_length(buf_item);
    }
	void renderer::draw_call_imgui(
		const graphics::texture& imgui_atlas,
		const graphics::texture* game_world_atlas
	) {
		const auto* const draw_data = ImGui::GetDrawData();

		if (draw_data != nullptr) {
			imgui_atlas.bind();

			ImGuiIO& io = ImGui::GetIO();
			// const int fb_width = static_cast<int>(io.DisplaySize.x * io.DisplayFramebufferScale.x);
			const int fb_height = static_cast<int>(io.DisplaySize.y * io.DisplayFramebufferScale.y);
			(void)fb_height;

			GL_CHECK(glEnable(GL_SCISSOR_TEST));

			for (int n = 0; n < draw_data->CmdListsCount; ++n) {
				const ImDrawList* cmd_list = draw_data->CmdLists[n];
				const ImDrawIdx* idx_buffer_offset = 0;

				GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, triangle_buffer_id));
				GL_CHECK(buffer_data(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.Size * sizeof(ImDrawVert), (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW));

				GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, imgui_elements_id));
				GL_CHECK(buffer_data(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx), (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW));

				for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; ++cmd_i) {
					const ImDrawCmd* const pcmd = &cmd_list->CmdBuffer[cmd_i];

					const auto atlas_type = static_cast<augs::imgui_atlas_type>(reinterpret_cast<intptr_t>(pcmd->TextureId));

					bool rebind = false;

					if (atlas_type == augs::imgui_atlas_type::GAME) {
						if (game_world_atlas != nullptr) {
							game_world_atlas->bind();
							rebind = true;
						}
					}
					
					GL_CHECK(glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y)));
					GL_CHECK(glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset));

					idx_buffer_offset += pcmd->ElemCount;

					if (rebind) {
						imgui_atlas.bind();
					}
				}
			}

			GL_CHECK(glDisable(GL_SCISSOR_TEST));

			if (game_world_atlas != nullptr) {
				game_world_atlas->bind();
			}
		}
	}
Exemple #5
0
	void Bytes::Resize (int size) {
		
		if (size != _length) {
			
			if (!_value) {
				
				_value = alloc_empty_object ();
				
			}
			
			if (val_is_null (val_field (_value, id_b))) {
				
				value dataValue;
				
				if (useBuffer) {
					
					buffer b = alloc_buffer_len (size);
					dataValue = buffer_val (b);
					_data = (unsigned char*)buffer_data (b);
					
				} else {
					
					dataValue = alloc_raw_string (size);
					_data = (unsigned char*)val_string (dataValue);
					
				}
				
				alloc_field (_value, id_b, dataValue);
				
			} else {
				
				if (useBuffer) {
					
					buffer b = val_to_buffer (val_field (_value, id_b));
					buffer_set_size (b, size);
					_data = (unsigned char*)buffer_data (b);
					
				} else {
					
					value s = alloc_raw_string (size);
					memcpy ((char *)val_string (s), val_string (val_field (_value, id_b)), size);
					alloc_field (_value, id_b, s);
					_data = (unsigned char*)val_string (s);
					
				}
				
			}
			
			alloc_field (_value, id_length, alloc_int (size));
			
		}
		
		_length = size;
		
	}
Exemple #6
0
void testApp::bufferGrid()
{
	buffer_data(vertexBuffer, 
		GL_ARRAY_BUFFER, 
		g_vertex_buffer_data, 
		sizeof(GLfloat) * v_buffer_size);
	buffer_data(elementBuffer, 
		GL_ELEMENT_ARRAY_BUFFER, 
		g_element_buffer_data, 
		sizeof(GLushort) * e_buffer_size);
}
Exemple #7
0
/**
 * @brief Allocates a disk block.
 * 
 * @details Allocates a disk block by searching in the bitmap of blocks for a
 *          free block.
 * 
 * @param sb Superblock in which the disk block should be allocated.
 * 
 * @return Upon successful completion, the block number of the allocated block
 *         is returned. Upon failed, #BLOCK_NULL is returned instead.
 * 
 * @note The superblock must be locked.
 */
PRIVATE block_t block_alloc(struct superblock *sb)
{
	bit_t bit;          /* Bit number in the bitmap. */
	block_t num;        /* Block number.             */
	block_t blk;        /* Working block.            */
	block_t firstblk;   /* First block to check.     */
	struct buffer *buf; /* Working buffer.           */

	/* Search for a free block. */
	firstblk = (sb->zsearch - sb->first_data_block)/(BLOCK_SIZE << 3);
	blk = firstblk;
	do
	{
		bit = bitmap_first_free(buffer_data(sb->zmap[blk]), BLOCK_SIZE);
		
		/* Found. */
		if (bit != BITMAP_FULL)
			goto found;
		
		/* Wrap around. */
		blk = (blk + 1 < sb->zmap_blocks) ? blk + 1 : 0;
	} while (blk != firstblk);
	
	return (BLOCK_NULL);

found:

	num =  sb->first_data_block + bit + blk*(BLOCK_SIZE << 3);
	
	/* 
	 * Remember disk block number to 
	 * speedup next block allocation.
	 */
	sb->zsearch = num;
	
	/* Allocate block. */
	bitmap_set(buffer_data(sb->zmap[blk]), bit);
	buffer_dirty(sb->zmap[blk], 1);
	sb->flags |= SUPERBLOCK_DIRTY;
	
	/* Clean block to avoid security issues. */
	buf = bread(sb->dev, blk);	
	kmemset(buffer_data(buf), 0, BLOCK_SIZE);
	buffer_dirty(buf, 1);
	brelse(buf);
	
	return (num);
}
Exemple #8
0
static void maybe_write(struct thread *thread)
{
    obj_t *fp = thread->fp;
    int fd = fixnum_value(fp[-9]);
    int nfound, res;
    obj_t *old_sp;

    nfound = output_writable(fd);
    if (nfound < 0) {
        if (errno != EINTR) {
            old_sp = pop_linkage(thread);
            thread->sp = old_sp + 2;
            old_sp[0] = obj_False;
            old_sp[1] = make_fixnum(errno);
            do_return(thread, old_sp, old_sp);
        } else {
            wait_for_output(thread, fd, maybe_write);
        }
    } else if (nfound == 0)
        wait_for_output(thread, fd, maybe_write);
    else {
                res = write(fd,
                    buffer_data(fp[-8]) + fixnum_value(fp[-7]),
                    fixnum_value(fp[-6]));
                results(thread, pop_linkage(thread), res, make_fixnum(res));
    }
}
Exemple #9
0
static void maybe_read(struct thread *thread)
{
    obj_t *fp = thread->fp;
    int fd = fixnum_value(fp[-9]);
    int nfound, res;
    obj_t *old_sp;

    nfound = input_available(fd);
    if (nfound < 0) {
        old_sp = pop_linkage(thread);
        thread->sp = old_sp + 2;
        old_sp[0] = obj_False;
        old_sp[1] = make_fixnum(errno);
        do_return(thread, old_sp, old_sp);
    }
    else if (nfound == 0)
        wait_for_input(thread, fd, maybe_read);
    else {
        res = mindy_read(fd,
                         (char *)(buffer_data(fp[-8]) + fixnum_value(fp[-7])),
                         fixnum_value(fp[-6]));

        results(thread, pop_linkage(thread), res, make_fixnum(res));
    }
}
Exemple #10
0
 Value * Bundle::getBytesContentV(const char * format,va_list va){
     Value * path = getFilePathV(format,va);
     
     if(_parent){
         return _parent->getBytesContent(path->stringValue());
     }
     
     Value * v = NULL;
     InvokeTickBegin
     hbuffer_t content = buffer_alloc(512, 512);
     FILE * f = fopen(path->stringValue(), "r");
     char buffer[1024];
     int len;
     
     if(f){
         while((len = fread(buffer, 1, sizeof(buffer), f)) >0){
             buffer_append(content, buffer, len);
         }
         fclose(f);
     }
     
     if(buffer_length(content) >0){
         v = Value::newValue((void *)buffer_data(content),buffer_length(content));
     }
     
     buffer_dealloc(content);
     
     return v;
 }
    DEFINE_FUNC_1(webp_decode_argb, data_buffer_value) {
        if (!val_is_buffer(data_buffer_value)) {
            val_throw(alloc_string("webp_decode_argb: Expected to be a buffer"));
            return alloc_null();
        }
        buffer data_buffer = val_to_buffer(data_buffer_value);
        int    data_len = buffer_size(data_buffer);
        char  *data_ptr = buffer_data(data_buffer);
        int webp_width = -1, webp_height = -1;
        char *webp_data_ptr = (char *)WebPDecodeARGB((const unsigned char *)data_ptr, data_len, &webp_width, &webp_height);
        int webp_data_len = webp_width * webp_height * 4;

        if (webp_data_ptr == NULL) {
            val_throw(alloc_string("webp_decode_argb: Invalid webp data"));
            return alloc_null();
        }

        buffer webp_buffer = alloc_buffer_len(0);
        buffer_append_sub(webp_buffer, webp_data_ptr, webp_data_len);
        buffer_set_size(webp_buffer, webp_data_len);

        value array = alloc_array(3);
        val_array_set_i(array, 0, alloc_int(webp_width));
        val_array_set_i(array, 1, alloc_int(webp_height));
        val_array_set_i(array, 2, buffer_val(webp_buffer));

        if (webp_data_ptr != NULL) free(webp_data_ptr);

        return array;
    }
    DEFINE_FUNC_1(webp_get_features, data_buffer_value) {
        if (!val_is_buffer(data_buffer_value)) {
            val_throw(alloc_string("webp_get_features: Expected to be a buffer"));
            return alloc_null();
        }
        buffer data_buffer = val_to_buffer(data_buffer_value);
        int    data_len = buffer_size(data_buffer);
        char  *data_ptr = buffer_data(data_buffer);

        WebPBitstreamFeatures features = {0};
        VP8StatusCode code = WebPGetFeatures((const unsigned char *)data_ptr, data_len, &features);

        if (code != VP8_STATUS_OK) {
            val_throw(alloc_string("webp_get_features: Error: (code != VP8_STATUS_OK)"));
            return alloc_null();
        }

        value array = alloc_array(7);
        val_array_set_i(array, 0, alloc_int(features.width));
        val_array_set_i(array, 1, alloc_int(features.height));
        val_array_set_i(array, 2, alloc_int(features.has_alpha));
        //val_array_set_i(array, 3, alloc_int(features.bitstream_version));
        val_array_set_i(array, 3, alloc_int(0));
        val_array_set_i(array, 4, alloc_int(features.no_incremental_decoding));
        val_array_set_i(array, 5, alloc_int(features.rotate));
        val_array_set_i(array, 6, alloc_int(features.uv_sampling));
        return array;
    }
Exemple #13
0
int cmd_lex(FILE *file, const char *filename)
{
    struct token token;
    buffer_t token_value;

    token_value = buffer_create(1024);

    lexer_init(file);
    log_set_unit(basename(filename));

    printf("Line\tText\tValue\tType\n");
    fflush(stdout);

    while (lexer_next_token(&token)) {
        lexer_token_value(&token, token_value);

        printf("%d:%d\t%s\t%s\t%s\n", token.line, token.column, token.text,
            buffer_data(token_value), lexer_token_type_name(token.type));
        fflush(stdout);

        lexer_token_free_data(&token);
    }

    buffer_free(token_value);
    lexer_destroy();
    log_close();

    return EXIT_SUCCESS;
}
Exemple #14
0
static void
compile_regexes(FileEntry *fileEntry)
{
	BUFFER *bufRegex;
	int result;

	while (fileEntry->szParameter) {
		bufRegex = buffer_create();
		buffer_append(bufRegex, "^[ \t]*");
		buffer_append(bufRegex, fileEntry->szParameter);
		buffer_append(bufRegex, "[ \t]*=[ \t]*(");
		buffer_append(bufRegex, fileEntry->szRegex);
		buffer_append(bufRegex, ")[ \t]*");

		fileEntry->pRegexCompiled = malloc(sizeof(regex_t));
		if (!fileEntry->pRegexCompiled) {
			exit(EXIT_FAILURE);
		}

		result = regcomp(
			fileEntry->pRegexCompiled,
			buffer_data(bufRegex),
			REG_EXTENDED
		);
		if (result) {
			exit(EXIT_FAILURE);
		}

		buffer_destroy(bufRegex);
		fileEntry++;
	}
}
Exemple #15
0
/**
	file_contents : f:string -> string
	<doc>Read the content of the file [f] and return it.</doc>
**/
static value file_contents( value name ) {
	buffer s;
	int len;
	int p;
	val_check(name,string);
	fio f(val_filename(name));
        const char *fname = val_string(name);
	gc_enter_blocking();
	f.io = fopen(fname,"rb");
	if( f.io == NULL )
		file_error("file_contents",&f);
	fseek(f.io,0,SEEK_END);
	len = ftell(f.io);
	fseek(f.io,0,SEEK_SET);
	gc_exit_blocking();
	s = alloc_buffer_len(len);
	p = 0;
	gc_enter_blocking();
	while( len > 0 ) {
		int d;
		POSIX_LABEL(file_contents);
		d = (int)fread((char*)buffer_data(s)+p,1,len,f.io);
		if( d <= 0 ) {
			HANDLE_FINTR(f.io,file_contents);
			fclose(f.io);
			file_error("file_contents",&f);
		}
		p += d;
		len -= d;
	}	
	fclose(f.io);
	gc_exit_blocking();
	return buffer_val(s);
}
Exemple #16
0
/**
	file_read : 'file -> s:string -> p:int -> l:int -> int
	<doc>
	Read up to [l] chars into the string [s] starting at position [p].
	Returns the number of chars readed which is > 0 (or 0 if l == 0).
	</doc>
**/
static value file_read( value o, value s, value pp, value n ) {
	fio *f;
	int p;
	int len;
	int buf_len;
	val_check_kind(o,k_file);
	val_check(s,buffer);
	buffer buf = val_to_buffer(s);
	buf_len = buffer_size(buf);
	val_check(pp,int);
	val_check(n,int);
	f = val_file(o);
	p = val_int(pp);
	len = val_int(n);
	if( p < 0 || len < 0 || p > buf_len || p + len > buf_len )
		return alloc_null();
	gc_enter_blocking();
	while( len > 0 ) {
		int d;
		POSIX_LABEL(file_read_again);
		d = (int)fread(buffer_data(buf)+p,1,len,f->io);
		if( d <= 0 ) {
			int size = val_int(n) - len;
			HANDLE_FINTR(f->io,file_read_again);
			if( size == 0 )
				file_error("file_read",f);
			return alloc_int(size);
		}
		p += d;
		len -= d;
	}
	gc_exit_blocking();
	return n;
}
Exemple #17
0
/**
	socket_send_to : 'socket -> buf:string -> pos:int -> length:int -> addr:{host:'int32,port:int} -> int
	<doc>
	Send data from an unconnected UDP socket to the given address.
	</doc>
**/
static value socket_send_to( value o, value dataBuf, value pos, value len, value vaddr ) {
	int p,l;
	value host, port;
	struct sockaddr_in addr;
	val_check_kind(o,k_socket);
   buffer buf = val_to_buffer(dataBuf);
	const char *cdata = buffer_data(buf);
	int dlen = buffer_size(buf);
	val_check(pos,int);
	val_check(len,int);
	val_check(vaddr,object);
	host = val_field(vaddr, f_host);
	port = val_field(vaddr, f_port);
	val_check(host,int);
	val_check(port,int);
	p = val_int(pos);
	l = val_int(len);
	memset(&addr,0,sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(val_int(port));
	*(int*)&addr.sin_addr.s_addr = val_int(host);
	if( p < 0 || l < 0 || p > dlen || p + l > dlen )
		neko_error();

   SOCKET sock = val_sock(o);
	gc_enter_blocking();
	POSIX_LABEL(send_again);
	dlen = sendto(sock, cdata + p , l, MSG_NOSIGNAL, (struct sockaddr*)&addr, sizeof(addr));
	if( dlen == SOCKET_ERROR ) {
		HANDLE_EINTR(send_again);
		return block_error();
	}
	gc_exit_blocking();
	return alloc_int(dlen);
}
Exemple #18
0
int ipc_send_argv(int sock, const char **argv, int argc)
{
    struct buffer buf;
    int i, err;
    size_t buf_size, argv_lengths[argc];
    
    buf_size = sizeof(argc) + sizeof(buf_size);
    
    for (i = 0; i < argc; ++i) {
        argv_lengths[i] = strlen(argv[i]) + 1;
        buf_size += argv_lengths[i];
    }
    
    err = buffer_init(&buf, buf_size);
    if (err < 0)
        return err;
    
    buffer_write(&buf, &argc, sizeof(argc));
    buffer_write(&buf, &buf_size, sizeof(buf_size));
    
    for (i = 0; i < argc; ++i)
        buffer_write(&buf, argv[i], argv_lengths[i]);
    
    assert(buffer_size(&buf) == buf_size && "Invalid buffer size");
    
    err = ipc_send(sock, buffer_data(&buf), buffer_size(&buf));
    
    buffer_destroy(&buf);
    
    return err;
}
Exemple #19
0
void buffer_print(Buffer* buf) {
    int i;
    printf("P=%2d  T=%2d  F=%2d D=%2d: ", buf->putIndex, buf->takeIndex, buffer_free(buf), buffer_data(buf));
    printf("Buffer [");
    if (buf->putIndex >= buf->takeIndex) {   // no wraparound
        for (i=0; i<buf->size; i++) {
            if (i < buf->takeIndex) printf("_");
            else if (i >= buf->putIndex) printf("_");
            else printf("D");
            if (i%5 == 4 && i!=buf->size-1) printf(".");
        }
    } else {
        for (i=0; i<buf->size; i++) {
            if (i < buf->putIndex) printf("D");
            else if (i < buf->takeIndex) printf("_");
            else printf("D");
            if (i%5 == 4 && i!=buf->size-1) printf(".");
        }
    }
    printf("]    [");
    for (i=0; i<buf->size; i++) {
        if (i<buffer_data(buf)) printf("D");
        else printf("_");
    }
    printf("]\n");
}
	void renderer::fullscreen_quad() {
		float vertices[] = {
			1.f, 1.f,
			1.f, 0.f,
			0.f, 0.f,

			0.f, 0.f,
			0.f, 1.f,
			1.f, 1.f
		};
		(void)vertices;

		GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, triangle_buffer_id));

		GL_CHECK(glDisableVertexAttribArray(static_cast<int>(vertex_attribute::texcoord)));
		GL_CHECK(glDisableVertexAttribArray(static_cast<int>(vertex_attribute::color)));
		GL_CHECK(glVertexAttribPointer(static_cast<int>(vertex_attribute::position), 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), 0));
		GL_CHECK(buffer_data(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW));

		GL_CHECK(glDrawArrays(GL_TRIANGLES, 0, 6));

		GL_CHECK(glEnableVertexAttribArray(static_cast<int>(vertex_attribute::position)));
		GL_CHECK(glEnableVertexAttribArray(static_cast<int>(vertex_attribute::texcoord)));
		GL_CHECK(glEnableVertexAttribArray(static_cast<int>(vertex_attribute::color)));

		GL_CHECK(glVertexAttribPointer(static_cast<int>(vertex_attribute::position), 2, GL_FLOAT, GL_FALSE, sizeof(vertex), nullptr));
		GL_CHECK(glVertexAttribPointer(static_cast<int>(vertex_attribute::texcoord), 2, GL_FLOAT, GL_FALSE, sizeof(vertex), reinterpret_cast<char*>(sizeof(float) * 2)));
		GL_CHECK(glVertexAttribPointer(static_cast<int>(vertex_attribute::color), 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(vertex), reinterpret_cast<char*>(sizeof(float) * 2 + sizeof(float) * 2)));
	}
Exemple #21
0
/**
 * @brief Frees a direct disk block.
 * 
 * @details Frees a direct disk block by setting the block as free in the bitmap
 *          of blocks.
 * 
 * @param sb  Superblock in which the disk block should be freed.
 * @param num Number of the direct disk block that shall be freed.
 * 
 * @note The superblock must be locked.
 */
PRIVATE void block_free_direct(struct superblock *sb, block_t num)
{
	unsigned idx; /* Bitmap index.  */
	unsigned off; /* Bitmap offset. */
	
	/* Nothing to be done. */
	if (num == BLOCK_NULL)
		return;
		
	/* 
	 * Remember free disk block to
	 * speedup next block allocation.
	 */
	if (num < sb->zsearch)
		sb->zsearch = num;
	
	num -= sb->first_data_block;
	
	/*
	 * Compute block index and offset 
	 * in the bitmap.
	 */
	idx = num/(BLOCK_SIZE << 3);
	off = num%(BLOCK_SIZE << 3);
	
	/* Free disk block. */
	bitmap_clear(buffer_data(sb->zmap[idx]), off);
	buffer_dirty(sb->zmap[idx], 1);
	sb->flags |= SUPERBLOCK_DIRTY;
}
	void renderer::call_lines() {
		if (lines.empty()) return;

		GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, triangle_buffer_id));
		GL_CHECK(buffer_data(GL_ARRAY_BUFFER, sizeof(vertex_line) * lines.size(), lines.data(), GL_STREAM_DRAW));
		GL_CHECK(glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(lines.size()) * 2));
	}
	void renderer::call_triangles(const vertex_triangle_buffer& buffer) {
		GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, triangle_buffer_id));

		GL_CHECK(buffer_data(GL_ARRAY_BUFFER, sizeof(vertex_triangle) * buffer.size(), buffer.data(), GL_STREAM_DRAW));
		GL_CHECK(glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(buffer.size()) * 3));
		num_total_triangles_drawn += buffer.size();
	}
Exemple #24
0
static value socket_recv_from( value o, value dataBuf, value pos, value len, value addr ) {
	int p,l,ret;
	int retry = 0;
	struct sockaddr_in saddr;
	SockLen slen = sizeof(saddr);
	val_check_kind(o,k_socket);
	val_check(dataBuf,buffer);
	buffer buf = val_to_buffer(dataBuf);
   char *data = buffer_data(buf);
   int dlen = buffer_size(buf);
	val_check(pos,int);
	val_check(len,int);
	val_check(addr,object);
	p = val_int(pos);
	l = val_int(len);

	if( p < 0 || l < 0 || p > dlen || p + l > dlen )
		neko_error();
   SOCKET sock = val_sock(o);
   gc_enter_blocking();
	POSIX_LABEL(recv_from_again);
	if( retry++ > NRETRYS ) {
      ret = recv(sock,data+p,l,MSG_NOSIGNAL);
	} else
		ret = recvfrom(sock, data + p , l, MSG_NOSIGNAL, (struct sockaddr*)&saddr, &slen);
	if( ret == SOCKET_ERROR ) {
		HANDLE_EINTR(recv_from_again);
		return block_error();
	}
   gc_exit_blocking();
	alloc_field(addr,f_host,alloc_int32(*(int*)&saddr.sin_addr));
	alloc_field(addr,f_port,alloc_int(ntohs(saddr.sin_port)));
	return alloc_int(ret);
}
Exemple #25
0
int
main(int argc, char **argv)
{
    enum Codec_T ct = DECODER;
    REPR_FORMAT(repr);
    BUFFER(inbuf);

    const struct option longopts[] = {
        { "encode", 0, NULL, 'e' },
        { "format", 1, NULL, 'f' },
        { "help", 0, NULL, 'h' },
        { "version", 0, NULL, 'V' }
    };
    int c;
    while ((c = getopt_long(argc, argv, "ef:hV", longopts, NULL)) != -1) {
        switch (c) {
        case 'e':
            ct = ENCODER;
            break;

        case 'f':
            if (repr.dict != NULL) {
                repr_destroy(&repr);
                die("Multiple -f/--format options are not"
                    " allowed");
            }

            if (repr_create(&repr, optarg) != 0) {
                repr_destroy(&repr);
                return 1;
            }
            break;

        case 'h':
            usage(*argv);
            return 0;

        case 'V':
            printf("%s %s\n", basename(*argv), VERSION);
            return 0;

        default:
            return 1;
        }
    }

    int rv = 0;
    if (optind == argc) {
        rv = process_file(ct, "-", &inbuf, &repr);
    } else {
        int i;
        for (i = optind; i < argc; ++i)
            rv |= process_file(ct, argv[i], &inbuf, &repr);
    }

    repr_destroy(&repr);
    free(buffer_data(&inbuf));
    return -rv;
}
Exemple #26
0
/**
   process_stdin_write : 'process -> buf:string -> pos:int -> len:int -> int
   <doc>
   Write up to [len] bytes from [buf] starting at [pos] to the process stdin.
   Returns the number of bytes writen this way. Raise an exception if this
   process stdin is closed.
   </doc>
**/
static value process_stdin_write( value vp, value str, value pos, value len ) {
   CHECK_ARGS();
   gc_enter_blocking();
#   ifdef NEKO_WINDOWS
   DWORD nbytes;
   if( !WriteFile(p->iwrite,buffer_data(buf)+val_int(pos),val_int(len),&nbytes,NULL) )
#   else
   int nbytes = write(p->iwrite,buffer_data(buf)+val_int(pos),val_int(len));
   if( nbytes == -1 )
#   endif
   {
      gc_exit_blocking();
      return alloc_null();
   }
   gc_exit_blocking();
   return alloc_int(nbytes);
}
Exemple #27
0
//data is expected to be a bytearray
//FIXME Extend this like drawElements
value bufferData( value target, value size, value data, value usage )
{
	glBufferData(
		(GLenum)val_int( target ),
		(GLsizeiptr)val_int( size ),
		(const GLvoid *)buffer_data( val_to_buffer ( data ) ),
		(GLenum)val_int( usage ) );
	return alloc_null( );
}
Exemple #28
0
//data is expected to be a bytearray starting at desired position
//FIXME Extend this like drawElements
value bufferSubData( value target, value offset, value size, value data )
{
	glBufferSubData(
		(GLenum)val_int( target ),
		(GLintptr)val_int( offset ),
		(GLsizeiptr)val_int( size ),
		(const GLvoid *)buffer_data( val_to_buffer ( data ) ) );
	return alloc_null( );
}
Exemple #29
0
static void find_nearest_block(struct group *group, struct ray const *ray, struct nearest *nearest)
{
    struct groupdata *groupdata = group->data;

    struct ray groupspaceray;
    vec3_subtract(&groupspaceray.origin, &ray->origin, &group->position);
    groupspaceray.direction = ray->direction;

    buffer *buffer = create_buffer();
    ptrarray *blocks = groupdata->blocks;
    size_t blockcount = ptrarray_count(blocks);

    for (size_t i = 0; i < blockcount; ++i)
    {
        block *block = get_ptrarray(blocks, i);

        get_block_triangles(block, buffer);

        triangle *tris = buffer_data(buffer);
        size_t tricount = buffer_count(buffer, sizeof(struct triangle));

        for (size_t j = 0; j < tricount; ++j)
        {
            float temp;
            if (ray_intersect_triangle(&temp, &groupspaceray, &tris[j]))
            {
                /*
                 * Use <= for distance comparsion here so that when there are
                 * multiple candidates for selection the last block added will
                 * be selected. It is useful after pasting that the new blocks
                 * can be dragged to a new location.
                 */
                if (temp <= nearest->distance)
                {
                    nearest->distance = temp;
                    nearest->group    = group;
                    nearest->block    = block;
                    nearest->triangle = tris[j];
                }
            }
        }

        clear_buffer(buffer);
    }

    destroy_buffer(buffer);

    struct ptrarray *groups = groupdata->groups;
    size_t groupcount = ptrarray_count(groups);

    for (size_t i = 0; i < groupcount; ++i)
    {
        struct group *childgroup = get_ptrarray(groups, i);
        find_nearest_block(childgroup, ray, nearest);
    }
}
Exemple #30
0
/*
 * Reads a block from a RAM disk device.
 */
PRIVATE int ramdisk_readblk(unsigned minor, buffer_t buf)
{	
	addr_t ptr;
	
	ptr = ramdisks[minor].start + (buffer_num(buf) << BLOCK_SIZE_LOG2);
	
	kmemcpy(buffer_data(buf), (void *)ptr, BLOCK_SIZE);
	
	return (0);
}