Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang format GNU #1474

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
880 changes: 880 additions & 0 deletions .clang-format

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions .clang-format-gnu-derived
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
BasedOnStyle: Gnu
Language: Cpp
SortIncludes: Never
...
189 changes: 94 additions & 95 deletions src/java/nxt_jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,165 +11,164 @@

#include "nxt_jni.h"

static jclass nxt_java_NoSuchElementException_class;
static jclass nxt_java_IOException_class;
static jclass nxt_java_IllegalStateException_class;
static jclass nxt_java_File_class;
static jmethodID nxt_java_File_ctor;

static jclass nxt_java_NoSuchElementException_class;
static jclass nxt_java_IOException_class;
static jclass nxt_java_IllegalStateException_class;
static jclass nxt_java_File_class;
static jmethodID nxt_java_File_ctor;

static inline char nxt_java_lowcase(char c);

static inline char nxt_java_lowcase (char c);

int
nxt_java_jni_init(JNIEnv *env)
nxt_java_jni_init (JNIEnv *env)
{
jclass cls;
jclass cls;

cls = (*env)->FindClass(env, "java/util/NoSuchElementException");
if (cls == NULL) {
return NXT_UNIT_ERROR;
cls = (*env)->FindClass (env, "java/util/NoSuchElementException");
if (cls == NULL)
{
return NXT_UNIT_ERROR;
}

nxt_java_NoSuchElementException_class = (*env)->NewGlobalRef(env, cls);
(*env)->DeleteLocalRef(env, cls);
nxt_java_NoSuchElementException_class = (*env)->NewGlobalRef (env, cls);
(*env)->DeleteLocalRef (env, cls);


cls = (*env)->FindClass(env, "java/io/IOException");
if (cls == NULL) {
(*env)->DeleteGlobalRef(env, nxt_java_NoSuchElementException_class);
return NXT_UNIT_ERROR;
cls = (*env)->FindClass (env, "java/io/IOException");
if (cls == NULL)
{
(*env)->DeleteGlobalRef (env, nxt_java_NoSuchElementException_class);
return NXT_UNIT_ERROR;
}

nxt_java_IOException_class = (*env)->NewGlobalRef(env, cls);
(*env)->DeleteLocalRef(env, cls);

nxt_java_IOException_class = (*env)->NewGlobalRef (env, cls);
(*env)->DeleteLocalRef (env, cls);

cls = (*env)->FindClass(env, "java/lang/IllegalStateException");
if (cls == NULL) {
(*env)->DeleteGlobalRef(env, nxt_java_NoSuchElementException_class);
(*env)->DeleteGlobalRef(env, nxt_java_IOException_class);
return NXT_UNIT_ERROR;
cls = (*env)->FindClass (env, "java/lang/IllegalStateException");
if (cls == NULL)
{
(*env)->DeleteGlobalRef (env, nxt_java_NoSuchElementException_class);
(*env)->DeleteGlobalRef (env, nxt_java_IOException_class);
return NXT_UNIT_ERROR;
}

nxt_java_IllegalStateException_class = (*env)->NewGlobalRef(env, cls);
(*env)->DeleteLocalRef(env, cls);
nxt_java_IllegalStateException_class = (*env)->NewGlobalRef (env, cls);
(*env)->DeleteLocalRef (env, cls);


cls = (*env)->FindClass(env, "java/io/File");
if (cls == NULL) {
(*env)->DeleteGlobalRef(env, nxt_java_NoSuchElementException_class);
(*env)->DeleteGlobalRef(env, nxt_java_IOException_class);
(*env)->DeleteGlobalRef(env, nxt_java_IllegalStateException_class);
return NXT_UNIT_ERROR;
cls = (*env)->FindClass (env, "java/io/File");
if (cls == NULL)
{
(*env)->DeleteGlobalRef (env, nxt_java_NoSuchElementException_class);
(*env)->DeleteGlobalRef (env, nxt_java_IOException_class);
(*env)->DeleteGlobalRef (env, nxt_java_IllegalStateException_class);
return NXT_UNIT_ERROR;
}

nxt_java_File_class = (*env)->NewGlobalRef(env, cls);
(*env)->DeleteLocalRef(env, cls);


nxt_java_File_ctor = (*env)->GetMethodID(env, nxt_java_File_class, "<init>",
"(Ljava/lang/String;)V");
if (nxt_java_File_ctor == NULL) {
(*env)->DeleteGlobalRef(env, nxt_java_NoSuchElementException_class);
(*env)->DeleteGlobalRef(env, nxt_java_IOException_class);
(*env)->DeleteGlobalRef(env, nxt_java_IllegalStateException_class);
(*env)->DeleteGlobalRef(env, nxt_java_File_class);
return NXT_UNIT_ERROR;
nxt_java_File_class = (*env)->NewGlobalRef (env, cls);
(*env)->DeleteLocalRef (env, cls);

nxt_java_File_ctor = (*env)->GetMethodID (env, nxt_java_File_class, "<init>",
"(Ljava/lang/String;)V");
if (nxt_java_File_ctor == NULL)
{
(*env)->DeleteGlobalRef (env, nxt_java_NoSuchElementException_class);
(*env)->DeleteGlobalRef (env, nxt_java_IOException_class);
(*env)->DeleteGlobalRef (env, nxt_java_IllegalStateException_class);
(*env)->DeleteGlobalRef (env, nxt_java_File_class);
return NXT_UNIT_ERROR;
}

return NXT_UNIT_OK;
return NXT_UNIT_OK;
}


void
nxt_java_throw_NoSuchElementException(JNIEnv *env, const char *msg)
nxt_java_throw_NoSuchElementException (JNIEnv *env, const char *msg)
{
(*env)->ThrowNew(env, nxt_java_NoSuchElementException_class, msg);
(*env)->ThrowNew (env, nxt_java_NoSuchElementException_class, msg);
}


void
nxt_java_throw_IOException(JNIEnv *env, const char *msg)
nxt_java_throw_IOException (JNIEnv *env, const char *msg)
{
(*env)->ThrowNew(env, nxt_java_IOException_class, msg);
(*env)->ThrowNew (env, nxt_java_IOException_class, msg);
}


void
nxt_java_throw_IllegalStateException(JNIEnv *env, const char *msg)
nxt_java_throw_IllegalStateException (JNIEnv *env, const char *msg)
{
(*env)->ThrowNew(env, nxt_java_IllegalStateException_class, msg);
(*env)->ThrowNew (env, nxt_java_IllegalStateException_class, msg);
}


nxt_unit_field_t *
nxt_java_findHeader(nxt_unit_field_t *f, nxt_unit_field_t *end,
const char *name, uint8_t name_len)
nxt_java_findHeader (nxt_unit_field_t *f, nxt_unit_field_t *end,
const char *name, uint8_t name_len)
{
const char *field_name;
const char *field_name;

for (/* void */ ; f < end; f++) {
if (f->skip != 0 || f->name_length != name_len) {
continue;
for (/* void */; f < end; f++)
{
if (f->skip != 0 || f->name_length != name_len)
{
continue;
}

field_name = nxt_unit_sptr_get(&f->name);
field_name = nxt_unit_sptr_get (&f->name);

if (nxt_java_strcaseeq(name, field_name, name_len)) {
return f;
if (nxt_java_strcaseeq (name, field_name, name_len))
{
return f;
}
}

return NULL;
return NULL;
}


int
nxt_java_strcaseeq(const char *str1, const char *str2, int len)
nxt_java_strcaseeq (const char *str1, const char *str2, int len)
{
char c1, c2;
const char *end1;
char c1, c2;
const char *end1;

end1 = str1 + len;
end1 = str1 + len;

while (str1 < end1) {
c1 = nxt_java_lowcase(*str1++);
c2 = nxt_java_lowcase(*str2++);
while (str1 < end1)
{
c1 = nxt_java_lowcase (*str1++);
c2 = nxt_java_lowcase (*str2++);

if (c1 != c2) {
return 0;
if (c1 != c2)
{
return 0;
}
}

return 1;
return 1;
}


static inline char
nxt_java_lowcase(char c)
nxt_java_lowcase (char c)
{
return (c >= 'A' && c <= 'Z') ? c | 0x20 : c;
return (c >= 'A' && c <= 'Z') ? c | 0x20 : c;
}


jstring
nxt_java_newString(JNIEnv *env, char *str, uint32_t len)
nxt_java_newString (JNIEnv *env, char *str, uint32_t len)
{
char tmp;
jstring res;
char tmp;
jstring res;

tmp = str[len];
tmp = str[len];

if (tmp != '\0') {
str[len] = '\0';
if (tmp != '\0')
{
str[len] = '\0';
}

res = (*env)->NewStringUTF(env, str);
res = (*env)->NewStringUTF (env, str);

if (tmp != '\0') {
str[len] = tmp;
if (tmp != '\0')
{
str[len] = tmp;
}

return res;
return res;
}
46 changes: 22 additions & 24 deletions src/java/nxt_jni.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,48 @@
#ifndef _NXT_JAVA_JNI_H_INCLUDED_
#define _NXT_JAVA_JNI_H_INCLUDED_


#include <jni.h>
#include <nxt_unit_typedefs.h>

int nxt_java_jni_init (JNIEnv *env);

int nxt_java_jni_init(JNIEnv *env);

void nxt_java_throw_NoSuchElementException(JNIEnv *env, const char *msg);

void nxt_java_throw_IOException(JNIEnv *env, const char *msg);
void nxt_java_throw_NoSuchElementException (JNIEnv *env, const char *msg);

void nxt_java_throw_IllegalStateException(JNIEnv *env, const char *msg);
void nxt_java_throw_IOException (JNIEnv *env, const char *msg);

nxt_unit_field_t *nxt_java_findHeader(nxt_unit_field_t *f, nxt_unit_field_t *e,
const char *name, uint8_t name_len);
void nxt_java_throw_IllegalStateException (JNIEnv *env, const char *msg);

int nxt_java_strcaseeq(const char *str1, const char *str2, int len);
nxt_unit_field_t *nxt_java_findHeader (nxt_unit_field_t *f,
nxt_unit_field_t *e, const char *name,
uint8_t name_len);

jstring nxt_java_newString(JNIEnv *env, char *str, uint32_t len);
int nxt_java_strcaseeq (const char *str1, const char *str2, int len);

jstring nxt_java_newString (JNIEnv *env, char *str, uint32_t len);

typedef struct {
uint32_t header_size;
uint32_t buf_size;
typedef struct
{
uint32_t header_size;
uint32_t buf_size;

jobject jreq;
jobject jresp;
jobject jreq;
jobject jresp;

nxt_unit_buf_t *first;
nxt_unit_buf_t *buf;
nxt_unit_buf_t *first;
nxt_unit_buf_t *buf;

} nxt_java_request_data_t;


static inline jlong
nxt_ptr2jlong(void *ptr)
nxt_ptr2jlong (void *ptr)
{
return (jlong) (intptr_t) ptr;
return (jlong)(intptr_t)ptr;
}

static inline void *
nxt_jlong2ptr(jlong l)
nxt_jlong2ptr (jlong l)
{
return (void *) (intptr_t) l;
return (void *)(intptr_t)l;
}

#endif /* _NXT_JAVA_JNI_H_INCLUDED_ */
#endif /* _NXT_JAVA_JNI_H_INCLUDED_ */
Loading
Loading