1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

ext_help.h, minissl.c, puma_http11.c - change Data -> TypedData (#2430)

'Data_' macros have been 'deprecated' since Ruby 2.3 or earlier, but are still supported.

Update c source to use the 'TypedData_' macros.
This commit is contained in:
MSP-Greg 2020-10-16 08:36:08 -05:00 committed by GitHub
parent 2f90396c95
commit 04eb8bdb39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 46 deletions

View file

@ -2,7 +2,7 @@
#define ext_help_h
#define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "%s", "NULL found for " # T " when shouldn't be.");
#define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name);
#define DATA_GET(from,type,data_type,name) TypedData_Get_Struct(from,type,data_type,name); RAISE_NOT_NULL(name);
#define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "%s", "Wrong argument type for " # V " required " # T);
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))

View file

@ -2,12 +2,7 @@
#include <ruby.h>
#include <ruby/version.h>
#if RUBY_API_VERSION_MAJOR == 1
#include <rubyio.h>
#else
#include <ruby/io.h>
#endif
#ifdef HAVE_OPENSSL_BIO_H
@ -33,7 +28,8 @@ typedef struct {
int bytes;
} ms_cert_buf;
void engine_free(ms_conn* conn) {
void engine_free(void *ptr) {
ms_conn *conn = ptr;
ms_cert_buf* cert_buf = (ms_cert_buf*)SSL_get_app_data(conn->ssl);
if(cert_buf) {
OPENSSL_free(cert_buf->buf);
@ -45,10 +41,16 @@ void engine_free(ms_conn* conn) {
free(conn);
}
const rb_data_type_t engine_data_type = {
"MiniSSL/ENGINE",
{ 0, engine_free, 0 },
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
};
ms_conn* engine_alloc(VALUE klass, VALUE* obj) {
ms_conn* conn;
*obj = Data_Make_Struct(klass, ms_conn, 0, engine_free, conn);
*obj = TypedData_Make_Struct(klass, ms_conn, &engine_data_type, conn);
conn->read = BIO_new(BIO_s_mem());
BIO_set_nbio(conn->read, 1);
@ -281,7 +283,7 @@ VALUE engine_inject(VALUE self, VALUE str) {
ms_conn* conn;
long used;
Data_Get_Struct(self, ms_conn, conn);
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
StringValue(str);
@ -334,7 +336,7 @@ VALUE engine_read(VALUE self) {
char buf[512];
int bytes, error;
Data_Get_Struct(self, ms_conn, conn);
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
ERR_clear_error();
@ -361,7 +363,7 @@ VALUE engine_write(VALUE self, VALUE str) {
ms_conn* conn;
int bytes;
Data_Get_Struct(self, ms_conn, conn);
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
StringValue(str);
@ -385,7 +387,7 @@ VALUE engine_extract(VALUE self) {
size_t pending;
char buf[512];
Data_Get_Struct(self, ms_conn, conn);
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
pending = BIO_pending(conn->write);
if(pending > 0) {
@ -404,7 +406,7 @@ VALUE engine_shutdown(VALUE self) {
ms_conn* conn;
int ok;
Data_Get_Struct(self, ms_conn, conn);
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
ERR_clear_error();
@ -419,7 +421,7 @@ VALUE engine_shutdown(VALUE self) {
VALUE engine_init(VALUE self) {
ms_conn* conn;
Data_Get_Struct(self, ms_conn, conn);
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
return SSL_in_init(conn->ssl) ? Qtrue : Qfalse;
}
@ -432,7 +434,7 @@ VALUE engine_peercert(VALUE self) {
ms_cert_buf* cert_buf = NULL;
VALUE rb_cert_buf;
Data_Get_Struct(self, ms_conn, conn);
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
cert = SSL_get_peer_certificate(conn->ssl);
if(!cert) {
@ -469,7 +471,7 @@ VALUE engine_peercert(VALUE self) {
static VALUE
engine_ssl_vers_st(VALUE self) {
ms_conn* conn;
Data_Get_Struct(self, ms_conn, conn);
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
return rb_ary_new3(2, rb_str_new2(SSL_get_version(conn->ssl)), rb_str_new2(SSL_state_string(conn->ssl)));
}

View file

@ -253,11 +253,18 @@ void HttpParser_free(void *data) {
}
}
void HttpParser_mark(puma_parser* hp) {
void HttpParser_mark(void *ptr) {
puma_parser *hp = ptr;
if(hp->request) rb_gc_mark(hp->request);
if(hp->body) rb_gc_mark(hp->body);
}
const rb_data_type_t HttpParser_data_type = {
"HttpParser",
{ HttpParser_mark, HttpParser_free, 0 },
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
};
VALUE HttpParser_alloc(VALUE klass)
{
puma_parser *hp = ALLOC_N(puma_parser, 1);
@ -274,7 +281,7 @@ VALUE HttpParser_alloc(VALUE klass)
puma_parser_init(hp);
return Data_Wrap_Struct(klass, HttpParser_mark, HttpParser_free, hp);
return TypedData_Wrap_Struct(klass, &HttpParser_data_type, hp);
}
/**
@ -286,7 +293,7 @@ VALUE HttpParser_alloc(VALUE klass)
VALUE HttpParser_init(VALUE self)
{
puma_parser *http = NULL;
DATA_GET(self, puma_parser, http);
DATA_GET(self, puma_parser, &HttpParser_data_type, http);
puma_parser_init(http);
return self;
@ -303,7 +310,7 @@ VALUE HttpParser_init(VALUE self)
VALUE HttpParser_reset(VALUE self)
{
puma_parser *http = NULL;
DATA_GET(self, puma_parser, http);
DATA_GET(self, puma_parser, &HttpParser_data_type, http);
puma_parser_init(http);
return Qnil;
@ -320,7 +327,7 @@ VALUE HttpParser_reset(VALUE self)
VALUE HttpParser_finish(VALUE self)
{
puma_parser *http = NULL;
DATA_GET(self, puma_parser, http);
DATA_GET(self, puma_parser, &HttpParser_data_type, http);
puma_parser_finish(http);
return puma_parser_is_finished(http) ? Qtrue : Qfalse;
@ -351,7 +358,7 @@ VALUE HttpParser_execute(VALUE self, VALUE req_hash, VALUE data, VALUE start)
char *dptr = NULL;
long dlen = 0;
DATA_GET(self, puma_parser, http);
DATA_GET(self, puma_parser, &HttpParser_data_type, http);
from = FIX2INT(start);
dptr = rb_extract_chars(data, &dlen);
@ -385,7 +392,7 @@ VALUE HttpParser_execute(VALUE self, VALUE req_hash, VALUE data, VALUE start)
VALUE HttpParser_has_error(VALUE self)
{
puma_parser *http = NULL;
DATA_GET(self, puma_parser, http);
DATA_GET(self, puma_parser, &HttpParser_data_type, http);
return puma_parser_has_error(http) ? Qtrue : Qfalse;
}
@ -400,7 +407,7 @@ VALUE HttpParser_has_error(VALUE self)
VALUE HttpParser_is_finished(VALUE self)
{
puma_parser *http = NULL;
DATA_GET(self, puma_parser, http);
DATA_GET(self, puma_parser, &HttpParser_data_type, http);
return puma_parser_is_finished(http) ? Qtrue : Qfalse;
}
@ -416,7 +423,7 @@ VALUE HttpParser_is_finished(VALUE self)
VALUE HttpParser_nread(VALUE self)
{
puma_parser *http = NULL;
DATA_GET(self, puma_parser, http);
DATA_GET(self, puma_parser, &HttpParser_data_type, http);
return INT2FIX(http->nread);
}
@ -429,7 +436,7 @@ VALUE HttpParser_nread(VALUE self)
*/
VALUE HttpParser_body(VALUE self) {
puma_parser *http = NULL;
DATA_GET(self, puma_parser, http);
DATA_GET(self, puma_parser, &HttpParser_data_type, http);
return http->body;
}