mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
Make all public prism headers check for C++ so that consumers do not have to wrap includes in extern "C". https://github.com/ruby/prism/commit/a7071e9939
61 lines
1.4 KiB
C
61 lines
1.4 KiB
C
/**
|
|
* @file buffer.h
|
|
*
|
|
* A wrapper around a contiguous block of allocated memory.
|
|
*/
|
|
#ifndef PRISM_BUFFER_H
|
|
#define PRISM_BUFFER_H
|
|
|
|
#include "prism/compiler/exported.h"
|
|
#include "prism/compiler/nodiscard.h"
|
|
#include "prism/compiler/nonnull.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* A wrapper around a contiguous block of allocated memory.
|
|
*/
|
|
typedef struct pm_buffer_t pm_buffer_t;
|
|
|
|
/**
|
|
* Allocate and initialize a new buffer. If the buffer cannot be allocated, this
|
|
* function will abort the process.
|
|
*
|
|
* @returns A pointer to the initialized buffer. The caller is responsible for
|
|
* freeing the buffer with pm_buffer_free.
|
|
*/
|
|
PRISM_NODISCARD PRISM_EXPORTED_FUNCTION pm_buffer_t * pm_buffer_new(void);
|
|
|
|
/**
|
|
* Free both the memory held by the buffer and the buffer itself.
|
|
*
|
|
* @param buffer The buffer to free.
|
|
*/
|
|
PRISM_EXPORTED_FUNCTION void pm_buffer_free(pm_buffer_t *buffer) PRISM_NONNULL(1);
|
|
|
|
/**
|
|
* Return the value of the buffer.
|
|
*
|
|
* @param buffer The buffer to get the value of.
|
|
* @returns The value of the buffer.
|
|
*/
|
|
PRISM_EXPORTED_FUNCTION char * pm_buffer_value(const pm_buffer_t *buffer) PRISM_NONNULL(1);
|
|
|
|
/**
|
|
* Return the length of the buffer.
|
|
*
|
|
* @param buffer The buffer to get the length of.
|
|
* @returns The length of the buffer.
|
|
*/
|
|
PRISM_EXPORTED_FUNCTION size_t pm_buffer_length(const pm_buffer_t *buffer) PRISM_NONNULL(1);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|